在Debian系统上使用Filebeat分析日志,可以按照以下步骤进行:
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.9.0-linux-x86_64.tar.gz
tar -zxvf filebeat-8.9.0-linux-x86_64.tar.gz
cd filebeat-8.9.0
编辑 /etc/filebeat/filebeat.yml
文件,配置要监控的日志文件路径和输出位置。例如:
filebeat.inputs:
- type: log
paths:
- /var/log/*.log
output.logstash:
hosts: ["localhost:5044"]
./filebeat -e
sudo systemctl enable filebeat
sudo systemctl start filebeat
对于多行日志,可以使用 multiline
配置:
filebeat.inputs:
- type: log
paths:
- /var/log/*.log
multiline:
pattern: '^\['
negate: true
match: after
如果日志是JSON格式的,可以使用 json
配置:
filebeat.inputs:
- type: log
paths:
- /var/log/*.json
json:
keys_under_root: true
overwrite_keys: true
message_key: log
使用以下命令监控Filebeat的运行状态:
sudo systemctl status filebeat
根据实际需求调整配置,如 harvester_limit
、ignore_older
、scan_frequency
等。
更多详细信息和高级配置,请参考 Filebeat官方文档。