首页主机资讯filebeat在ubuntu上如何进行数据加密

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

时间2025-11-19 19:15:04发布访客分类主机资讯浏览1253
导读:在 Ubuntu 上配置 Filebeat 的数据加密 一 前置准备 安装 Filebeat:sudo apt-get update && sudo apt-get install filebeat 规划证书目录:建议统一...

在 Ubuntu 上配置 Filebeat 的数据加密

一 前置准备

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

二 生成证书与密钥

  • 创建目录:mkdir -p /etc/filebeat/certs
  • 生成 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”
  • 生成 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
  • 如 Elasticsearch 也启用客户端校验,需为其生成服务器证书(CN 建议与 ES 主机名一致),并在 ES 端配置信任该 CA。
  • 权限设置:chmod 600 /etc/filebeat/certs/.key; chmod 644 /etc/filebeat/certs/.crt。

三 配置 Filebeat 启用 TLS

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

    • type: log enabled: true paths:
      • /var/log/*.log

    output.elasticsearch: hosts: [“https://your_elasticsearch_host: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”

    如启用 X-Pack 安全,补充认证

    username: “filebeat_user”

    password: “secure_password”

  • 说明:

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

四 配置 Elasticsearch 启用 TLS

  • 基本 HTTP 层加密(Filebeat 用 https 连 9200): xpack.security.enabled: true xpack.security.http.ssl.enabled: true xpack.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”]
  • 节点间传输加密(Transport 层,集群内部通信): xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: “transport.p12” xpack.security.transport.ssl.truststore.path: “truststore.p12”
  • 生成 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 配置目录。

五 启动与验证

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

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: filebeat在ubuntu上如何进行数据加密
本文地址: https://pptw.com/jishu/751462.html
Debian Python机器学习库怎么选 filebeat在ubuntu上如何进行数据备份

游客 回复需填写必要信息