定制CentOS Filebeat的日志采集规则,主要通过编辑其配置文件/etc/filebeat/filebeat.yml实现,以下是具体方法:
sudo yum install filebeat进行安装。filebeat.inputs部分,通过paths字段指定要采集的日志文件路径,可使用通配符,如paths: - /var/log/*.log。fields字段中添加自定义字段,如fields: {application: "myapp", environment: "production"},若要将这些字段放在顶级字段,可设置fields_under_root: true。include_lines和exclude_lines字段来包含或排除特定日志行,如include_lines: ['^ERR', '^WARN'],exclude_lines: ['^dbg']。multiline字段配置,如multiline.pattern: '^\[',multiline.negate: true,multiline.match: 'after'等。output部分,指定日志输出目标,如输出到Elasticsearch可配置output.elasticsearch,设置主机地址和端口等;输出到Logstash可配置output.logstash。sudo systemctl restart filebeat重启服务使配置生效。sudo journalctl -u filebeat -f,或查看输出目标(如Elasticsearch)来确认配置是否正确。