温馨提示×

Debian Filebeat怎么配置

小樊
50
2026-08-20 07:27:27
栏目: 智能运维

下面给你一个在 Debian 系统上配置 Filebeat 的完整示例,从安装到常见使用场景(如收集日志并发送到 Elasticsearch 或 Logstash)。


一、安装 Filebeat(Debian)

1. 下载并安装(官方方式,推荐)

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.13.4-amd64.deb
sudo dpkg -i filebeat-8.13.4-amd64.deb

版本号可根据需要调整,建议与 Elasticsearch 版本一致。


二、Filebeat 配置文件位置

/etc/filebeat/filebeat.yml

通常你只需要修改这个文件。


三、最简单配置示例(收集系统日志)

示例:收集 /var/log/*.log

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

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

启动并测试:

sudo filebeat test config
sudo filebeat test output
sudo systemctl restart filebeat

四、常见配置场景


✅ 场景 1:输出到 Elasticsearch(本地)

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

如果 ES 有安全认证:

output.elasticsearch:
  hosts: ["https://es-node:9200"]
  username: "elastic"
  password: "your_password"
  ssl.verification_mode: none

✅ 场景 2:输出到 Logstash

output.logstash:
  hosts: ["127.0.0.1:5044"]

Logstash 示例配置:

input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => ["localhost:9200"]
  }
}

✅ 场景 3:收集多个日志目录

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

  - type: filestream
    enabled: true
    paths:
      - /var/log/mysql/*.log

✅ 场景 4:添加自定义字段(区分来源)

filebeat.inputs:
  - type: filestream
    enabled: true
    paths:
      - /var/log/app/*.log
    fields:
      app: myapp
    fields_under_root: true

五、启用 Filebeat 模块(推荐)

Filebeat 自带很多常见日志模块(nginx、mysql、systemd 等)。

查看可用模块

filebeat modules list

启用模块

sudo filebeat modules enable nginx

配置模块(示例)

/etc/filebeat/modules.d/nginx.yml

六、设置 Filebeat 自动启动

sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat

七、查看 Filebeat 状态与日志

sudo journalctl -u filebeat -f

或:

/var/log/filebeat/filebeat

八、常见排错

1. 没有数据进入 ES

  • 检查 filebeat test output
  • 确认索引是否存在:
curl localhost:9200/_cat/indices

2. 权限问题

sudo chmod 644 /var/log/*.log

3. 时间问题

Filebeat 不会修改日志时间,Elasticsearch 使用 @timestamp


九、最小可用配置(总结)

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

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

如果你愿意,可以告诉我:

  • ✅ Debian 版本(10 / 11 / 12)
  • ✅ 日志类型(nginx / docker / java / 自定义)
  • ✅ 输出目标(ES / Logstash / Kafka)

我可以给你一份完全贴合你环境的 Filebeat 配置

0