温馨提示×

centos filebeat怎么连接es

小樊
44
2026-08-18 20:30:56
栏目: 智能运维

CentOS 上让 Filebeat 连接 Elasticsearch(ES),核心就是:
✅ 安装 Filebeat
✅ 修改 filebeat.yml
✅ 启动并验证

下面给你一个完整、可直接用的流程(适用于 Filebeat → Elasticsearch 直连,不走 Logstash)。


一、环境说明

  • OS:CentOS 7 / 8
  • Filebeat:7.x / 8.x(建议和 ES 同版本)
  • ES:已启动,且网络可达

二、安装 Filebeat

1️⃣ 使用 RPM 安装(推荐)

# 以 8.11.0 为例,换成你的版本
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.11.0-x86_64.rpm

sudo rpm -ivh filebeat-8.11.0-x86_64.rpm

安装完成后:

filebeat version

三、配置 Filebeat 连接 ES

1️⃣ 编辑配置文件

sudo vi /etc/filebeat/filebeat.yml

2️⃣ 核心配置示例(重点)

✅ 输入(读取日志)

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

✅ 输出到 Elasticsearch

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

⚠️ 如果 ES 没开安全认证,可以去掉 username / password

✅ 索引模板(可选但推荐)

setup.template.name: "filebeat"
setup.template.pattern: "filebeat-*"

✅ Kibana(可选)

setup.kibana:
  host: "http://192.168.1.10:5601"

四、如果 ES 是 HTTPS(常见)

output.elasticsearch:
  hosts: ["https://192.168.1.10:9200"]
  username: "elastic"
  password: "your_password"
  ssl.verification_mode: none   # 如果是自签证书

五、初始化并启动 Filebeat

1️⃣ 加载索引模板(第一次必须)

sudo filebeat setup

如果只想加载模板:

sudo filebeat setup --index-management

2️⃣ 启动服务

sudo systemctl enable filebeat
sudo systemctl start filebeat

查看状态:

systemctl status filebeat

六、验证是否成功

1️⃣ 查看 ES 是否有索引

curl -u elastic:your_password http://192.168.1.10:9200/_cat/indices/filebeat*?v

2️⃣ 查看数据

curl -u elastic:your_password http://192.168.1.10:9200/filebeat-*/_search?pretty

七、常见错误排查

❌ 连不上 ES

connection attempt failed

✅ 检查:

  • ES 是否启动
  • 防火墙 / 安全组
  • hosts 地址是否正确

❌ 没有数据

✅ 检查:

  • filebeat.inputs.enabled: true
  • 日志文件是否有新内容
  • 文件权限

八、Filebeat 直连 vs Logstash

方案 推荐场景
Filebeat → ES 简单、轻量
Filebeat → Logstash → ES 需要过滤、解析

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

  • ✅ ES 版本
  • ✅ 是否开启 HTTPS / 安全认证
  • ✅ 日志路径

我可以帮你直接生成一份可用的 filebeat.yml

0