创建Nginx采集策略

<p class="shortdesc">本文主要介绍如何为主机组创建Nginx采集策略。</p> <section class="section prereq" id="Create_Nginx_Strategy__prereq_lfv_ssz_wmb"><div class="tasklabel"><h2 class="doc-tairway">前提条件</h2></div> <ol class="ol" id="Create_Nginx_Strategy__ol_vkr_tsz_wmb"> <li class="li">您已成功创建主机组,可参考创建主机组。</li> <li class="li">您已成功安装Nginx组件。<div class="note important note_important"><span class="note__title">重要:</span> 安装Nginx设备的操作系统只能为Linux或Unix。</div></li> <li class="li">用户自定义配置的Nginx访问日志格式,需要与控制台创建采集策略配置的Nginx日志格式一致,否则会导致用户的日志数据提取不准确或无法提取。</li> </ol> </section> <section class="section context"><div class="tasklabel"><h2 class="doc-tairway">背景信息</h2></div> <p class="p">使用平安云日志服务采集日志:</p> <ul class="ul" id="Create_Nginx_Strategy__ul_kzg_ssz_wmb"> <li class="li">安装日志采集客户端:平安云会自动为您需要采集的主机组安装日志采集客户端。</li> <li class="li">配置采集策略:您可以通过控制台给相应的主机组创建日志采集策略。</li> </ul> <p class="p">针对通用的开源Nginx负载均衡组件,平安云日志服务提供了定制化的Nginx采集模板,您可通过日志服务控制台方便的使用平安云日志服务。</p> </section> <section><div class="tasklabel"><h2 class="doc-tairway">操作步骤</h2></div><ol class="ol steps"><li class="li step stepexpand"> <span class="ph cmd"> 登录<a class="xref" href="/console/logcloud/indexed/list" target="_blank">日志服务管理控制台</a>。</span> </li><li class="li step stepexpand"> <span class="ph cmd">单击左侧导航栏<span class="ph uicontrol">项目管理</span>,进入<span class="keyword wintitle">项目列表</span>页面。</span> </li><li class="li step stepexpand"> <span class="ph cmd">选择目标地域,单击目标项目名称。</span> </li><li class="li step stepexpand"> <span class="ph cmd">单击<span class="keyword wintitle">AGENT配置</span>页签。</span> </li><li class="li step stepexpand"> <span class="ph cmd">单击页面右上角<span class="ph uicontrol">创建配置</span>,进入<span class="keyword wintitle">创建配置</span>页面。</span> </li><li class="li step stepexpand"> <span class="ph cmd">根据以下信息,创建Nginx采集策略:</span> <div class="itemgroup info"> <table class="table" id="Create_Nginx_Strategy__table_tmm_ctz_wmb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1">参数</th> <th class="entry" id="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2">说明</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1 "> <p class="p">数据类型</p> </td> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2 "> <p class="p">配置采集的日志类型,支持:</p> <ul class="ul" id="Create_Nginx_Strategy__ul_umm_ctz_wmb"> <li class="li">Nginx</li> <li class="li">通用</li> </ul> <p class="p">此处选择Nginx。</p> </td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1 "> <p class="p">名称</p> </td> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2 "> <p class="p">配置Nginx采集策略的名称。</p> <ul class="ul" id="Create_Nginx_Strategy__ul_vmm_ctz_wmb"> <li class="li">支持汉字、英文大小写字母、数字、特殊字符“_”“-”“@”。</li> <li class="li">长度在1~45个字符之间。</li> </ul> </td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1 "> <p class="p">日志路径</p> </td> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2 "> <p class="p">配置待采集日志的云主机上的绝对路径。</p> <div class="note note note_note"><span class="note__title">说明:</span> <ul class="ul" id="Create_Nginx_Strategy__ul_xmm_ctz_wmb"> <li class="li">目录必须具体到文件。</li> <li class="li">默认不扫描子目录。</li> <li class="li">多个路径使用英文逗号隔开。</li> </ul> </div> </td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1 "> <p class="p">是否归档</p> </td> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2 "> <p class="p">是否需要将采集到的日志文件归档在平安云提供的存储设备上。</p> <ul class="ul" id="Create_Nginx_Strategy__ul_jmz_ftz_wmb"> <li class="li">是:归档,日志可在平安云上保存一年。<ul class="ul" id="Create_Nginx_Strategy__ul_ot3_gtz_wmb"> <li class="li"> 1. 系统将自动删除超过一年的日志数据。</li> <li class="li"> 2. 若您需要在平安云的存储设备中保存更长时间,可提交<a class="xref" href="/console/workorder/create" target="_blank">工单</a>申请。</li> </ul></li> <li class="li">否:不归档。系统将自动删除超过索引设置保存时间的日志数据。</li> </ul> </td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1 "> <p class="p">应用到主机组</p> </td> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2 "> <p class="p">选择需要应用此采集策略的主机组。</p> </td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1 "> <p class="p">Nginx日志格式</p> </td> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2 "> <p class="p">待采集的Nginx访问日志的格式。</p> <p class="p">默认情况下,平安云日志服务声明了通用的Nginx访问日志格式,通过对采集状态和信息进行查询、分析、统计,提供了业界使用率较高的十几种可视化图表,提升用户对Nginx应用的访问业务分析和监控的效率。</p> <div class="note important note_important"><span class="note__title">重要:</span> <ol class="ol" type="a" id="Create_Nginx_Strategy__ol_c14_ltz_wmb"> <li class="li">用户可以更新为实际配置的格式。</li> <li class="li">此处需要与您自定义配置的Nginx访问日志格式一致。</li> </ol> </div> </td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__1 "> <p class="p">Nginx键名称</p> </td> <td class="entry" headers="Create_Nginx_Strategy__table_tmm_ctz_wmb__entry__2 "> <p class="p">根据<span class="ph uicontrol">Nginx日志格式</span>填写的内容,自动解析成系统能够提从采集到的日志中提取的字段列表,不可编辑,可供您实时查看可提取的日志字段。详细内容可参考Nginx日志格式详细信息。</p> </td> </tr> </tbody></table> <p class="p"><span class="ph uicontrol">Nginx日志格式详细信息</span></p> <table class="table" id="Create_Nginx_Strategy__table_u1n_qtz_wmb"><caption></caption><colgroup><col><col></colgroup><thead class="thead"> <tr class="row"> <th class="entry" id="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1">参数</th> <th class="entry" id="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2">说明</th> </tr> </thead><tbody class="tbody"> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">remote_addr</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">记录访问网站的客户端地址。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">remote_user</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">记录访问网站的用户名。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">time_local</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">记录访问网站时间与时区。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">request</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">用户的HTTP请求起始行信息。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">status</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">记录HTTP请求返回的状态码,例如:200、404等。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">body_bytes_sent</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">Nginx服务器发送给客户端的响应body字节数。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">http_referer</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">记录此次请求是从哪个链接访问过来的。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">http_user_agent</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">记录客户端访问信息,例如:浏览器、手机客户端等。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">http_x_forwarded_for</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">访问网站时若有代理服务器,需设置web节点记录客户端地址的配置。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">request_time</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">处理客户端请求使用的时间,单位为秒,精度为毫秒。从Nginx服务端收到客户端发出的第一个字符开始,到把最后一个字符发送给客户端,且Nginx服务端完成日志写入为止。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">upstream_response_time</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">上游服务的响应请求的处理时间。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">upstream_addr</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">上游服务器的地址。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">upstream_status</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">上游服务器返回请求的响应状态。</p></td> </tr> <tr class="row"> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__1 "><p class="p">request_length</p></td> <td class="entry" headers="Create_Nginx_Strategy__table_u1n_qtz_wmb__entry__2 "><p class="p">客户端的请求长度 ,单位为字节。(包括请求的地址、HTTP请求头和请求主体)</p></td> </tr> </tbody></table> </div> </li><li class="li step stepexpand"> <span class="ph cmd"> 单击<span class="ph uicontrol">确定</span>。</span> </li></ol></section> <section class="section result" id="Create_Nginx_Strategy__result_ogm_5tz_wmb"><div class="tasklabel"><h2 class="doc-tairway">执行结果</h2></div> <p class="p">在<span class="keyword wintitle">AGENT配置</span>页签,可以看到刚刚创建的Nginx采集策略。 </p> <img class="image" id="Create_Nginx_Strategy__image_fz2_xtz_wmb" src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20210106133702-16b89b9e97f7.png" width="830"> </section> <section class="section postreq" id="Create_Nginx_Strategy__postreq_fs2_ytz_wmb"><div class="tasklabel"><h2 class="doc-tairway">后续操作</h2></div> <p class="p">采集一段时间Nginx日志后,通过<a class="xref" href="/console/logcloud/dashboard/list" target="_blank">仪表盘管理</a>查看定制化的视图报表,可参考<a class="xref" href="/ssr/help/middleware/LogCloud/User_Guide.Visualization.Dashboard" target="_blank">可视化</a>。</p> </section>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

工单支持

解决云产品相关技术问题