Ubuntu 上 Filebeat 错误排查步骤
一 快速定位与日志获取
sudo systemctl status filebeat -l 与 sudo journalctl -xe -u filebeat.service。sudo journalctl -u filebeat.service -f。sudo tail -f /var/log/filebeat/filebeat.log。sudo filebeat -c /etc/filebeat/filebeat.yml -e,能快速暴露 YAML 解析、模块加载、输出连接 等初始化错误。logging.level: debug,并重启服务:sudo systemctl restart filebeat,随后查看 /var/log/filebeat/filebeat.log 获取更细粒度信息。二 配置与语法检查
sudo yamllint /etc/filebeat/filebeat.yml;YAML 对缩进敏感,常见错误为列表项或层级不一致。filebeat.inputs 中 type、enabled、paths 等字段正确,路径是否存在且可访问。output.logstash.hosts 一般为 [“host:5044”];若启用 SSL/TLS,需补充 ssl.certificate_authorities、ssl.verification_mode 等。output.elasticsearch.hosts 如 [“http://host:9200”];若启用 安全认证,需配置 username/password 或 API Key。sudo systemctl restart filebeat,并立即查看 journalctl 与 filebeat.log 的输出。三 运行与连通性验证
sudo systemctl is-active filebeat(期望返回 active)。telnet logstash-host 5044 或 nc -vz logstash-host 5044。curl -X GET "http://elasticsearch:9200"(如启用 HTTPS/认证,需相应调整 URL 与头部)。四 权限与采集路径问题
sudo chmod o+r /path/to/your.log。paths 是否指向真实存在的文件或通配路径;若路径错误或文件被轮转移除,Filebeat 将无数据可读。add_docker_metadata 处理器;确保 Docker 日志驱动为 json-file/journald 且 Filebeat 可访问 Docker 套接字或日志文件。五 数据是否到达与端到端验证
curl -X GET "http://localhost:9200/_cat/indices?v",应能看到 filebeat-* 或自定义索引。curl -X GET "http://localhost:9200/filebeat-*/_search?pretty&q=*",验证是否有文档写入。