在 CentOS 上排查 Filebeat 问题,一般可以按下面步骤系统地进行。
systemctl status filebeat
如果没启动:
systemctl start filebeat
systemctl enable filebeat
ps -ef | grep filebeat
/var/log/filebeat/filebeat
实时查看:
tail -f /var/log/filebeat/filebeat
常见错误示例:
No such file or directory → 日志路径不对connection refused → 无法连接 ES / Logstash / KafkaExponential backoff → 输出端异常/etc/filebeat/filebeat.yml
filebeat test config
filebeat test output
ls -l /var/log/xxx/*.log
ps -ef | grep filebeat
默认用户是 root 或 filebeat
若日志文件权限不足:
chmod 644 /var/log/xxx.log
临时关闭测试:
setenforce 0
如解决问题:
getenforce
可放行日志目录:
semanage fcontext -a -t var_log_t "/data/logs(/.*)?"
restorecon -Rv /data/logs
示例:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/*.log
修改后必须重启:
systemctl restart filebeat
output.elasticsearch:
hosts: ["http://localhost:9200"]
测试:
curl http://localhost:9200
output.logstash:
hosts: ["localhost:5044"]
端口是否监听:
ss -lntp | grep 5044
编辑:
/etc/filebeat/filebeat.yml
logging.level: debug
logging.selectors: ["*"]
重启:
systemctl restart filebeat
如果日志“不采集”或“重复采集”:
systemctl stop filebeat
rm -rf /var/lib/filebeat/registry
systemctl start filebeat
⚠️ 会重新读取所有日志
| 问题 | 原因 |
|---|---|
| 无数据 | paths 写错 |
| 连不上 ES | 端口/账号错误 |
| 权限拒绝 | SELinux / 文件权限 |
| 数据重复 | registry 损坏 |
| CPU 高 | 日志量过大 |
如果你愿意,可以把 filebeat.yml(脱敏) 或 报错日志贴出来,我可以直接帮你定位问题。