溫馨提示×

Filebeat在CentOS上如何實現日志加密傳輸

小樊
39
2025-03-19 15:30:25
欄目: 網絡安全

在CentOS上使用Filebeat實現日志加密傳輸,可以通過以下步驟來完成:

1. 安裝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

2. 配置Filebeat

編輯Filebeat的配置文件/etc/filebeat/filebeat.yml,添加或修改以下配置以實現日志加密傳輸。

2.1 啟用TLS加密

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"

2.2 配置證書和密鑰

你需要生成SSL證書和密鑰,并將它們放置在指定的目錄中。

生成CA證書
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"
生成Filebeat證書和密鑰
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

2.3 配置Elasticsearch

確保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 ""

3. 重啟Filebeat和Elasticsearch

完成配置后,重啟Filebeat和Elasticsearch服務以應用更改。

sudo systemctl restart filebeat
sudo systemctl restart elasticsearch

4. 驗證配置

確保Filebeat能夠成功連接到Elasticsearch,并且日志數據是通過TLS加密傳輸的。你可以通過查看Elasticsearch的日志文件來驗證這一點。

sudo tail -f /var/log/elasticsearch/filebeat.log

通過以上步驟,你可以在CentOS上使用Filebeat實現日志的加密傳輸。確保在生產環境中使用強密碼和證書,并定期更新它們以保持安全性。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女