转载来源 :ELK收集tomcat日志 :https://www.jianshu.com/p/9f4ba87e4e15
1.安装tomcat
注意:需要提前安装好java环境
[root@db01
~]# yum install
-y tomcat tomcat
-webapps tomcat
-admin
-webapps tomcat
-docs
-webapp tomcat
-javadoc
2.修改tomcat日志为json格式
[root@db01
~]# vim
/etc
/tomcat
/server
.xml ##编辑配置文件
##找到
139行
,将`pattern
="%h %l %u %t "%r" %s %b" />删除
##再添加下面这条参数
pattern
="{"clientip":"%h", "client user":"%l", "authenticated":"%u", "AccessTime":"%t", "method":"%r", "status":"%s", "SendBytes":"%b", "Query?string":"%q", "partner":"%{Referer}i", "AgentVersion":"%{User-Agent}i"}"/>
3.启动tomcat
[root@db01
~]# systemctl start tomcat
[root@db01
~]# netstat
-lntup
| grep
8080 ##查看
8080端口是否打开
tcp6
0 0 :::8080 :::* LISTEN
15905/java
3.用浏览器访问tomcat并产生一下日志
在此页面随意点击,使tomcat产生日志
4.修改filebeat配置文件
[root@db01
~]# vim
/etc
/filebeat
/filebeat
.yml
filebeat
.inputs
:
- type
: log
enabled
: true
paths
:
- /var
/log
/tomcat
/localhost_access_log
.*.txt
json
.keys_under_root
: true
json
.overwrite_keys
: true
tags
: ["tomcat"]
setup
.kibana
:
host
: "172.16.210.53:5601"
output
.elasticsearch
:
hosts
: ["172.16.210.53:9200"]
indices
:
- index
: "tomcat-access-%{[beat.version]}-%{+yyyy.MM}"
when
.contains
:
tags
: "tomcat"
5.重启filebeat
[root@db01
~]# systemctl restart filebeat
6.回到kibana界面添加索引
回到discover添加tomcat的索引展示,就能查看到tomcat的日志了 然后也可以添加过滤项,来展示想要查看的指定信息