ELK采集tomcat日志 逃离我推掉我的手 2022-01-07 15:53 425阅读 0赞 # ELK采集tomcat日志 # ## 一,软件架构 ## ![af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png][] ### Nxlog ### nxlog 是用 C 语言写的一个跨平台日志收集处理软件。其内部支持使用 Perl 正则和语法来进行数据结构化和逻辑判断操作。不过,其最常用的场景。是在 windows 服务器上,作为 logstash 的替代品运行。 * 官方文档 \[[https://nxlog.co/products/nxlog-community-edition][https_nxlog.co_products_nxlog-community-edition]\] * 下载地址 \[[https://nxlog.co/products/nxlog-community-edition/download][https_nxlog.co_products_nxlog-community-edition_download]\] ### Logstash ### logstash就是一根具备实时数据传输能力的管道,负责将数据信息从管道的输入端传输到管道的输出端;与此同时这根管道还可以让你根据自己的需求在中间加上滤网,Logstash提供里很多功能强大的滤网以满足你的各种应用场景。 * 官方文档 \[[https://www.elastic.co/guide/en/logstash/current/introduction.html][https_www.elastic.co_guide_en_logstash_current_introduction.html]\] * 下载地址 \[[https://www.elastic.co/cn/downloads][https_www.elastic.co_cn_downloads]\] ### Elasticsearch ### ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于\[云计算\])中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。 * 官方文档 \[[https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html][https_www.elastic.co_guide_en_elasticsearch_reference_current_index.html]\] * 下载地址 \[[https://www.elastic.co/cn/downloads][https_www.elastic.co_cn_downloads]\] ### Kibana ### Kibana是一个开源的分析与可视化平台,设计出来用于和Elasticsearch一起使用的。你可以用kibana搜索、查看、交互存放在Elasticsearch索引里的数据,使用各种不同的图表、表格、地图等kibana能够很轻易地展示高级数据分析与可视化。 * 官方文档 \[[https://www.elastic.co/guide/en/kibana/current/index.html][https_www.elastic.co_guide_en_kibana_current_index.html]\] * 下载地址 \[[https://www.elastic.co/cn/downloads][https_www.elastic.co_cn_downloads]\] # 二、安装部署 # ### Nxlog ### #### 1. 下载nxlog安装包(这里以windows为例)。 #### nxlog有ce版本和和EE版本,支持windows、linux等等操作系统。 #### 2. 双击安装 #### 默认安装路径:**C:\\Program Files (x86)\\nxlog** #### 3. 修改配置文件: #### 修改:**C:\\Program Files (x86)\\nxlog\\conf\\nxlog.conf** ## This is a sample configuration file. See the nxlog reference manual about the ## configuration options. It should be installed locally and is also available ## online at http://nxlog.org/docs/ ## Please set the ROOT to the folder your nxlog was installed into, ## otherwise it will not start. #define ROOT C:\Program Files\nxlog define ROOT C:\Program Files (x86)\nxlog Moduledir C:\Program Files (x86)\nxlog\modules CacheDir C:\Program Files (x86)\nxlog\data Pidfile C:\Program Files (x86)\nxlog\data\nxlog.pid SpoolDir C:\Program Files (x86)\nxlog\data LogFile C:\Program Files (x86)\nxlog\data\nxlog.log <Extension _syslog> Module xm_syslog </Extension> <Input testfile> Module im_file File "D:\\apache-tomcat-7.0.77\\logs\\\*.log" SavePos TRUE </Input> <Output out> Module om_tcp Host 192.168.8.83 Port 514 </Output> <Route 1> Path testfile => out </Route> * 配置路径 <table> <thead> <tr> <th style="text-align:center;">名称</th> <th style="text-align:center;">定义</th> <th style="text-align:center;">路径</th> </tr> </thead> <tbody> <tr> <td style="text-align:center;">nxlog根目录</td> <td style="text-align:center;">define ROOT()</td> <td style="text-align:center;">C:\Program Files (x86)\nxlog</td> </tr> <tr> <td style="text-align:center;">模块路径</td> <td style="text-align:center;">Moduledir</td> <td style="text-align:center;">C:\Program Files (x86)\nxlog\modules</td> </tr> <tr> <td style="text-align:center;">nxlog缓存数据</td> <td style="text-align:center;">CacheDir</td> <td style="text-align:center;">C:\Program Files (x86)\nxlog\data</td> </tr> <tr> <td style="text-align:center;">pid路径</td> <td style="text-align:center;">Pidfile</td> <td style="text-align:center;">C:\Program Files (x86)\nxlog\data\nxlog.pid</td> </tr> <tr> <td style="text-align:center;">资源池路径</td> <td style="text-align:center;">SpoolDir</td> <td style="text-align:center;">C:\Program Files (x86)\nxlog\data</td> </tr> <tr> <td style="text-align:center;">日志路径</td> <td style="text-align:center;">LogFile</td> <td style="text-align:center;">C:\Program Files (x86)\nxlog\data\nxlog.log</td> </tr> </tbody> </table> #### 4. 启动nxlog #### 启动后查看日志,如果logstash未启动会报错 * 正常启动 ![303938cd-965c-4f34-9cd7-495b4473e86f.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] #### 5.设置nxlog服务 #### nxlog安装后,默认会在系统穿件一个nxlog的系统服务。可以根据自己的选择配置自动启动。 ![cb74f291-d94b-432e-82f6-372371f91315.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] ### Logstash安装配置 ### #### 1. 软件环境说明 #### <table> <thead> <tr> <th>软件系统</th> <th>版本</th> </tr> </thead> <tbody> <tr> <td>linux</td> <td>centos7 64bit</td> </tr> <tr> <td>jdk</td> <td>1.8.0.144 64bit linux版本</td> </tr> <tr> <td>Logstash</td> <td>6.1.1 linux</td> </tr> </tbody> </table> #### 2. jdk安装(跳过) #### #### 3. 官方下载Logstash解压。 #### cd /opt wget https://artifacts.elastic.co/downloads/logstash/logstash-6.1.1.tar.gz tar -zxvf logstash-6.1.1.tar.gz #建立软链接 ln -s /opt/logstash-6.1.1/bin/logstash /usr/local/sbin/logstash` #### 4. 测试Logstash #### 原理:输入,过滤器,输出 ![398d5be6-6444-4aed-82bd-44772cdf10f8.jpg][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] #因为已经加了软链接,所以直接可以输入命令 logstash执行 logstash -e 'input { stdin { } } output { stdout {} }' 输入 hello可以看到logstash直接获取到了hello ![575b20a6-7a4e-4d0e-845a-9e3b28c8312a.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] #### 5,常用参数 #### <table> <thead> <tr> <th>参数</th> </tr> </thead> <tbody> <tr> <td>-n</td> </tr> <tr> <td>-f</td> </tr> <tr> <td>-e</td> </tr> <tr> <td>-l</td> </tr> <tr> <td>--debug</td> </tr> <tr> <td>--log.level</td> </tr> <tr> <td>--config.debug</td> </tr> <tr> <td>-t</td> </tr> <tr> <td>-r</td> </tr> <tr> <td>--config.reload.interval</td> </tr> <tr> <td>--http.host</td> </tr> <tr> <td>--http.port</td> </tr> <tr> <td>--quiet</td> </tr> </tbody> </table> #### 6. 配置tomcat日志采集 #### * 在Logstash的bin下面创建nxlog.conf文件。 * 通过tcp的方式接受nxlog采集的日志。 * 配置elasticsearch的地址和index等信息 input { tcp { port => 514 } } output{ elasticsearch { hosts => "192.168.8.83:9200" index => "logstash-test1" template_overwrite => true } } #### 7. 启动Logstash #### logstash -f /opt/logstash-6.1.1/bin/nxlog.conf #### 8 检查运行正常即可 #### * Logstash启动较慢,需要等待一会。 ### Elasticsearch安装启动 ### #### 1. 软件环境说明 #### <table> <thead> <tr> <th>软件系统</th> <th>版本</th> </tr> </thead> <tbody> <tr> <td>linux</td> <td>centos7 64bit</td> </tr> <tr> <td>jdk</td> <td>1.8.0.144 64bit linux版本</td> </tr> <tr> <td>Elasticsearch</td> <td>6.1.1 linux</td> </tr> </tbody> </table> #### 2. jdk安装(跳过) #### #### 3. 官方下载安装包并解压 #### #建立软链接 ln -s /opt/elasticsearch-6.1.1/bin/elasticsearch /usr/local/sbin/elasticsearch #### 4. 配置Elasticsearch #### * 配置文件 **/opt/elasticsearch-6.1.1/config/elasticsearch.yml** #定义es集群名称 cluster.name: bosheng_logs ##定义该节点的名称,各个节点不能重复 node.name: node1 ##配置数据目录,注意elasticsearch会有自己的运行用户,要赋予目录此用户的权限 path.data: /logs ##配置日志目录 path.logs: /opt/elasticsearch-6.1.1/logs ##关闭锁定内存 bootstrap.memory_lock: false bootstrap.system_call_filter: false ##指定本机IP地址 network.host: 192.168.8.83 #指定http访问端口 http.port: 9200 #### 5.创建一个新用户来启动elastricsearch。 #### * 使用root用户创建 useradd elk passwd elk chown -R elk /opt/elasticsearch-6.1.1 #### 6. 使用创建的用户启动Elasticsearch #### su elk elasticsearch #### 7. 检查启动是否正常 #### ![49fbfe63-cc42-42b7-a4e8-5a7a90a215ba.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] ### Kibana安装启动 ### #### 1. 软件环境说明 #### <table> <thead> <tr> <th>软件系统</th> <th>版本</th> </tr> </thead> <tbody> <tr> <td>linux</td> <td>centos7 64bit</td> </tr> <tr> <td>jdk</td> <td>1.8.0.144 64bit linux版本</td> </tr> <tr> <td>Kibana</td> <td>6.1.1 linux</td> </tr> </tbody> </table> #### 2. jdk安装(跳过) #### #### 3. 官方下载安装包并解压 #### #建立软链接 ln -s /opt/kibana-6.1.1-linux-x86_64/bin/kibana /usr/local/sbin/kibana #### 4. 配置kibana #### * 配置文件路径 **/opt/kibana-6.1.1-linux-x86\_64/config/kibana.yml** server.port: 5601 server.host: 192.168.8.83 elasticsearch.url: "http://192.168.8.83:9200" #### 启动kibana,并验证。 #### * 启动 kibana * 启动成功 ![088e555f-e315-462f-97f9-7dcef1c69a91.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] * 访问 ![eb8f887b-24e8-4f66-b260-c9e17718e2a1.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] ## 三、验证 ## ### 1. 启动tomcat7.0.77 ### ### 2. 查看Elasticsearch接收到的日志信息 ### ![fa2c7893-0d0e-4a5a-a348-21cf16954277.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] ### 3. 通过kibana查看tomcat的启动日志 ### ![77f0c71d-8f20-4103-811f-97080d6e6e81.png][af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png] **通过检查之后,我们发现我们成功的采集到了tomcat的日志到Elasticsearch** 转载于:https://www.cnblogs.com/kakarott/p/8118906.html [af759a0c-c5f8-43d5-b1fe-353ff7450cc5.png]: [https_nxlog.co_products_nxlog-community-edition]: https://nxlog.co/products/nxlog-community-edition [https_nxlog.co_products_nxlog-community-edition_download]: https://nxlog.co/products/nxlog-community-edition/download [https_www.elastic.co_guide_en_logstash_current_introduction.html]: https://www.elastic.co/guide/en/logstash/current/introduction.html [https_www.elastic.co_cn_downloads]: https://www.elastic.co/cn/downloads [https_www.elastic.co_guide_en_elasticsearch_reference_current_index.html]: https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html [https_www.elastic.co_guide_en_kibana_current_index.html]: https://www.elastic.co/guide/en/kibana/current/index.html
还没有评论,来说两句吧...