温馨提示×

debian filebeat怎样转发

小樊
34
2026-10-20 23:49:00
栏目: 智能运维

在 Debian 上,Filebeat 转发日志通常有三种常见场景:

  1. 转发到 Elasticsearch
  2. 转发到 Logstash
  3. 转发到其他地方(如 Kafka / Redis)

下面按最常见用法一步一步说明(以 Debian 11/12 为例)。


一、安装 Filebeat(Debian)

sudo apt update
sudo apt install filebeat -y

安装完成后配置文件在:

/etc/filebeat/filebeat.yml

二、基本转发配置(核心)

1️⃣ 采集日志(inputs)

编辑配置文件:

sudo vim /etc/filebeat/filebeat.yml

示例(监听系统日志):

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

老版本可能是 type: log,Debian 新版推荐 filestream


三、转发到不同目标

✅ 方式一:转发到 Elasticsearch(最简单)

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

启动:

sudo systemctl enable filebeat
sudo systemctl start filebeat

查看状态:

sudo systemctl status filebeat

✅ 方式二:转发到 Logstash(最常用)

output.logstash:
  hosts: ["logstash.example.com:5044"]

Logstash 端需有:

input {
  beats {
    port => 5044
  }
}

启动 Filebeat:

sudo systemctl restart filebeat

✅ 方式三:转发到 Kafka(高吞吐)

output.kafka:
  hosts: ["kafka1:9092", "kafka2:9092"]
  topic: "filebeat-logs"

四、启用模块(可选但推荐)

例如系统日志模块:

sudo filebeat modules enable system

然后:

sudo filebeat setup

五、调试与排错

测试配置是否正确

sudo filebeat test config

测试输出是否可达

sudo filebeat test output

查看日志

journalctl -u filebeat -f

六、最小可用示例(转发到 ES)

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

output.elasticsearch:
  hosts: ["http://127.0.0.1:9200"]

如果你能告诉我:

  • 转发到哪里(ES / Logstash / Kafka)
  • Debian 版本
  • 是否使用 TLS / 认证

我可以给你完全适配的配置文件。

0 踩