前面使用json格式收集了nginx的日志,但是再index的显示是filebeat-*,现在使用自定义的index进行配置
但是再使用filebeat的7.4版本以后,有一个巨坑,就是按照网络的很多配置,最后显示的结果依然是filebeat的默认index
一 自定义index
1.1 配置index
[root@node4 src]# vim /etc/filebeat/filebeat.yml
会报一个错误
Jan 19 03:23:08 node4 filebeat: Exiting: setup.template.name and setup.template.pattern have to be set if index name is modified
1.2 添加模板
[root@node4 src]# vim /etc/filebeat/filebeat.yml
重启之后,依然没有生效
看到这个日志
Jan 19 03:25:35 node4 filebeat: 2020-01-19T03:25:35.493-0500#011INFO#011[index-management]#011idxmgmt/std.go:394#011Set setup.template.name to '{filebeat-7.4.2 {now/d}-000001}' as ILM is enabled. Jan 19 03:25:35 node4 filebeat: 2020-01-19T03:25:35.493-0500#011INFO#011[index-management]#011idxmgmt/std.go:399#011Set setup.template.pattern to 'filebeat-7.4.2-*' as ILM is enabled. Jan 19 03:25:35 node4 filebeat: 2020-01-19T03:25:35.493-0500#011INFO#011[index-management]#011idxmgmt/std.go:433#011Set settings.index.lifecycle.rollover_alias in template to {filebeat-7.4.2 {now/d}-000001} as ILM is enabled.
1.3 配置ILM
检查ILM这个关键字
https://www.elastic.co/guide/en/beats/filebeat/current/ilm.html
官方解释如下
配置
1.4 重启之后检查
终于配置出来,在这里折腾了好几个小时
二 收集多台机器日志
2.1 配置多台nginx 并检查
node4:192.168.132.134 nginx filebeat
node4:192.168.132.134 nginx filebeat
node4:192.168.132.134 nginx filebeat
相同的安装和配置
[root@node4 ~]# netstat -ntlp
[root@node4 ~]# systemctl status filebeat
访问各个节点,然后查看日志,已经收集
2.2 配置错误日志
配置错误日志并配置索引分开
[root@node4 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs: - type: log enabled: true paths: - /usr/local/nginx/logs/access.log json.key_under_root: true json.overwrite_keys: true tags: ["access"] - type: log enabled: true paths: - /usr/local/nginx/logs/error.log tags: ["error"] setup.kibana: host: "192.168.132.131:5601" output.elasticsearch: hosts: ["192.168.132.131:9200","192.168.132.132:9200","192.168.132.133:9200"] #index: "nginx-%{[agent.version]}-%{+yyyy.MM.dd}" indices: - index: "access-%{[agent.version]}-%{+yyyy.MM.dd}" when.contains: tags: "access" - index: "error-%{[agent.version]}-%{+yyyy.MM.dd}" when.contains: tags: "error" setup.template.name: "nginx" setup.template.pattern: "nginx-*" setup.template.overwrite: true setup.template.enabled: true setup.ilm.enabled: false
访问后查看
kibana查看你日志
错误日志
nginx的日志收集实验及自定义index介绍到这里