006.ELK收集Tomcat日志
2020-04-16 本文已影响0人
CoderJed
1. Tomcat日志转为JSON格式
/etc/tomcat/server.xml
# 默认的配置
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
# 修改为
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="{"clientip":"%h","ClientUser":"%l","authenticated":"%u","AccessTime":"%t","method":"%r","status":"%s","SendBytes":"%b","Query?string":"%q","partner":"%{Referer}i","AgentVersion":"%{User-Agent}i"}"/>
重启Tomcat:
systemctl restart tomcat
2. filebeat配置文件
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/tomcat/localhost_access_log*
json.keys_under_root: true
json.overwrite_keys: true
setup.kibana:
host: "192.168.47.175:5601"
output.elasticsearch:
hosts: ["localhost:9200"]
index: "tomcat-access-%{+yyyy.MM}"
setup.template.name: "tomcat"
setup.template.pattern: "tomcat-*"
setup.template.enabled: false
setup.template.overwrite: true
3. 测试
在Tomcat首页随便点几下:
GET _cat/indices
green open tomcat-access-2020.04 HvD0vJOkROa_etei9vA2KQ 5 1 1 0 33.5kb 16.7kb