最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Filebeat在CentOS上如何进行数据加密传输
时间:2026-07-30 18:14:48 编辑:袖梨 来源:一聚教程网
在 CentOS 上配置 Filebeat 的加密传输
一 准备与安装
- 在 CentOS 上安装 Filebeat(以 7.x 为例):执行命令:
sudo yum install filebeat -y。安装完成后,配置文件默认位于 /etc/filebeat/filebeat.yml。如使用 Elasticsearch 8.x,建议通过官方仓库安装,保持版本一致以获得完整的 TLS/X-Pack 支持。
二 生成证书与密钥
- 方式 A(推荐,便于与 ES 集成):使用 elasticsearch-certutil 生成 CA 与节点/客户端证书(PEM 或 PKCS#12)。示例:
- 生成 CA:
sudo /usr/share/elasticsearch/bin/elasticsearch-certutil ca --pem --out /etc/elasticsearch/certs/ca.zip - 解压:
unzip -o /etc/elasticsearch/certs/ca.zip -d /etc/elasticsearch/certs/ - 为 Filebeat 生成客户端证书(PEM):
sudo /usr/share/elasticsearch/bin/elasticsearch-certutil cert --pem --ca-cert /etc/elasticsearch/certs/ca/ca.crt --ca-key /etc/elasticsearch/certs/ca/ca.key --out /etc/filebeat/certs/filebeat.zip - 解压到 /etc/filebeat/certs/,得到 filebeat.crt 与 filebeat.key。
- 生成 CA:
- 方式 B(通用 OpenSSL):自建 CA 并签发客户端证书,注意为 ES 主机名/IP 配置 SAN(subjectAltName),避免证书校验失败。示例:
- 生成 CA:
openssl req -x509 -newkey rsa:2048 -keyout ca.key -out ca.crt -days 3650 -nodes -subj "/CN=ca" - 生成 Filebeat 私钥与 CSR:
openssl genrsa -out filebeat.key 2048;openssl req -new -key filebeat.key -out filebeat.csr -subj "/CN=filebeat" - 签发证书(含 SAN):
openssl x509 -req -in filebeat.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out filebeat.crt -days 365 -sha256 -extfile <(printf "subjectAltName=DNS:your_es_host,DNS:localhost,IP:192.168.1.10")
- 生成 CA:
- 将证书权限收紧:
chmod 600 /etc/filebeat/certs/*.key; chown root:root /etc/filebeat/certs/*。
三 配置 Filebeat 使用 TLS 输出到 Elasticsearch
- 编辑 /etc/filebeat/filebeat.yml,在 output.elasticsearch 启用 TLS 并指向证书;如启用 X-Pack 安全,同时配置认证:
- 最小可用示例(单向 TLS,仅验证 ES 证书):
filebeat.inputs:- type: logenabled: truepaths:- /var/log/*.logoutput.elasticsearch:hosts: ["https://es01.example.com:9200"]ssl.enabled: truessl.verification_mode: certificatessl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]# 如 ES 要求客户端证书,再添加下面三行# ssl.certificate: "/etc/filebeat/certs/filebeat.crt"# ssl.key: "/etc/filebeat/certs/filebeat.key"username: "filebeat_internal"password: "YourStrongP@ssw0rd" - 双向 TLS(mTLS,ES 也验证客户端证书):在 ES 端开启客户端校验,并在 Filebeat 的 output 中同时配置 ssl.certificate 与 ssl.key。
- 说明:
ssl.verification_mode常用值为 certificate(校验证书)或 full(校验证书与主机名);生产建议 full。
- 最小可用示例(单向 TLS,仅验证 ES 证书):
四 配置 Elasticsearch 启用 TLS
- 编辑 /etc/elasticsearch/elasticsearch.yml,启用 X-Pack 安全 与 HTTP/Transport TLS(示例为 PEM 证书,若使用 PKCS#12 则以 keystore/truststore 路径为准):
xpack.security.enabled: truexpack.security.transport.ssl.enabled: truexpack.security.transport.ssl.verification_mode: certificatexpack.security.transport.ssl.certificate: /etc/elasticsearch/certs/elasticsearch.crtxpack.security.transport.ssl.key: /etc/elasticsearch/certs/elasticsearch.keyxpack.security.transport.ssl.certificate_authorities: ["/etc/elasticsearch/certs/ca.crt"]xpack.security.http.ssl.enabled: truexpack.security.http.ssl.certificate: /etc/elasticsearch/certs/elasticsearch.crtxpack.security.http.ssl.key: /etc/elasticsearch/certs/elasticsearch.keyxpack.security.http.ssl.certificate_authorities: ["/etc/elasticsearch/certs/ca.crt"] - 如使用 PKCS#12,可用
elasticsearch-certutil cert --p12生成 elastic-certificates.p12,并在配置中使用keystore.path与truststore.path指向该文件。
五 启动与验证
- 重启服务并查看状态:
sudo systemctl restart elasticsearch && sudo systemctl enable elasticsearchsudo systemctl restart filebeat && sudo systemctl enable filebeat- 查看 Filebeat 日志:
sudo journalctl -u filebeat -f
- 连接性验证(带证书与凭据):
curl -u filebeat_internal:YourStrongP@ssw0rd --cacert /etc/filebeat/certs/ca.crt --cert /etc/filebeat/certs/filebeat.crt --key /etc/filebeat/certs/filebeat.key https://es01.example.com:9200- 若仅做单向校验,可省略 –cert/–key;若 ES 启用 mTLS,则必须提供客户端证书。
- 常见问题排查:证书路径与权限错误、证书 SAN 不匹配、ES 未启用 xpack.security.http.ssl.enabled、Filebeat 中 hosts 未使用 https、或 verification_mode 与证书配置不一致。
相关文章
- 恋与深空简单易懂养卡推荐 07-30
- 原神月之四版本更新维护预告 07-30
- 超自然行动组1周年庆是什么时候开启 07-30
- 崩坏星穹铁道余晖残卷戮力双雄打法攻略 07-30
- 劫后公司手机版成就攻略 劫后公司手机版全成就解锁技巧与速通方法 07-30
- 三国天下归心怎么样 三国天下归心深度测评与真实玩家体验分享 07-30