想把log统一管理起来,第一个想到的就是ELK了。
先下载解压缩filebeat
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.7.2-linux-x86_64.tar.gz
tar xzvf filebeat-6.7.2-linux-x86_64.tar.gz
修改配置文件, 默认的配置文件是filebeat.yml
cd filebeat-6.7.0-darwin-x86_64
vim filebeat.yml
把enabled设置成true才能生效,paths就是指定的log目录
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
配置es的output
output.elasticsearch:
hosts: ["<es_url>"]
username: "elastic"
password: "<password>"
配置kibana访问地址,如果是https的url开始请加上https://,不然报错找不到地址
setup.kibana:
host: "<kibana_url>"
开启logstash module,在filebeat目录下执行如下命令
./filebeat modules enable logstash
然后可以在modules.d目录下修改logstash.yml的配置
cd modules.d
vim logstash.yml
启动filebeat
#The setup command loads the Kibana dashboards. If the dashboards are already set up, omit this command.
#./filebeat setup
./filebeat -e
坑
检测到了log的变化,但是没有写入到ES,根据报错信息大概知道是index找不到,并且ES没有开启自动创建index的功能,解决办法是开启自动创建index的配置,或者根据报错信息手动创建一个(PUT /index_name)
{"type":"index_not_found_exception","reason":"no such index and [action.auto_create_index] contains [-*] which forbids automatic creation of the index","index_uuid":"_na_","index":"filebeat-6.7.2-2019.09.17"}
#在kibana管理界面中点击DevTools,然后通过命令手动创建一个index
PUT /filebeat-6.7.2-2019.09.17