centos

CentOS上Filebeat如何配置SSL加密

小樊
41
2025-04-20 18:29:58
栏目: 云计算

在CentOS上配置Filebeat以使用SSL加密涉及几个步骤。以下是一个基本的指南,帮助你设置Filebeat以通过SSL/TLS加密传输数据。

前提条件

  1. Filebeat已安装:确保你已经在CentOS上安装了Filebeat。
  2. Elasticsearch已配置SSL:确保你的Elasticsearch集群已经配置了SSL/TLS。

步骤

1. 配置Filebeat输出到Elasticsearch

编辑Filebeat的配置文件/etc/filebeat/filebeat.yml,添加或修改以下内容以启用SSL/TLS加密:

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/*.log

output.elasticsearch:
  hosts: ["https://your_elasticsearch_host:9200"]
  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"

2. 生成SSL证书

如果你还没有SSL证书,可以使用openssl生成自签名证书。

生成CA证书
mkdir -p /etc/filebeat/certs
cd /etc/filebeat/certs

openssl req -x509 -newkey rsa:4096 -keyout ca.key -out ca.crt -days 3650 -nodes
生成Filebeat证书
openssl req -newkey rsa:4096 -keyout filebeat.key -out filebeat.csr -nodes
openssl x509 -req -in filebeat.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out filebeat.crt -days 3650

3. 配置Elasticsearch客户端证书

确保Elasticsearch配置文件/etc/elasticsearch/elasticsearch.yml中启用了客户端证书验证:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

然后,使用elasticsearch-certutil工具生成客户端证书:

cd /etc/elasticsearch
bin/elasticsearch-certutil cert -out filebeat.p12 -pass ""

将生成的filebeat.p12文件复制到Filebeat的证书目录:

cp filebeat.p12 /etc/filebeat/certs/

4. 重启Filebeat和Elasticsearch

重启Filebeat和Elasticsearch服务以应用更改:

sudo systemctl restart filebeat
sudo systemctl restart elasticsearch

验证配置

确保Filebeat能够成功连接到Elasticsearch并传输数据。你可以查看Filebeat的日志文件/var/log/filebeat/filebeat以获取更多信息。

tail -f /var/log/filebeat/filebeat

通过以上步骤,你应该能够在CentOS上成功配置Filebeat以使用SSL/TLS加密传输数据。

0
看了该问题的人还看了