CentOS 上 Filebeat 启动失败的定位与修复
一、快速定位
systemctl status filebeat -l 与 journalctl -xeu filebeat,优先关注带有 Active: failed、code=exited, status=1/FAILURE 的行以及具体报错关键词(如配置解析、连接超时、权限拒绝)。yamllint /etc/filebeat/filebeat.yml(若未安装:yum install -y yamllint)。chmod go-w /etc/filebeat/filebeat.yml(或相应自定义配置路径)。output.elasticsearch.hosts 或 output.logstash.hosts 的主机与端口正确,启用 HTTPS/认证/证书 时补充 ssl、username/password、cacert 等参数。paths 指向真实存在的日志文件(如 /var/log/*.log 或应用日志目录),路径错误或文件不存在会导致采集异常。telnet logstash-host 5044curl -X GET "http://es-host:9200"二、常见原因与对应修复
yamllint 修正缩进与语法;逐项核对 output 与 input 配置项。chmod go-w /path/filebeat.yml,仅保留所有者可写。paths 正确、日志文件已生成,必要时调整路径或创建采集所需的目录与文件。firewall-cmd --add-port=5044/tcp --permanent && firewall-cmd --reload(如走 9200/443 同理)。top/htop 检查 CPU/内存,必要时扩容或优化 Filebeat 配置(如批量大小、工作线程)。systemctl reset-failed filebeat && systemctl start filebeat,再观察 journalctl 输出。三、最小可用配置示例
output.logstash:
hosts: ["logstash.example.com:5044"]
telnet logstash.example.com 5044output.elasticsearch:
hosts: ["http://es.example.com:9200"]
username: "elastic"
password: "your_password"
curl -u elastic:your_password http://es.example.com:9200filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/messages
- /var/log/*.log
yamllint /etc/filebeat/filebeat.ymlsystemctl daemon-reload && systemctl start filebeat && tail -f /var/log/filebeat/filebeat.log四、仍未恢复时的建议
systemctl reset-failed filebeat && systemctl start filebeat,并持续观察 journalctl -xeu filebeat 的输出以定位残留问题。