摘要:
默认系统日志日期是不包含年的,为了方便采集到ELK,可以改成年月日的标准格式,看上去也更友好一些Apr 16 22:10:01 dev01 ...
默认系统日志日期是不包含年的,为了方便采集到ELK,可以改成年月日的标准格式,看上去也更友好一些
Apr 16 22:10:01 dev01 systemd: Started Session 3197 of user root. Apr 16 22:20:01 dev01 systemd: Started Session 3198 of user root. Apr 16 22:30:01 dev01 systemd: Started Session 3199 of user root.
具体更改方法:
cat > /etc/rsyslog.d/newdateformat.conf << \EOF $template myformat,"%$NOW% %TIMESTAMP:8:15% %HOSTNAME% %syslogtag% %msg%\n" $ActionFileDefaultTemplate myformat EOF systemctl restart rsyslog
修改后时间格式为:
2020-04-16 23:15:27 dev01 systemd: Stopped System Logging Service. 2020-04-16 23:15:27 dev01 systemd: Starting System Logging Service...
Logstash配置:因为不是json格式,所以需要grok模块对日志格式化匹配,然后使用date模块匹配日志里的时间格式:
grok { match => { "message" => "%{TIMESTAMP_ISO8601:syslogtime}" } } date { match => ["syslogtime", "yyyy-MM-dd HH:mm:ss"] target => "@timestamp" }
filebeat配置:inputs.d/systemlog.yml
- type: log enabled: true paths: - /var/log/messages exclude_lines: '[[:graph:] ]+filebeat[[:graph:] ]+' tags: ["syslog"] fields: svcname: syslog logtype: sys-messages - type: log enabled: true paths: - /var/log/secure tags: ["syslog"] fields: svcname: syslog logtype: sys-secure
kibana日志展示:
还没有评论,来说两句吧...