温馨提示×

centos filebeat怎么连es

小樊
42
2026-09-30 02:41:12
栏目: 智能运维

在 CentOS 上让 Filebeat 连接 Elasticsearch(ES),通常有以下几种方式。下面以 Filebeat 直接连 ES(最常见、最简单)为例说明。


一、前提条件

  • CentOS 7 / 8 / Stream 均可
  • 已安装 Elasticsearch( reachable 网络)
  • ES 端口通常是 9200
  • 如果是 ES 安全模式(TLS / 账号密码),需要对应配置

二、安装 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

三、配置 Filebeat 连接 ES

编辑配置文件:

sudo vi /etc/filebeat/filebeat.yml

示例 1:ES 无安全认证(内网常见)

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

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

示例 2:ES 开启账号密码

output.elasticsearch:
  hosts: ["https://192.168.1.100:9200"]
  username: "elastic"
  password: "your_password"
  ssl.verification_mode: none

示例 3:ES 使用 TLS(推荐)

output.elasticsearch:
  hosts: ["https://es.example.com:9200"]
  username: "filebeat_writer"
  password: "xxx"
  ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]

四、启动 Filebeat

sudo systemctl enable filebeat
sudo systemctl start filebeat

查看状态:

systemctl status filebeat

五、验证是否连上 ES

1. 查看 Filebeat 日志

journalctl -u filebeat -f

2. 在 ES 中查看索引

curl http://192.168.1.100:9200/_cat/indices?v

你应该能看到类似:

filebeat-8.x.x-2026.03.11

六、常见问题

1. 连不上 ES

  • 防火墙:9200 是否开放
  • ES 是否只允许 localhost
  • ES 配置:
network.host: 0.0.0.0
discovery.type: single-node

2. 时间字段不对

  • 确认 CentOS 时间同步:
timedatectl

3. 想先输出到 Logstash

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

七、典型架构(可选)

Filebeat → Elasticsearch → Kibana

或

Filebeat → Logstash → Elasticsearch

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

  • ES 版本(7.x / 8.x)
  • 是否开启安全(TLS / 密码)
  • 是否用 Logstash

我可以给你 完全贴合你环境的配置。

0 踩