温馨提示×

centosfilebeat怎么配置证书

小樊
39
2026-10-14 18:02:20
栏目: 智能运维

在 CentOS 上配置 Filebeat 使用证书,通常有两种常见场景:

  1. Filebeat → Elasticsearch(HTTPS + 证书)
  2. Filebeat → Logstash(SSL/TLS 加密)

下面分别说明,以 CentOS 7/8 为例,Filebeat 通过 RPM 安装。


一、准备证书文件

通常你需要以下文件(由 Elasticsearch / CA 提供):

  • ca.crt:CA 证书
  • client.crt:Filebeat 客户端证书(可选)
  • client.key:客户端私钥(可选)

示例目录:

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

设置权限:

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

二、Filebeat → Elasticsearch(HTTPS 证书配置)

1️⃣ 修改 filebeat.yml

output.elasticsearch:
  hosts: ["https://es-node1:9200"]
  username: "filebeat_user"
  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"

如果 ES 使用自签名证书,只配 certificate_authorities 即可


三、Filebeat → Logstash(SSL 配置)

1️⃣ Logstash 端(input)

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"

四、SELinux 注意事项(CentOS 常见坑)

如果开启 SELinux,证书可能无法读取:

setsebool -P filebeat_connect_any 1

或临时测试:

setenforce 0

五、测试与启动

filebeat test config
filebeat test output

启动:

systemctl restart filebeat
systemctl enable filebeat

查看日志:

journalctl -u filebeat -f

六、常见问题

✅ x509: certificate signed by unknown authority
→ ca.crt 路径错误或未配置

✅ tls: failed to find certificate
→ client.crt / client.key 不匹配

✅ permission denied
→ 证书权限问题(必须是 600)


如果你能告诉我:

  • Filebeat 是发给 ES 还是 Logstash
  • 是否需要 客户端双向认证
  • CentOS 版本

我可以给你一份可直接用的完整配置。

0 踩