一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

filebeat在ubuntu上如何进行数据加密

时间:2026-07-31 09:08:48 编辑:袖梨 来源:一聚教程网

在 Ubuntu 上配置 Filebeat 的数据加密

一 前置准备

  1. 安装 Filebeat:sudo apt-get update && sudo apt-get install filebeat
  2. 规划证书目录:建议统一放在 /etc/filebeat/certs,并设置最小权限(私钥 600,证书 644),避免泄露凭据。

二 生成证书与密钥

  1. 创建目录:mkdir -p /etc/filebeat/certs
  2. 生成 CA(自签,长期有效):openssl req -x509 -newkey rsa:4096 -keyout /etc/filebeat/certs/ca.key -out /etc/filebeat/certs/ca.crt -days 3650 -nodes -subj “/C=CN/ST=YourState/L=YourCity/O=YourOrg/CN=YourCA”
  3. 生成 Filebeat 客户端证书与密钥(用于双向 TLS/mTLS):openssl req -newkey rsa:2048 -keyout /etc/filebeat/certs/filebeat.key -out /etc/filebeat/certs/filebeat.csr -nodes -subj “/C=CN/ST=YourState/L=YourCity/O=YourOrg/CN=filebeat”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
  4. 如 Elasticsearch 也启用客户端校验,需为其生成服务器证书(CN 建议与 ES 主机名一致),并在 ES 端配置信任该 CA。
  5. 权限设置:chmod 600 /etc/filebeat/certs/.key; chmod 644 /etc/filebeat/certs/.crt。

三 配置 Filebeat 启用 TLS

  1. 编辑 /etc/filebeat/filebeat.yml,示例(直连 Elasticsearch,启用双向 TLS):filebeat.inputs:

    1. type: logenabled: truepaths:
      1. /var/log/*.log

    output.elasticsearch:hosts: [“https://your_elasticsearch_host:9200”]ssl.enabled: truessl.verification_mode: certificatessl.certificate_authorities: [“/etc/filebeat/certs/ca.crt”]ssl.certificate: “/etc/filebeat/certs/filebeat.crt”ssl.key: “/etc/filebeat/certs/filebeat.key”

    如启用 X-Pack 安全,补充认证username: “filebeat_user”password: “secure_password”
  2. 说明:

    1. 单向 TLS(仅验证 ES 证书)时,可省略 ssl.certificate/ssl.key。
    2. 若经由 Logstash 转发,请在 Logstash 的 Beats 输入启用 SSL,并让 Filebeat 的 output.logstash 使用 ssl.certificate_authorities 指向同一 CA。

四 配置 Elasticsearch 启用 TLS

  1. 基本 HTTP 层加密(Filebeat 用 https 连 9200):xpack.security.enabled: truexpack.security.http.ssl.enabled: truexpack.security.http.ssl.certificate: “/etc/elasticsearch/certs/elasticsearch.crt”xpack.security.http.ssl.key: “/etc/elasticsearch/certs/elasticsearch.key”xpack.security.http.ssl.certificate_authorities: [“/etc/elasticsearch/certs/ca.crt”]
  2. 节点间传输加密(Transport 层,集群内部通信):xpack.security.transport.ssl.enabled: truexpack.security.transport.ssl.verification_mode: certificatexpack.security.transport.ssl.keystore.path: “transport.p12”xpack.security.transport.ssl.truststore.path: “truststore.p12”
  3. 生成 p12(示例):elasticsearch-certutil cert --pem --ca-cert /etc/filebeat/certs/ca.crt --ca-key /etc/filebeat/certs/ca.key --out /tmp/elastic-bundle.zip,解压后按提示生成 transport.p12/truststore.p12 并放置到 ES 配置目录。

五 启动与验证

  1. 重启服务:sudo systemctl restart filebeat;如修改了 ES,也重启 Elasticsearch。
  2. 查看状态与日志:
    1. systemctl status filebeat
    2. journalctl -u filebeat -f 或 tail -f /var/log/filebeat/filebeat
  3. 连通性验证(使用与 Filebeat 相同的证书与 CA):curl -k --cacert /etc/filebeat/certs/ca.crt --cert /etc/filebeat/certs/filebeat.crt --key /etc/filebeat/certs/filebeat.key https://your_elasticsearch_host:9200/_cat/nodes?v
  4. 常见问题排查:
    1. 证书路径或权限错误(私钥应为 600,证书 644)。
    2. 主机名不匹配或 CA 不一致(证书 CN/SAN 需覆盖实际访问域名/IP)。
    3. 未启用 ES 的 http.ssl 或未放行 9200 端口。
    4. 若使用自签名 CA,确保 Filebeat 与 ES 都信任同一 ca.crt。

热门栏目