Filebeat加密传输实现指南
一、核心思路与前置条件
二、生成证书与密钥
# 1) 创建CA
mkdir -p /etc/filebeat/certs
openssl genrsa -out /etc/filebeat/certs/ca.key 2048
openssl req -x509 -new -nodes -key /etc/filebeat/certs/ca.key -sha256 -days 3650 \
-out /etc/filebeat/certs/ca.crt -subj "/C=CN/ST=YourState/L=YourCity/O=YourOrg/CN=YourCA"
# 2) 生成Filebeat客户端证书(用于双向TLS)
openssl genrsa -out /etc/filebeat/certs/filebeat.key 2048
openssl req -new -key /etc/filebeat/certs/filebeat.key -out /etc/filebeat/certs/filebeat.csr \
-subj "/C=CN/ST=YourState/L=YourCity/O=YourOrg/CN=filebeat-client"
# 注意:将ES地址写入SAN,例如DNS:es.example.com,IP:10.0.0.10
cat > /etc/filebeat/certs/filebeat.cnf <<EOF
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
[v3_req]
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = es.example.com
IP.1 = 10.0.0.10
EOF
openssl x509 -req -in /etc/filebeat/certs/filebeat.csr -CA /etc/filebeat/certs/ca.crt -CAkey /etc/filebeat/certs/ca.key \
-CAcreateserial -out /etc/filebeat/certs/filebeat.crt -days 365 -sha256 -extfile /etc/filebeat/certs/filebeat.cnf
# 3) 生成Elasticsearch服务器证书(示例)
openssl genrsa -out /etc/filebeat/certs/es.key 2048
openssl req -new -key /etc/filebeat/certs/es.key -out /etc/filebeat/certs/es.csr \
-subj "/C=CN/ST=YourState/L=YourCity/O=YourOrg/CN=es.example.com"
cat > /etc/filebeat/certs/es.cnf <<EOF
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
[v3_req]
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = es.example.com
IP.1 = 10.0.0.10
EOF
openssl x509 -req -in /etc/filebeat/certs/es.csr -CA /etc/filebeat/certs/ca.crt -CAkey /etc/filebeat/certs/ca.key \
-CAcreateserial -out /etc/filebeat/certs/es.crt -days 365 -sha256 -extfile /etc/filebeat/certs/es.cnf
三、Filebeat配置示例
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["https://es.example.com:9200"]
ssl.enabled: true
ssl.verification_mode: certificate
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
output.elasticsearch:
hosts: ["https://es.example.com:9200"]
ssl.enabled: true
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"
output.logstash:
hosts: ["logstash.example.com:5044"]
ssl.enabled: true
ssl.verification_mode: certificate
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
# 如Logstash开启客户端校验
# ssl.certificate: "/etc/filebeat/certs/filebeat.crt"
# ssl.key: "/etc/filebeat/certs/filebeat.key"
四、目标端配置要点
xpack.security.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: /path/to/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: /path/to/elastic-certificates.p12
# 节点间传输加密(如启用)
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /path/to/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /path/to/elastic-certificates.p12
五、验证与运维建议
filebeat test config -c /etc/filebeat/filebeat.ymlfilebeat test output -c /etc/filebeat/filebeat.ymlsystemctl restart filebeat,查看日志:journalctl -u filebeat -fcurl -vk https://es.example.com:9200