在CentOS上配置Filebeat以使用SSL加密涉及几个步骤。以下是一个基本的指南,帮助你设置Filebeat以通过SSL/TLS加密传输数据。
编辑Filebeat的配置文件/etc/filebeat/filebeat.yml
,添加或修改以下内容以启用SSL/TLS加密:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["https://your_elasticsearch_host:9200"]
ssl.verification_mode: certificate
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
ssl.certificate: "/etc/filebeat/certs/filebeat.crt"
ssl.key: "/etc/filebeat/certs/filebeat.key"
如果你还没有SSL证书,可以使用openssl
生成自签名证书。
mkdir -p /etc/filebeat/certs
cd /etc/filebeat/certs
openssl req -x509 -newkey rsa:4096 -keyout ca.key -out ca.crt -days 3650 -nodes
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 3650
确保Elasticsearch配置文件/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.p12
然后,使用elasticsearch-certutil
工具生成客户端证书:
cd /etc/elasticsearch
bin/elasticsearch-certutil cert -out filebeat.p12 -pass ""
将生成的filebeat.p12
文件复制到Filebeat的证书目录:
cp filebeat.p12 /etc/filebeat/certs/
重启Filebeat和Elasticsearch服务以应用更改:
sudo systemctl restart filebeat
sudo systemctl restart elasticsearch
确保Filebeat能够成功连接到Elasticsearch并传输数据。你可以查看Filebeat的日志文件/var/log/filebeat/filebeat
以获取更多信息。
tail -f /var/log/filebeat/filebeat
通过以上步骤,你应该能够在CentOS上成功配置Filebeat以使用SSL/TLS加密传输数据。