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

最新下载

热门教程

Debian Filebeat如何进行数据加密

时间:2026-08-04 07:11:49 编辑:袖梨 来源:一聚教程网

Debian上Filebeat数据加密实操指南

一 前置准备

  1. 安装Filebeat(Debian):建议使用官方或Elastic APT仓库,导入GPG并添加源后安装,主配置文件位于**/etc/filebeat/filebeat.yml**。完成后确认服务可用。
  2. 证书准备:生成或获取CA证书、Filebeat的客户端证书与私钥,并按统一目录存放,例如**/etc/filebeat/pki/tls/{certs,private}**。生产环境建议使用受信任CA签发的证书。

二 生成证书示例

  1. 创建目录
    1. mkdir -p /etc/filebeat/pki/tls/{certs,private}
  2. 生成CA证书(示例有效期3650天)
    1. openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/filebeat/pki/tls/private/ca.key -out /etc/filebeat/pki/tls/certs/ca.crt -subj “/CN=Elastic CA”
  3. 生成Filebeat客户端证书与私钥(示例有效期365天)
    1. openssl req -newkey rsa:2048 -nodes -keyout /etc/filebeat/pki/tls/private/filebeat.key -out /etc/filebeat/pki/tls/certs/filebeat.csr -subj “/CN=filebeat.example.com”
    2. openssl x509 -req -in /etc/filebeat/pki/tls/certs/filebeat.csr -CA /etc/filebeat/pki/tls/certs/ca.crt -CAkey /etc/filebeat/pki/tls/private/ca.key -CAcreateserial -out /etc/filebeat/pki/tls/certs/filebeat.crt -days 365证书路径与文件名可按实际环境调整,但需与Filebeat配置保持一致。

三 配置Filebeat启用TLS加密

  1. 输出到Elasticsearch(HTTPS)
    1. 在**/etc/filebeat/filebeat.yml**中启用TLS并指定证书路径与服务器地址:
      1. output.elasticsearch:
        1. hosts: [“https://elasticsearch.example.com:9200”]
        2. ssl.enabled: true
        3. ssl.verification_mode: certificate
        4. ssl.certificate_authorities: [“/etc/filebeat/pki/tls/certs/ca.crt”]
        5. ssl.certificate: “/etc/filebeat/pki/tls/certs/filebeat.crt”
        6. ssl.key: “/etc/filebeat/pki/tls/private/filebeat.key”
  2. 输出到Logstash(TLS)
    1. 在对应的Logstash输出段添加与上述一致的**ssl.**参数,确保证书路径与CA一致。
  3. 说明
    1. 若Elasticsearch启用X-Pack安全,可同时配置用户名/密码或API Key进行身份认证,与TLS叠加使用更安全。

四 服务端Elasticsearch必要配置

  1. 启用安全功能与HTTP层TLS(示例)
    1. xpack.security.enabled: true
    2. xpack.security.http.ssl.enabled: true
    3. xpack.security.http.ssl.certificate: “/etc/elasticsearch/certs/http.pem”
    4. xpack.security.http.ssl.key: “/etc/elasticsearch/certs/http-key.pem”
    5. xpack.security.http.ssl.certificate_authorities: [“/etc/elasticsearch/certs/ca.pem”]
  2. 集群内部传输加密(如部署多节点)
    1. xpack.security.transport.ssl.enabled: true
    2. xpack.security.transport.ssl.verification_mode: certificate
    3. xpack.security.transport.ssl.keystore.path: “elastic-certificates.p12”
    4. xpack.security.transport.ssl.truststore.path: “elastic-certificates.p12”
  3. 完成后重启Elasticsearch使配置生效。

五 生效验证与加固建议

  1. 生效与验证

    1. 重启Filebeat:systemctl restart filebeat
    2. 查看状态与日志:systemctl status filebeat;tail -f /var/log/filebeat/filebeat
    3. 确认日志中无TLS握手或证书验证错误,且事件正常发送。
  2. 加固建议

    1. 文件与目录权限:chmod 600 /etc/filebeat/filebeat.yml;chown -R filebeat:filebeat /etc/filebeat /var/log/filebeat
    2. 以非特权用户运行:在systemd服务单元设置User=filebeat,避免使用root
    3. 网络访问控制:使用UFW/iptables仅允许必要来源IP访问9200/5044等端口
    4. 证书与组件维护:提前规划证书有效期与轮换;保持Filebeat与Elasticsearch及时更新并定期审计配置

热门栏目