温馨提示×

debian filebeat怎么连es

小樊
36
2026-10-26 22:55:14
栏目: 智能运维

在 Debian 上让 Filebeat 连接 Elasticsearch(ES),一般分为 安装 → 配置 → 启动 三步。下面以 Filebeat 8.x 为例(7.x 也类似,会有少量差异)。


一、安装 Filebeat(Debian)

1. 使用官方 APT 源(推荐)

sudo apt update
sudo apt install curl gnupg -y

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/elastic-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

sudo apt update
sudo apt install filebeat -y

二、配置 Filebeat 连接 ES

1. 编辑配置文件

sudo vim /etc/filebeat/filebeat.yml

2. 基础 ES 连接配置(重点)

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

output.elasticsearch:
  hosts: ["http://ES_IP:9200"]
  username: "elastic"
  password: "你的ES密码"

⚠️ 说明:

  • ES_IP:Elasticsearch 地址
  • 如果 ES 是 HTTPS + 自签证书:
output.elasticsearch:
  hosts: ["https://ES_IP:9200"]
  ssl.verification_mode: none
  username: "elastic"
  password: "密码"

三、加载索引模板(可选但推荐)

sudo filebeat setup --index-management \
  -E output.elasticsearch.hosts=["ES_IP:9200"] \
  -E output.elasticsearch.username=elastic \
  -E output.elasticsearch.password=密码

四、启动 Filebeat

sudo systemctl enable filebeat
sudo systemctl start filebeat

查看状态:

sudo systemctl status filebeat

五、验证是否连上 ES

curl -u elastic:密码 http://ES_IP:9200/_cat/indices?v | grep filebeat

看到 filebeat-* 索引即成功。


六、常见问题

1. 连不上 ES

  • 防火墙:9200
  • ES 是否允许外网:network.host
  • 用户权限(elastic / 自定义 role)

2. 使用 ES 8 默认安全

  • 默认开启 TLS
  • 需要:https + 用户名密码

3. 只采集指定日志

paths:
  - /var/log/nginx/access.log

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

  • ES 版本(7 / 8)
  • 是否启用 TLS
  • 是否使用 Kibana

我可以给你一份 完全对应的配置文件。

0 踩