在 CentOS 上调试 Filebeat 问题,通常可以从日志、配置、运行状态、调试模式几个方面入手。下面给你一套实用排查思路。
journalctl -u filebeat -f
或查看历史:
journalctl -u filebeat --since "1 hour ago"
默认日志位置(取决于配置):
/var/log/filebeat/filebeat.log
如果没有日志:
ls -l /var/log/filebeat/
systemctl status filebeat
常见异常:
active (running) ✅failed ❌inactive ⚠️重启命令:
systemctl restart filebeat
filebeat test config
filebeat test output
编辑配置文件:
vi /etc/filebeat/filebeat.yml
在末尾或 logging 段加入:
logging.level: debug
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat.log
重启:
systemctl restart filebeat
然后查看:
tail -f /var/log/filebeat/filebeat.log
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/*.log
检查:
ls -l /var/log/nginx/
注意:
symlinks: true)ls -l /var/log/xxx.log
Filebeat 运行用户:
ps -ef | grep filebeat
如果是 root 启动的,一般不会有权限问题;
否则需要:
chmod +r /var/log/xxx.log
检查 SELinux:
getenforce
如果是 Enforcing:
setenforce 0 # 临时关闭
或添加策略(推荐):
semanage fcontext -a -t var_log_t "/your/log/path(/.*)?"
restorecon -Rv /your/log/path
output.elasticsearch:
hosts: ["http://localhost:9200"]
测试:
curl -X GET "localhost:9200/_cat/indices?v"
output.logstash:
hosts: ["localhost:5044"]
在 Logstash 上确认:
tcpdump -i lo port 5044
Filebeat 记录采集位置:
/var/lib/filebeat/registry
有时文件被删或 inode 变化会导致不采集:
systemctl stop filebeat
rm -rf /var/lib/filebeat/registry
systemctl start filebeat
⚠️ 会重新采集所有日志
filebeat test config
filebeat test output
filebeat export config
systemctl status filebeat
journalctl -u filebeat -f
| 问题 | 可能原因 |
|---|---|
| 没日志 | 路径错 / 权限不足 |
| 日志不更新 | registry 问题 |
| 启动失败 | yml 格式错误 |
| ES 无数据 | output 配置错 |
| SELinux 拦截 | 日志读不到 |
如果你愿意,可以贴出:
filebeat.ymljournalctl -u filebeat 报错我可以帮你精准定位问题。