下面以 CentOS 7/8 为例,给你一个从安装到配置的 Filebeat 实战说明(以采集日志并发送到 Elasticsearch / Logstash 为例)。
sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
sudo cat > /etc/yum.repos.d/filebeat.repo <<EOF
[elastic-8.x]
name=Elastic repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
sudo yum install filebeat -y
如果你用的是 Elasticsearch 7.x,把
8.x改成7.x
配置文件路径:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /app/logs/*.log
output.elasticsearch:
hosts: ["http://192.168.1.10:9200"]
username: "elastic"
password: "yourpassword"
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
output.logstash:
hosts: ["192.168.1.20:5044"]
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after
fields:
env: production
app: nginx
fields_under_root: true
ignore_older: 24h
systemctl enable filebeat
systemctl start filebeat
查看状态:
systemctl status filebeat
filebeat test config
filebeat test output
journalctl -u filebeat -f
# 或
tail -f /var/log/filebeat/filebeat
paths:
- /var/log/nginx/*.log
paths:
- /var/lib/docker/containers/*/*.log
filebeat.inputs:
- type: log
paths:
- /app/a/logs/*.log
tags: ["app-a"]
- type: log
paths:
- /app/b/logs/*.log
tags: ["app-b"]
如果你有 具体日志路径 / 发送到哪(ES、Logstash、Kafka) / CentOS 版本,我可以帮你写一份可直接用的 filebeat.yml。