温馨提示×

centos filebeat如何连接es

小樊
46
2026-09-06 02:06:34
栏目: 智能运维

在 CentOS 上使用 Filebeat 连接 Elasticsearch(ES),一般分为以下几个步骤:


一、环境准备

  • CentOS 7/8(示例以 CentOS 7 为主)
  • 已安装并运行 Elasticsearch
  • Filebeat 版本建议与 ES 版本一致

二、安装 Filebeat(CentOS)

1. 使用官方 RPM 源安装(推荐)

sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

sudo cat > /etc/yum.repos.d/filebeat.repo <<EOF
[filebeat]
name=Elasticsearch repository for Filebeat
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

sudo yum install filebeat -y

若使用 ES 7.x,把 8.x 改为 7.x


三、配置 Filebeat 连接 ES

编辑配置文件:

vi /etc/filebeat/filebeat.yml

1. 配置输入(示例:收集系统日志)

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

2. 配置输出到 Elasticsearch

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

如果是 无认证 ES

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

如果是 HTTPS + 证书

output.elasticsearch:
  hosts: ["https://192.168.1.100:9200"]
  username: "elastic"
  password: "your_password"
  ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]

四、加载 ES 模板(可选但推荐)

filebeat setup --index-management -E output.elasticsearch.hosts=["192.168.1.100:9200"]

五、启动 Filebeat

systemctl enable filebeat
systemctl start filebeat

查看状态:

systemctl status filebeat

六、验证是否连接成功

1. 查看 Filebeat 日志

journalctl -u filebeat -f

2. 查看 ES 中是否有索引

curl -u elastic:your_password http://192.168.1.100:9200/_cat/indices?v

应能看到类似:

filebeat-8.x.x-2026.xx.xx

七、常见问题排查

1. 连接被拒绝

  • ES 是否监听 9200
  • 防火墙是否放行
firewall-cmd --add-port=9200/tcp --permanent
firewall-cmd --reload

2. 认证失败

  • 用户名/密码错误
  • ES 安全模式未开启但配置了密码

3. 时间不同步

ntpdate pool.ntp.org

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

  • ES 版本(7.x / 8.x)
  • 是否启用安全认证(xpack)
  • 是否使用 Kibana

我可以给你一份可直接用的 filebeat.yml 示例

0