ElastAlert教程10章:filebeat输出到ElasticSearch中
filebeat收集日志后,需要发送给elasticSearch,这样ElastAlert才能从elasticSearch中定时获取数据来计算是否需要告警。
所以,我们本课就先将filebeat辛辛苦苦收集的数据放到ES中吧。
filebeat将数据推送到ES中
要将日志数据推送到 elasticSearch 中非常简单,只需要修改配置文件test4.yml即可
filebeat.inputs: - type: log enabled: true paths: ["/root/logs/*.log"] output.console: pretty: true enable: true output.elasticsearch: hosts: ["localhost:9200"]
这里是将 /root/logs 中的数据推送到 ES 中,我们这里 ES 和 filebeat 是在一台机器上的,所以,hosts填写 localhost 就可以了,9200 是 ES 的默认端口。
执行代码,运行 filebeat :
./filebeat -e -c test4.yml
我们会发现会输出如下的错误:
[root@my-node filebeat-7.1.1-linux-x86_64]# ./filebeat -e -c test4.yml Exiting: error unpacking config data: more than one namespace configured accessing 'output' (source:'test4.yml')
意思是多了一个 output 命名空间,配置文件中不能同时出现2个output。我们去掉配置文件中多的一个 output ,如下:
filebeat.inputs: - type: log enabled: true paths: ["/root/logs/*.log"] output.elasticsearch: hosts: ["localhost:9200"]
然后在重新执行启动 filebeat 命令 :
./filebeat -e -c test5.yml
查看ES中的数据
我们在/root/logs目录新建一个1.log文件,然后我们向 1.log 中继续输入数据:
echo aaa >> /root/logs/1.log
这时,数据就会被filebeat收集,并传入 ES 中,打开 elastic header :
按照上面的步骤查找, 你就能看到刚才录入的数据:
红色框中的就是刚才输入的数据。
好了,数据现在进入ES了,大功告成。可以开始王者荣耀了。
学习为了什么,为了享受啊,来一把王者荣耀。欢迎大家加入我们的王者荣耀群:
