1、首先是filebeat配置自定义索引名称配置
vim filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log 修改为需要读取的日志路径
tags: ["nginx"] #标签名自定义
output.elasticsearch:
hosts: ["192.168.11.139:9200"]
indices:
- index: "filebeat-nginx-%{+yyyy.MM.dd}" #filebeat-nginx替换为你想要的索引名称。%{+yyyy.MM.dd}是年月日的标识方便分辨索引日期
when.contains:
tags: "nginx" #标签名和上面一直
nohup ./filebeat -e -c filebeat.yml > filebeat.log & 修改完配置运行filebeat
vim filebeat.log 查看一下运行日志
提示启动和输入完成 1 那么索引就已经生成了
2、还有要说的就说在使用过程用遇到的坑,我使用的是filebeat7.8版本
遇到的问题有索引删除后重启filebeat后当天不在生成新的索引
还有就是更新filebeat配置文件后重启filebeat配置没有生效
如果大家也遇到这样的问题不要慌可能是版本的问题
ps -ef |grep filebeat
kill -9 13482
rm -rf filebeat/data/registry/filebeat
停掉filebeat服务 然后删除filebeat工作目录 最后在启动即可
nohup ./filebeat -e -c filebeat.yml > filebeat.log & 运行filebeat
3、采集error日志时开发经常会看java的报错,但是java报错一般都很长使用默认配置的话filebeat采集出来的日志是一行一行的,看起来非常的不方便
根据需求我们重新配置一下filebeat即可
vim filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/log/error.log
multiline.pattern: '^20' #正则表达式是以20 开头的行
multiline.negate: true #参数将匹配结果取反,表示将非匹配行合并到上一行中
multiline.match: after #参数来指定合并行的位置,这里我们使用 after 表示合并到下一行
tags: ["error"]
output.elasticsearch:
hosts: ["192.168.197.136:9200"]
indices:
- index: "nginx-1-error-%{+yyyy.MM.dd}"
when.contains:
tags: "error"
ps -ef |grep filebeat kill -9 进程号
rm -rf filebeat/data/registry/filebeat 删除filebeat工作目录
nohup ./filebeat -e -c filebeat.yml > filebeat.log & 运行filebeat
然后来到kibana在看一下展示的内容就会发现整段报错都展示出来了。