温馨提示×

debian filebeat怎样看日志

小樊
43
2026-10-12 06:42:22
栏目: 智能运维

在 Debian 上,Filebeat 本身不“显示”日志内容,它的作用是采集日志并发送到 Elasticsearch / Logstash / Kafka 等。
所以“看日志”通常分几种情况,我按常见场景给你说明。


一、看 Filebeat 自己的运行日志(排错用)

1. 使用 systemd(最常见)

如果你是用 apt 安装的 Filebeat:

sudo journalctl -u filebeat -f

查看历史日志:

sudo journalctl -u filebeat --since "1 hour ago"

2. 查看日志文件

Filebeat 默认日志路径:

/var/log/filebeat/filebeat

查看:

sudo tail -f /var/log/filebeat/filebeat

二、看 Filebeat 采集了哪些日志(配置是否正确)

1. 查看配置文件

sudo cat /etc/filebeat/filebeat.yml

重点看:

filebeat.inputs:
- type: log
  paths:
    - /var/log/*.log

2. 测试配置是否正确

sudo filebeat test config

3. 测试输出(ES / Logstash)

sudo filebeat test output

三、看 Filebeat 实际采集到的日志内容

✅ 方式 1:直接看原始日志文件(最简单)

Filebeat 只是读文件:

sudo tail -f /var/log/nginx/access.log

✅ 方式 2:输出到控制台(调试非常有用)

修改 /etc/filebeat/filebeat.yml:

output.console:
  pretty: true

然后运行:

sudo filebeat -e -c /etc/filebeat/filebeat.yml

你会看到 Filebeat 采集到的每一条日志 JSON。

⚠️ 调试完记得改回:

output.elasticsearch:
  hosts: ["localhost:9200"]

四、看已经发送到 Elasticsearch 的日志

1. 用 Kibana(推荐)

  • 打开 Kibana
  • Stack Management → Index Patterns
  • 创建 filebeat-*
  • Discover 中查看

2. 用 curl 查 ES

curl -X GET "localhost:9200/filebeat-*/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "size": 10,
  "sort": [{ "@timestamp": "desc" }]
}'

五、常见问题排查

Filebeat 没日志?

sudo filebeat modules enable system
sudo filebeat setup
sudo systemctl restart filebeat

权限问题

sudo usermod -aG adm filebeat

总结(快速命令)

# 看 filebeat 状态
systemctl status filebeat

# 看运行日志
journalctl -u filebeat -f

# 看采集配置
cat /etc/filebeat/filebeat.yml

# 调试输出
filebeat -e -c /etc/filebeat/filebeat.yml

如果你能告诉我:

  • 日志来源(nginx / 自定义 / docker)
  • 输出到哪(ES / Logstash / 本地)

我可以给你更精确的命令。

0 踩