在CentOS系统上配置Filebeat与Elasticsearch之间的数据传输加密,SSL/TLS协议是保障安全通信的标准方案。尽管自签名证书在开发测试环境中可以满足基本需求,但生产环境下强烈建议采用权威CA签发的证书。接下来,我们将详细梳理从证书生成到验证的完整配置流程,确保每一步都切实可行。
- 生成证书——采用自签名方案时,可直接利用OpenSSL工具,首先生成CA根证书,再签发Filebeat客户端证书:
证书生成完成后,将# 生成CA证书 openssl req -x509 -newkey rsa:4096 -keyout ca.key -out ca.crt -days 3650 -nodes # 生成Filebeat证书 openssl req -newkey rsa:4096 -keyout filebeat.key -out filebeat.csr -nodes openssl x509 -req -in filebeat.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out filebeat.crt -days 3650ca.crt、filebeat.crt和filebeat.key部署到Filebeat节点,建议统一存放于/etc/filebeat/certs/目录下。 - 配置Filebeat——编辑
/etc/filebeat/filebeat.yml,在output.elasticsearch段落中开启SSL加密并配置证书路径,注意将host地址改为https协议:
这里有两个关键点:output.elasticsearch: hosts: ["https://elasticsearch_host:9200"] ssl.enabled: true ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"] ssl.certificate: "/etc/filebeat/certs/filebeat.crt" ssl.key: "/etc/filebeat/certs/filebeat.key"certificate_authorities指向CA根证书,用于验证Elasticsearch服务端身份;certificate和key则是Filebeat自身用于证明身份的凭证。 - 配置Elasticsearch——Elasticsearch同样需要启用SSL,并配置信任Filebeat的证书。编辑
/etc/elasticsearch/elasticsearch.yml,添加或调整以下配置:
注意这里的xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12elastic-certificates.p12是Elasticsearch默认生成的PKCS12格式证书文件,如果使用自签名CA,也可以替换为自己的证书库,但需确保路径配置一致。 - 重启服务——配置修改完成后,务必重启两个服务以使其生效:
如果Elasticsearch集群包含多个节点,需要逐个重启,采用滚动重启方式以避免影响业务。sudo systemctl restart filebeat sudo systemctl restart elasticsearch - 验证配置——检查Filebeat日志(
/var/log/filebeat/filebeat)中是否存在SSL相关的报错信息。此外,可使用curl命令直接测试加密连接是否正常:
如果返回Elasticsearch的JSON格式响应,则表明TLS握手成功,数据传输加密已生效。curl --cacert /etc/filebeat/certs/ca.crt https://elasticsearch_host:9200
最后需要提醒的是:生产环境中使用自签名证书存在潜在的安全风险,例如中间人攻击风险以及证书过期维护的复杂性。直接采用CA签发的证书或企业内部PKI体系才是更稳妥的做法。如果是测试环境或内部网络隔离度较高,自签名证书也勉强可用,但务必确保证书生命周期管理纳入运维流程中。
