在 CentOS 上使用 Filebeat(属于 Elastic Stack)一般分为 安装 → 配置 → 启动 → 验证 几个步骤。下面给你一个从零开始的实战流程,假设你是要把日志发送到 Elasticsearch 或 Logstash。
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo tee /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
安装完成后,Filebeat 会在:
- 配置目录:
/etc/filebeat/- 二进制:
/usr/bin/filebeat- 日志:
/var/log/filebeat/
配置文件路径:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages
output.elasticsearch:
hosts: ["localhost:9200"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
output.logstash:
hosts: ["localhost:5044"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/app/*.json
json.keys_under_root: true
json.add_error_key: true
filebeat test config
测试输出:
filebeat test output
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
systemctl status filebeat
查看日志:
journalctl -u filebeat -f
如果发送到 ES:
curl -X GET "localhost:9200/_cat/indices?v"
你应该能看到类似:
filebeat-8.x.x-2026.xx.xx
在 Kibana → Discover 中:
filebeat-*filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
filebeat.inputs:
- type: container
paths:
- /var/lib/docker/containers/*/*.log
journalctl -u filebeat --no-pager | tail -n 50
output.elasticsearch.hosts 正确output.elasticsearch:
hosts: ["https://es-host:9200"]
username: "elastic"
password: "xxxxxx"
ssl.verification_mode: none
sudo systemctl stop filebeat
sudo yum remove filebeat -y
sudo rm -rf /etc/filebeat /var/log/filebeat
registry 目录如果你愿意,可以告诉我:
我可以帮你写一套 完整的 filebeat.yml ✅