温馨提示×

ubuntu filebeat怎么配置

小樊
36
2026-09-20 11:07:14
栏目: 智能运维

下面给你一个 Ubuntu 上 Filebeat 配置 的实用指南,从安装到常见使用场景(系统日志 / 自定义日志 / 输出到 Elasticsearch 或 Logstash)。


一、安装 Filebeat(Ubuntu)

1. 使用官方仓库安装(推荐)

sudo apt update
sudo apt install -y filebeat

2. 查看版本

filebeat version

二、Filebeat 主配置文件

配置文件位置:

/etc/filebeat/filebeat.yml

三、基础配置示例

示例 1:采集系统日志 → Elasticsearch

filebeat.inputs:
  - type: filestream
    id: system-log
    paths:
      - /var/log/syslog
      - /var/log/auth.log

output.elasticsearch:
  hosts: ["http://localhost:9200"]
  username: "elastic"
  password: "your_password"

示例 2:采集系统日志 → Logstash

filebeat.inputs:
  - type: filestream
    id: system-log
    paths:
      - /var/log/syslog

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

四、采集自定义应用日志

例如应用日志在:

/var/log/myapp/app.log
filebeat.inputs:
  - type: filestream
    id: myapp-log
    paths:
      - /var/log/myapp/*.log
    fields:
      app: myapp

五、启用 Filebeat 模块(可选,很常用)

查看可用模块

sudo filebeat modules list

启用系统模块

sudo filebeat modules enable system

修改模块配置(如 nginx、mysql)

/etc/filebeat/modules.d/system.yml

六、测试与启动

1. 测试配置

sudo filebeat test config
sudo filebeat test output

2. 设置开机启动

sudo systemctl enable filebeat

3. 启动 Filebeat

sudo systemctl start filebeat

4. 查看状态

sudo systemctl status filebeat

七、日志排查

journalctl -u filebeat -f

tail -f /var/log/filebeat/filebeat

八、常见注意点

✅ Ubuntu 20.04+ 推荐使用 filestream(不是 log
✅ 路径权限问题(filebeat 用户需可读)
✅ Elasticsearch 未启动会导致输出失败
✅ 多行日志需配置 multiline

多行日志示例(Java 异常)

multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after

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

  • Ubuntu 版本
  • Filebeat 输出目标(ES / Logstash / Kafka)
  • 要采集的日志类型(系统 / Nginx / Docker / 自定义)

我可以直接帮你写一份 完整可用的 filebeat.yml

0