1.配置filebeat收集error日志
在实际生产环境中,仅仅采集正常的业务访问日志通常无法满足运维需求,因为错误日志往往包含了系统异常、应用报错等关键信息,必须将其纳入统一监控体系。
针对整个集群,我们需要对Filebeat进行标准化配置。核心思路是在原有的日志输入基础上,新增针对错误日志的采集规则,这本质上是为错误日志定义独立的type标签以及对应的ES索引名称。
vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/www_access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["www"]
- type: log
enabled: true
paths:
- /var/log/nginx/bbs_access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["bbs"]
- type: log
enabled: true
paths:
- /var/log/nginx/blog_access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["blog"]
- type: log
enabled: true
paths:
- /var/log/nginx/error.log
tags: ["error"]
output.elasticsearch:
hosts: ["192.168.81.210:9200"]
indices:
- index: "nginx-www-access-%{+yyyy.MM.dd}"
when.contains:
tags: "www"
- index: "nginx-bbs-access-%{+yyyy.MM.dd}"
when.contains:
tags: "bbs"
- index: "nginx-blog-access-%{+yyyy.MM.dd}"
when.contains:
tags: "blog"
- index: "nginx-error-%{+yyyy.MM.dd}"
when.contains:
tags: "error"
systemctl restart filebeat
2.查看es是否产生error索引
完成配置重启服务后,检查Elasticsearch集群状态,确认名为nginx-error或类似命名的索引已成功创建,表明数据管道已正确将错误日志写入指定存储。

3.在kibana上关联es索引
登录Kibana管理界面,依次点击Management菜单下的Stack Management中的Index Patterns选项,然后点击Create index pattern按钮开始新建索引模式。

配置完成后,系统提示创建成功,此时该索引模式已注册到Kibana元数据中,允许后续查询操作识别该索引下的文档结构。

4.在kibana上统计错误日志
返回Kibana主界面的Discover页面,从下拉菜单中选择刚才创建的错误日志索引,即可浏览具体日志内容。用户可根据时间范围、关键字等条件自定义筛选和统计维度。

以上即为Filebeat同时收集错误日志与普通日志并存的详细实施步骤。如需了解更多关于Filebeat多源日志处理的高级技巧,建议参考本站其他相关技术文章。