使用filebeat自带模块读取nginx日志和mysql日志,保存到elasticsearch
网上很多教程都是filebeat读取文件,发送到logstash再解析,然后发送到elasticsearch
找了很久没有找到filebeat读取文件发送到elasticsearch的,今天自己学习记录下
参考文档 filebeat命令文档,filebeat modules文档
配置 filebeat.yml
~~~yaml
output.elasticsearch:
enabled: true
hosts: ["192.168.0.202:9200"]
#index: "log-%{[event.dataset]}-%{+yyyy.MM.dd}" 也可以不用配置下面的indices,直接配置这个即可
#默认索引格式 filebeat-%{[agent.version]}-%{+yyyy.MM.dd}
indices:
#自定义索引,更细粒度的控制索引,注意不会使用到filebeat索引模板,想要特定的字段类型 需要自己配置索引模板
- index: "log-%{[event.dataset]}-%{+yyyy}" #按年索引
#条件语法参考https://www.elastic.co/guide/en/beats/filebeat/7.9/defining-processors.html#conditions
when.equals:
#需要提前知道数据格式 再决定如何判断
event.module: "mysql"
- index: "log-%{[event.dataset]}-%{+yyyy.MM.dd}" #按天索引
when.equals:
event.module: "nginx"
运行filebeat
通过命令开启 不需要改模块配置文件
#运行filebeat -e输出详细日志 -modeules
./filebeat run -e -modules=mysql,nginx -M

最低0.47元/天 解锁文章
270





