轉載 : ELK收集nginx正常和錯誤日誌 :https://www.jianshu.com/p/ef62538724f7
1.修改filebeat配置文件
在53主機操作
[root@db01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
##收集正常日誌
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["access"]
##收集錯誤日誌
- type: log
enabled: true
paths:
- /var/log/nginx/error.log
tags: ["error"]
setup.kibana:
host: "172.16.210.53:5601"
##根據標籤來決定把日誌放進正確日誌索引和錯誤日誌索引
output.elasticsearch:
hosts: ["172.16.210.53:9200"]
indices:
- index: "nginx-access-%{[beat.version]}-%{+yyyy.MM}"
when.contains:
tags: "access"
- index: "nginx-error-%{[beat.version]}-%{+yyyy.MM}"
when.contains:
tags: "error"
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
setup.template.enabled: false
setup.template.overwrite: true
2.重啓filebeat
[root@db01 ~]# systemctl restart filebeat
3.使用ab工具來產生一些日誌
[root@db01 ~]# ab -n 100 -c 100 http://172.16.210.53/cc.html
4.使用es-head插件查看
能發現生成的兩個索引,分別是正常日誌和錯誤日誌
5.回到kibana添加數據項並查看項目
創建正常日誌索引
創建錯誤日誌索引
選擇要查看的索引項
查看access日誌
查看error日誌
要是想查看其他主機的正常和錯誤日誌的話,就把53主機的filebeat配置文件拷貝過去,再重啓filebeat
在53主機操作:
[root@db01 ~]# scp /etc/filebeat/filebeat.yml db02:/etc/filebeat/
[root@db01 ~]# scp /etc/filebeat/filebeat.yml db03:/etc/filebeat/
在54和55主機操作:
systemctl restart filebeat
在53主機操作
##給54和55主機產生一些錯誤日誌
[root@db01 ~]# ab -n 100 -c 100 http://172.16.210.54/4444.html
[root@db01 ~]# ab -n 100 -c 100 http://172.16.210.55/5555.html
回到kibana界面,添加主機名爲db02的過濾項
就能查看db02主機的錯誤日誌了
過濾db03,也能查看到db03的錯誤日誌