温馨提示×

ubuntu filebeat如何设置证书

小樊
35
2026-10-11 00:52:35
栏目: 智能运维

在 Ubuntu 上使用 Filebeat 配置证书,通常出现在以下两种场景:

  1. Filebeat → Elasticsearch / Logstash(TLS 加密通信)
  2. Filebeat 自身作为 HTTPS 服务(较少见)

下面以最常见场景:Filebeat 向 Elasticsearch / Logstash 发送数据并使用 TLS 证书为例说明。


一、准备证书文件

通常你会得到以下文件(名称可能不同):

  • ca.crt:CA 证书
  • client.crt:Filebeat 客户端证书
  • client.key:Filebeat 客户端私钥

放到合适目录,例如:

sudo mkdir -p /etc/filebeat/certs
sudo cp ca.crt client.crt client.key /etc/filebeat/certs/
sudo chmod 600 /etc/filebeat/certs/client.key
sudo chown -R root:root /etc/filebeat/certs

二、配置 Filebeat 使用证书

1️⃣ Filebeat → Elasticsearch(TLS)

编辑配置文件:

sudo vim /etc/filebeat/filebeat.yml

示例配置:

output.elasticsearch:
  hosts: ["https://es-node1:9200"]
  username: "filebeat_writer"
  password: "your_password"

  ssl:
    enabled: true
    certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
    certificate: "/etc/filebeat/certs/client.crt"
    key: "/etc/filebeat/certs/client.key"

✅ 说明:

  • certificate_authorities:用于验证 ES 的证书
  • certificate + key:Filebeat 自己的客户端证书(若 ES 开启双向 TLS)

2️⃣ Filebeat → Logstash(TLS)

output.logstash:
  hosts: ["logstash:5044"]

  ssl:
    enabled: true
    certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
    certificate: "/etc/filebeat/certs/client.crt"
    key: "/etc/filebeat/certs/client.key"

Logstash 端需对应开启 ssl => true。


三、自签名证书(无 CA)情况

如果只是自签名证书:

ssl:
  enabled: true
  verification_mode: "none"

⚠️ 不推荐生产环境使用


四、测试与启动

测试配置

sudo filebeat test config
sudo filebeat test output

重启 Filebeat

sudo systemctl restart filebeat
sudo systemctl status filebeat

五、常见问题

❌ x509: certificate signed by unknown authority

  • CA 文件未正确配置
  • 路径写错或权限不足

❌ permission denied

sudo chmod 600 /etc/filebeat/certs/client.key

❌ cannot validate certificate

  • 时间不同步
  • 证书 CN / SAN 不匹配

六、总结最小可用配置

ssl:
  enabled: true
  certificate_authorities: ["/etc/filebeat/certs/ca.crt"]

如你是 Elastic Cloud / Kubernetes / 双向认证 / PKCS#12 场景,可以告诉我,我可以给你对应配置示例。

0 踩