温馨提示×

Filebeat在CentOS怎么配置证书

小樊
45
2026-08-03 22:01:42
栏目: 智能运维

下面以 Filebeat 在 CentOS 上配置 TLS/SSL 证书 为例,分别说明 Filebeat → Elasticsearch / Logstash 两种常见场景,并给出完整配置示例和注意事项。


一、准备证书(通用)

通常你需要以下文件:

  • CA 证书ca.crt(用于验证服务端)
  • 客户端证书(双向 TLS 时需要):client.crt
  • 客户端私钥client.key

假设证书放在:

/etc/filebeat/certs/
├── ca.crt
├── client.crt
└── client.key

⚠️ 权限建议:

chmod 600 /etc/filebeat/certs/*
chown root:root /etc/filebeat/certs/*

二、Filebeat → Elasticsearch(TLS)

1️⃣ 修改 Filebeat 配置

编辑:

vim /etc/filebeat/filebeat.yml

2️⃣ 配置 Elasticsearch 输出 + 证书

output.elasticsearch:
  hosts: ["https://es-node1:9200"]
  username: "filebeat"
  password: "your_password"

  ssl:
    enabled: true
    certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
    certificate: "/etc/filebeat/certs/client.crt"
    key: "/etc/filebeat/certs/client.key"

3️⃣ 如果只验证服务端(单向 TLS)

ssl:
  enabled: true
  certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
  verification_mode: "full"

4️⃣ 重启 Filebeat

systemctl restart filebeat
systemctl status filebeat

三、Filebeat → Logstash(TLS)

1️⃣ Logstash 端(示例)

input {
  beats {
    port => 5044
    ssl => true
    ssl_certificate => "/etc/logstash/certs/server.crt"
    ssl_key => "/etc/logstash/certs/server.key"
    ssl_certificate_authorities => ["/etc/logstash/certs/ca.crt"]
  }
}

2️⃣ Filebeat 配置

output.logstash:
  hosts: ["logstash-host:5044"]
  ssl:
    enabled: true
    certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
    certificate: "/etc/filebeat/certs/client.crt"
    key: "/etc/filebeat/certs/client.key"

四、关闭证书验证(⚠️ 不推荐生产)

仅用于测试:

ssl:
  enabled: true
  verification_mode: "none"

五、常见问题排查

1️⃣ 证书路径错误

failed to load certificate

✅ 检查路径、权限、用户


2️⃣ 证书 CN / SAN 不匹配

x509: certificate is valid for xxx, not yyy

✅ 证书必须包含 ES/Logstash 的 hostname 或 IP


3️⃣ 查看 Filebeat 日志

journalctl -u filebeat -f

tail -f /var/log/filebeat/filebeat

六、总结

场景 必备证书
Filebeat → ES ca.crt
双向 TLS ca.crt + client.crt + client.key
Filebeat → Logstash ca.crt
双向 TLS ca.crt + client.crt + client.key

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

  • Filebeat 版本
  • 目标是 ES 还是 Logstash
  • 是否是 Elastic Stack 官方证书(elasticsearch-certutil)

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

0