温馨提示×

CentOS下Filebeat如何配置SSL加密

小樊
47
2025-11-07 23:00:19
栏目: 云计算

在CentOS系统下,为Filebeat配置SSL加密可以帮助你安全地传输日志数据。以下是详细的步骤指南:

1. 安装Filebeat

首先,确保你已经安装了Filebeat。如果还没有安装,可以使用以下命令进行安装:

sudo yum install filebeat -y

2. 配置Filebeat输出到Elasticsearch

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

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/client.crt"
  ssl.key: "/etc/filebeat/certs/client.key"

3. 生成SSL证书

你需要为Filebeat生成SSL证书。可以使用OpenSSL来生成自签名证书或从CA获取证书。

生成自签名证书

# 创建CA目录
mkdir -p /etc/filebeat/certs

# 生成CA私钥
openssl genrsa -out /etc/filebeat/certs/ca.key 2048

# 生成CA证书
openssl req -new -x509 -days 3650 -key /etc/filebeat/certs/ca.key -out /etc/filebeat/certs/ca.crt -subj "/C=US/ST=YourState/L=YourCity/O=YourOrganization/CN=YourCA"

# 生成Filebeat客户端私钥
openssl genrsa -out /etc/filebeat/certs/client.key 2048

# 生成CSR(证书签名请求)
openssl req -new -key /etc/filebeat/certs/client.key -out /etc/filebeat/certs/client.csr -subj "/C=US/ST=YourState/L=YourCity/O=YourOrganization/CN=your_elasticsearch_host"

# 使用CA证书签名CSR
openssl x509 -req -in /etc/filebeat/certs/client.csr -CA /etc/filebeat/certs/ca.crt -CAkey /etc/filebeat/certs/ca.key -CAcreateserial -out /etc/filebeat/certs/client.crt -days 365

从CA获取证书

如果你已经有CA证书和客户端证书,可以直接使用这些证书。

4. 配置Elasticsearch以接受SSL连接

确保你的Elasticsearch集群已经配置了SSL。编辑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服务:

sudo systemctl restart elasticsearch

5. 重启Filebeat服务

最后,重启Filebeat服务以应用新的配置:

sudo systemctl restart filebeat

6. 验证配置

你可以通过查看Filebeat和Elasticsearch的日志来验证SSL配置是否成功。例如,查看Filebeat日志:

sudo journalctl -u filebeat -f

查看Elasticsearch日志:

sudo journalctl -u elasticsearch -f

通过以上步骤,你应该能够在CentOS系统下成功配置Filebeat的SSL加密传输。

0