CentOS 上 Filebeat 采集不到日志 是很常见的问题,通常不是 Filebeat 本身坏了,而是配置、权限、路径或系统环境导致的。下面按最常见原因 → 排查方法 → 解决办法给你系统梳理一下。
systemctl status filebeat
# 或
ps -ef | grep filebeat
如果没运行:
systemctl start filebeat
systemctl enable filebeat
示例(正确):
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
❌ 常见错误:
/*检查:
ls -l /var/log/nginx/access.log
Filebeat 默认以 filebeat 用户运行。
查看:
ls -l /var/log/xxx.log
如果权限是:
-rw------- root root
Filebeat 读不了。
解决:
chmod 644 /var/log/xxx.log
# 或
usermod -aG root filebeat
查看:
getenforce
如果是 Enforcing:
临时验证:
setenforce 0
如果这样能采集 → 就是 SELinux 问题。
解决(推荐):
setsebool -P filebeat_can_read_logs on
或修改日志文件上下文:
semanage fcontext -a -t var_log_t "/your/log/path(/.*)?"
restorecon -Rv /your/log/path
Filebeat 默认 不会跟随软链接。
错误示例:
paths:
- /var/log/app.log # 实际是软链
解决:
paths:
- /var/log/app/app.log-*
或开启:
symlinks: true
Filebeat 会记录读取位置:
/var/lib/filebeat/registry
如果你:
解决(测试环境):
systemctl stop filebeat
rm -rf /var/lib/filebeat/registry
systemctl start filebeat
检查 output:
output.elasticsearch:
hosts: ["http://localhost:9200"]
测试连通:
curl http://localhost:9200
看 Filebeat 日志:
journalctl -u filebeat -f
常见错误:
Filebeat 只采集新增内容。
测试:
echo "test log" >> /var/log/xxx.log
systemctl status filebeat
journalctl -u filebeat -n 50
ls -l 日志路径
getenforce
cat /etc/filebeat/filebeat.yml
你可以直接贴:
filebeat.yml 相关配置journalctl -u filebeat 报错我可以直接帮你 定位是哪一类问题。