温馨提示×

centos filebeat怎么配es

小樊
45
2026-10-08 20:21:53
栏目: 智能运维

下面给你一个 CentOS 上 Filebeat 对接 Elasticsearch(ES) 的常用配置示例,适用于 Filebeat 直接写 ES(不走 Logstash)。


一、安装 Filebeat(CentOS)

1. 使用 RPM 安装(推荐)

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
enabled=1
EOF

sudo yum install filebeat -y

如果是 ES 7.x,把 8.x 改成 7.x


二、配置 Filebeat

配置文件路径:

/etc/filebeat/filebeat.yml

基础示例(Filebeat → ES)

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

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

# 可选:索引命名
setup.template.name: "filebeat"
setup.template.pattern: "filebeat-*"

三、ES 有安全认证(HTTPS)

如果 ES 开了 TLS:

output.elasticsearch:
  hosts: ["https://192.168.1.100:9200"]
  username: "elastic"
  password: "your_password"
  ssl.verification_mode: "none"   # 测试可用,生产建议配置证书

四、初始化 Filebeat 索引模板(重要)

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

或者一次性:

filebeat setup

五、启动 Filebeat

systemctl enable filebeat
systemctl start filebeat

查看状态:

systemctl status filebeat

六、验证数据是否写入 ES

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

或在 Kibana:

Stack Management → Index Management → filebeat-*

七、常见坑

  1. 时间不同步

    yum install ntpdate -y
    ntpdate pool.ntp.org
    
  2. ES 版本不一致

    • Filebeat 和 ES 大版本必须一致(如 8.x ↔ 8.x)
  3. 权限问题

    • Filebeat 需能读日志文件
    chmod 644 /var/log/messages
    

如果你需要:

  • ✅ Filebeat → Logstash → ES
  • ✅ 多行日志(Java / Docker)
  • ✅ Kibana 可视化配置

可以告诉我你的 ES 版本 + 日志类型,我给你定制配置。

0 踩