温馨提示×

centos filebeat怎么对接es

小樊
36
2026-09-18 02:35:19
栏目: 智能运维

在 CentOS 上把 Filebeat 对接 Elasticsearch(ES),通常有两种方式:

  1. Filebeat 直接写 ES(推荐,简单)
  2. Filebeat → Logstash → ES(需要额外处理日志时)

下面以 CentOS 7/8 + Filebeat 直接对接 ES 为例说明。


一、环境准备

假设:

  • CentOS 7/8
  • Elasticsearch 地址:http://192.168.1.100:9200
  • Filebeat 版本:与 ES 大版本一致(如 7.x / 8.x)

二、安装 Filebeat(CentOS)

1. 使用 RPM 安装(推荐)

# 以 8.x 为例
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

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

1. 修改配置文件

vi /etc/filebeat/filebeat.yml

2. 基础配置示例(直接写 ES)

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

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

setup.ilm.enabled: false
setup.template.enabled: true

⚠️ 如果是 ES 8.x + 安全开启,需要配置 username/password 如果是 ES 没开安全(测试环境),可以去掉 username/password


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

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 http://192.168.1.100:9200/_cat/indices?v

应该能看到类似:

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

3. Kibana 查看(可选)

  • Stack Management → Index Patterns
  • 创建 filebeat-*
  • Discover 中查看日志

七、常见问题

1. ES 拒绝连接

  • 检查 ES 是否监听 0.0.0.0
  • 防火墙:firewall-cmd --add-port=9200/tcp

2. 版本不一致

Filebeat 和 ES 大版本必须一致

3. 时间字段不对

  • ES 中默认 @timestamp 是采集时间
  • 可用 processors 解析日志时间

八、进阶(可选)

  • Filebeat → Logstash → ES
  • 使用 filebeat.modules(系统/nginx/redis 等)
  • 使用 ILM(索引生命周期)

如果你告诉我:

  • ✅ ES 版本
  • ✅ 是否开启安全(账号密码)
  • ✅ 采集什么日志(nginx / 业务日志 / 容器)

我可以直接给你 一份可用的 filebeat.yml 配置。

0 踩