在CentOS上使用Filebeat實現日志加密傳輸,可以通過以下步驟來完成:
首先,確保你已經在CentOS上安裝了Filebeat。你可以從Elastic官方網站下載并安裝最新版本的Filebeat。
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.10.0-amd64.deb
sudo dpkg -i filebeat-7.10.0-amd64.deb
編輯Filebeat的配置文件/etc/filebeat/filebeat.yml
,添加或修改以下配置以實現日志加密傳輸。
在filebeat.yml
中,找到或添加以下配置:
output.elasticsearch:
hosts: ["https://your_elasticsearch_host:9200"]
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
ssl.certificate: "/etc/filebeat/certs/filebeat.crt"
ssl.key: "/etc/filebeat/certs/filebeat.key"
你需要生成SSL證書和密鑰,并將它們放置在指定的目錄中。
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/filebeat/certs/ca.key -out /etc/filebeat/certs/ca.crt -subj "/C=US/ST=YourState/L=YourCity/O=YourOrganization/CN=YourCA"
sudo openssl req -newkey rsa:2048 -nodes -keyout /etc/filebeat/certs/filebeat.key -out /etc/filebeat/certs/filebeat.csr -subj "/C=US/ST=YourState/L=YourCity/O=YourOrganization/CN=your_elasticsearch_host"
sudo openssl x509 -req -in /etc/filebeat/certs/filebeat.csr -CA /etc/filebeat/certs/ca.crt -CAkey /etc/filebeat/certs/ca.key -CAcreateserial -out /etc/filebeat/certs/filebeat.crt -days 365
確保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實現日志的加密傳輸。確保在生產環境中使用強密碼和證書,并定期更新它們以保持安全性。