在 CentOS 下配置 Filebeat 一般分为 安装 → 配置 → 启动 → 验证 几步。下面以 Filebeat 7.x / 8.x 为例,给你一个完整、常用的配置示例(以收集日志并发送到 Elasticsearch 为例)。
# 导入 Elastic GPG 密钥
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 下载并安装 Filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.11.0-x86_64.rpm
rpm -ivh filebeat-8.11.0-x86_64.rpm
版本号可根据需要调整
/etc/filebeat/filebeat.yml
vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages
# ================== Elasticsearch 输出 ==================
output.elasticsearch:
hosts: ["http://localhost:9200"]
# 可选:Kibana 配置
setup.kibana:
host: "http://localhost:5601"
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/app/logs/*.log
fields:
app: myapp
fields_under_root: true
output.logstash:
hosts: ["127.0.0.1:5044"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/app/app.log
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after
# 测试配置是否正确
filebeat test config
# 测试输出是否可达
filebeat test output
# 启动 Filebeat
systemctl start filebeat
# 开机自启
systemctl enable filebeat
# 查看状态
systemctl status filebeat
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
filebeat setup
enabled: true 是否设置hostsoutput.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "changeme"
Filebeat → Elasticsearch
Filebeat → Logstash → Elasticsearch → Kibana
如果你愿意,我可以帮你:
直接把你的 使用场景或报错贴出来 即可。