“Ubuntu 上 Filebeat 报错”这个问题比较宽泛,因为 Filebeat 的报错原因非常多,通常和配置、权限、环境、版本有关。下面我按 常见报错类型 + 原因 + 解决办法 给你梳理一下,你可以对照自己的报错信息看是哪一种。
报错示例
Exiting: error loading config file: config file ("/etc/filebeat/filebeat.yml") can only be writable by the owner
或
permission denied
原因
解决
sudo chown root:root /etc/filebeat/filebeat.yml
sudo chmod 644 /etc/filebeat/filebeat.yml
读日志权限:
sudo usermod -aG adm filebeat
报错示例
YAML config parsing failed: yaml: line 12: did not find expected key
原因
解决
sudo filebeat test config
或
sudo filebeat -e -c /etc/filebeat/filebeat.yml
报错示例
connection attempt failed: dial tcp 127.0.0.1:9200: connection refused
原因
解决
sudo systemctl status elasticsearch
curl http://localhost:9200
确认 filebeat.yml:
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "xxx"
报错示例
No modules found
或
path does not exist
解决
sudo filebeat modules enable system
sudo filebeat setup
检查日志路径:
ls /var/log/
报错示例
systemctl status filebeat
原因
解决
sudo journalctl -u filebeat -xe
sudo rm -rf /var/lib/filebeat/registry
sudo systemctl restart filebeat
# 1. 测试配置
sudo filebeat test config
# 2. 前台运行看详细错误
sudo filebeat -e -c /etc/filebeat/filebeat.yml
# 3. 看系统日志
journalctl -u filebeat -xe
# 4. 看版本
filebeat version
如果你愿意,把下面任意一个贴出来,我可以直接帮你定位:
filebeat.yml 相关配置你现在的报错是哪一种?我可以直接帮你改配置。