使用Filebeat采集系统日志步骤如下:
安装Filebeat
sudo apt-get update && sudo apt-get install filebeatsudo yum install filebeat配置Filebeat
/etc/filebeat/filebeat.yml:
filebeat.inputs 中添加 paths,如 - /var/log/*.log。output.elasticsearch(发送到Elasticsearch)或 output.logstash(发送到Logstash),并配置地址,例如:output.elasticsearch:
hosts: ["localhost:9200"]
```。
multiline 配置。processors(如 dissect 解析非JSON日志)。启动并验证
sudo systemctl start filebeat。sudo systemctl enable filebeat。sudo tail -f /var/log/filebeat/filebeat.log。说明:配置文件中 paths 可根据实际需求调整,如监控特定日志文件(如 /var/log/syslog)或排除某些文件(如 exclude_files: [".gz$"])。如需更复杂功能(如Kafka输出、索引模板),可参考官方文档扩展配置。