温馨提示×

怎样调试debian filebeat

小樊
33
2026-09-21 16:52:59
栏目: 智能运维

下面按常见排查顺序给你一套在 Debian 上调试 Filebeat 的实用方法,从“先看日志”到“抓数据”。


一、基础状态检查

1. 查看 Filebeat 是否运行

systemctl status filebeat

没运行就启动:

systemctl start filebeat

开机自启:

systemctl enable filebeat

二、查看日志(最重要)

2. Filebeat 日志位置

Debian 默认日志在:

/var/log/filebeat/filebeat

实时查看:

journalctl -u filebeat -f

tail -f /var/log/filebeat/filebeat

常见错误:

  • No outputs are defined
  • connection refused
  • permission denied(文件读不了)

三、用测试命令调试(非常有用)

3. 测试配置文件是否正确

filebeat test config

只输出 Config OK 才行。


4. 测试输出(Elasticsearch / Logstash)

filebeat test output

例如 Elasticsearch 会显示:

  • 是否能连接
  • 认证是否通过

5. 干跑模式(不真正发送)

filebeat -e -d "*" -c /etc/filebeat/filebeat.yml

说明:

  • -e:日志输出到终端
  • -d "*":打开所有调试
  • Ctrl+C 停止

适合排查为什么没数据


四、确认输入配置是否正确

6. 检查 inputs

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/nginx/*.log

常见错误:

  • enabled: false
  • 路径写错
  • 文件权限不足(Filebeat 用户读不了)

测试文件是否可读:

sudo -u filebeat cat /var/log/nginx/access.log

五、Registry 问题(重复/不采集)

7. 清理 registry(谨慎)

Filebeat 记录采集位置:

/var/lib/filebeat/registry

如果“文件改了但不采集”或“重复采集”:

systemctl stop filebeat
rm -rf /var/lib/filebeat/registry
systemctl start filebeat

⚠️ 会重新从头采集


六、确认输出是否收到数据

Elasticsearch

GET filebeat-*/_search
{
  "size": 1,
  "sort": [{ "@timestamp": "desc" }]
}

Logstash

看 Logstash 日志:

/var/log/logstash/logstash-plain.log

七、开启 debug 日志(写文件)

logging.level: debug
logging.to_files: true
logging.files:
  path: /var/log/filebeat
  name: filebeat

八、常见坑总结

问题 原因
没数据 paths 错 / enabled false
权限拒绝 文件属主不对
ES 收不到 output 配错
重复日志 registry 损坏
CPU 高 scan_frequency 太小

如果你愿意,可以把:

  • filebeat.yml
  • 报错日志
  • 使用场景(ES / Logstash / Kafka)

发出来,我可以直接帮你定位问题。

0