在 CentOS 上,Filebeat 通常用于监控日志文件(如 /var/log/*.log、Nginx、Java 应用日志等),并把日志发送到 Elasticsearch / Logstash / Kafka。
下面从 安装 → 配置 → 启动 → 验证 一步步说明。
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo cat > /etc/yum.repos.d/filebeat.repo <<EOF
[filebeat]
name=Elasticsearch 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
vi /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
id: syslog
paths:
- /var/log/messages
- /var/log/secure
output.elasticsearch:
hosts: ["http://localhost:9200"]
⚠️ 7.x 以后推荐用
filestream
老版本用log
filebeat.inputs:
- type: filestream
id: nginx-access
paths:
- /var/log/nginx/access.log
- type: filestream
id: nginx-error
paths:
- /var/log/nginx/error.log
- type: filestream
id: app-log
paths:
- /data/app/logs/*.log
output.elasticsearch:
hosts: ["http://192.168.1.10:9200"]
output.logstash:
hosts: ["192.168.1.11:5044"]
output.kafka:
hosts: ["kafka1:9092"]
topic: logs-topic
systemctl enable filebeat
systemctl start filebeat
查看状态:
systemctl status filebeat
filebeat test config
journalctl -u filebeat -f
echo "test log" >> /var/log/messages
scan.at_start: end
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after
fields:
env: prod
app: order-service
Filebeat → Logstash → Elasticsearch → Kibana
如果你愿意,可以告诉我:
我可以直接给你 可用配置文件。