在CentOS上使用Filebeat進行日志加密可以通過配置TLS/SSL加密傳輸來實現。以下是詳細的步驟:
首先,確保你已經在CentOS上安裝了Filebeat。如果沒有安裝,可以使用以下命令進行安裝:
sudo yum install filebeat
使用OpenSSL生成SSL證書和密鑰。以下是生成自簽名證書的示例命令:
# 創建CA目錄和文件
mkdir -p /etc/pki/tls/certs
mkdir -p /etc/pki/tls/private
# 生成CA私鑰
openssl genrsa -out /etc/pki/tls/private/ca.key 2048
# 生成CA證書
openssl req -x509 -new -nodes -key /etc/pki/tls/private/ca.key -out /etc/pki/tls/certs/ca.crt -days 3650
# 生成Filebeat私鑰
openssl genrsa -out /etc/pki/tls/private/filebeat.key 2048
# 生成CSR(證書簽名請求)
openssl req -new -key /etc/pki/tls/private/filebeat.key -out /etc/pki/tls/certs/filebeat.csr -subj "/CN=<Filebeat_Server_IP>/"
# 使用CA證書簽名CSR,生成Filebeat證書
openssl x509 -req -in /etc/pki/tls/certs/filebeat.csr -CA /etc/pki/tls/certs/ca.crt -CAkey /etc/pki/tls/private/ca.key -CAcreateserial -out /etc/pki/tls/certs/filebeat.crt -days 365
編輯Filebeat的配置文件 /etc/filebeat/filebeat.yml,指定SSL證書和密鑰的位置,以及目標服務器的地址和端口。
filebeat.inputs:
- type: log
paths:
- /path/to/your/log/*.log
output.elasticsearch:
hosts:
- ["https://your-elasticsearch-server:9200"]
ssl.certificate_authorities:
- "/etc/pki/tls/certs/ca.crt" # CA證書的路徑,用于驗證目標服務器的身份
ssl.certificate: "/etc/pki/tls/certs/filebeat.crt" # Filebeat的證書路徑
ssl.key: "/etc/pki/tls/private/filebeat.key" # Filebeat的私鑰路徑
確保Elasticsearch已經配置為接受TLS連接。編輯 /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的 elasticsearch-certutil 工具生成證書和密鑰:
sudo /usr/share/elasticsearch/bin/elasticsearch-certutil ca --pem --out /etc/elasticsearch/certs/ca.crt
sudo /usr/share/elasticsearch/bin/elasticsearch-certutil cert --pem -in /etc/elasticsearch/certs/ca.crt -out /etc/elasticsearch/certs/elastic-certificates.p12 -pass ""
完成配置后,重啟Filebeat和Elasticsearch服務以應用更改:
sudo systemctl restart filebeat
sudo systemctl restart elasticsearch
確保Filebeat能夠成功連接到Elasticsearch,并且日志數據是通過TLS加密傳輸的。你可以通過查看Elasticsearch的日志文件來驗證這一點。
sudo tail -f /var/log/elasticsearch/filebeat.log
通過以上步驟,你可以在CentOS上使用Filebeat實現日志的加密傳輸。