温馨提示×

centos filebeat怎样加证书

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

在 CentOS 上给 Filebeat 配置证书,通常出现在以下两种场景:

  1. Filebeat 作为客户端:连接启用了 TLS 的 Elasticsearch / Logstash
  2. Filebeat 作为服务端(较少见):接收 Beats 输入(Logstash 或 Elastic Agent)

下面以 Filebeat → Elasticsearch / Logstash(TLS) 为例说明。


一、准备证书文件

常见证书文件:

  • ca.crt:CA 证书(必须)
  • client.crt:Filebeat 客户端证书(可选,双向认证时需要)
  • client.key:客户端私钥(可选)

将证书放到例如:

/etc/filebeat/certs/

设置权限(非常重要):

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

二、Filebeat 连接 Elasticsearch(带证书)

编辑配置文件:

vi /etc/filebeat/filebeat.yml

1. 单向 TLS(只验证服务端)

output.elasticsearch:
  hosts: ["https://es-node1:9200"]
  username: "filebeat_writer"
  password: "your_password"
  ssl:
    enabled: true
    certificate_authorities: ["/etc/filebeat/certs/ca.crt"]

2. 双向 TLS(客户端证书)

output.elasticsearch:
  hosts: ["https://es-node1:9200"]
  ssl:
    enabled: true
    certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
    certificate: "/etc/filebeat/certs/client.crt"
    key: "/etc/filebeat/certs/client.key"

三、Filebeat 连接 Logstash(带证书)

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:
  verification_mode: none

⚠️ 生产环境 不要使用


五、启动并验证

systemctl restart filebeat
systemctl status filebeat

查看日志:

journalctl -u filebeat -f

测试配置:

filebeat test output

六、常见问题

1. 权限错误

failed to load SSL certificate

✅ 检查证书文件权限和属主

2. 证书路径错误

✅ 使用 绝对路径

3. SELinux 限制(CentOS)

setsebool -P filebeat_connect_any 1

或临时关闭测试:

setenforce 0

如果你能告诉我:

  • Filebeat 是连 ES 还是 Logstash
  • 是否 自签证书
  • CentOS 版本(7 / 8 / Stream)

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

0 踩