下面以 Debian 系统 + Elastic Filebeat 为例,说明如何为 Filebeat 配置证书(常用于 Filebeat → Elasticsearch / Logstash 的 TLS 加密通信)。
你需要有以下证书文件(通常由 Elasticsearch/CA 签发):
ca.crt:CA 证书client.crt:Filebeat 客户端证书client.key:Filebeat 客户端私钥示例目录(推荐):
/etc/filebeat/certs/
├── ca.crt
├── client.crt
└── client.key
设置权限(非常重要):
sudo chown -R root:root /etc/filebeat/certs
sudo chmod 600 /etc/filebeat/certs/client.key
sudo chmod 644 /etc/filebeat/certs/ca.crt
sudo chmod 644 /etc/filebeat/certs/client.crt
编辑配置文件:
sudo nano /etc/filebeat/filebeat.yml
output.elasticsearch:
hosts: ["https://es-node1:9200"]
username: "filebeat_writer"
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"
output.logstash:
hosts: ["logs.example.com:5044"]
ssl:
enabled: true
certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
certificate: "/etc/filebeat/certs/client.crt"
key: "/etc/filebeat/certs/client.key"
sudo filebeat test config
sudo filebeat test output
看到 TLS connection ... OK 即说明证书配置正确。
sudo systemctl enable filebeat
sudo systemctl restart filebeat
sudo systemctl status filebeat
错误示例:
x509: certificate is valid for ..., not es-node1
✅ 解决:确保证书 CN 或 SAN 包含 ES 主机名
failed to load SSL cert
✅ 解决:确认 client.key 权限为 600
✅ 必须把 ca.crt 配置到 certificate_authorities
在 ES 节点:
/usr/share/elasticsearch/bin/elasticsearch-certutil cert \
--ca /etc/elasticsearch/certs/ca.p12 \
--name filebeat \
--out filebeat.p12
然后导出:
openssl pkcs12 -in filebeat.p12 -out client.crt -clcerts -nokeys
openssl pkcs12 -in filebeat.p12 -out client.key -nocerts
如果你能告诉我:
我可以给你更精确的配置示例。