溫馨提示×

如何在CentOS上安全地部署Filebeat

小樊
49
2025-03-23 16:08:41
欄目: 智能運維

在CentOS上安全地部署Filebeat涉及多個步驟,包括安裝、配置、安全設置和監控。以下是一個詳細的指南:

1. 安裝Filebeat

首先,確保你的CentOS系統已經更新到最新版本:

sudo yum update -y

然后,添加Elastic的官方YUM倉庫:

sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
echo "[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md" | sudo tee -a /etc/yum.repos.d/elasticsearch.repo

接下來,安裝Filebeat:

sudo yum install filebeat -y

2. 配置Filebeat

編輯Filebeat的配置文件 /etc/filebeat/filebeat.yml

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

output.elasticsearch:
  hosts: ["localhost:9200"]
  ssl.verification_mode: certificate
  ssl.certificate_authorities: ["/etc/pki/tls/certs/ca-bundle.crt"]
  ssl.certificate: "/etc/pki/tls/certs/filebeat.crt"
  ssl.key: "/etc/pki/tls/private/filebeat.key"

setup.template.enabled: false
setup.kibana:
  host: "localhost:5601"

3. 配置SSL/TLS

為了確保數據傳輸的安全性,你需要為Filebeat和Elasticsearch配置SSL/TLS。

生成證書

使用OpenSSL生成自簽名證書:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/filebeat.key -out /etc/pki/tls/certs/filebeat.crt -subj "/CN=filebeat/O=example.com"
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/elasticsearch.key -out /etc/pki/tls/certs/elasticsearch.crt -subj "/CN=elasticsearch/O=example.com"
sudo openssl req -new -x509 -days 365 -nodes -keyout /etc/pki/tls/certs/ca-bundle.crt -out /etc/pki/tls/certs/ca-bundle.crt -subj "/CN=ca/O=example.com"

配置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

xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: elastic-certificates.p12
xpack.security.http.ssl.truststore.path: elastic-certificates.p12

然后,重啟Elasticsearch:

sudo systemctl restart elasticsearch

配置Filebeat

確保Filebeat的配置文件中包含了SSL/TLS相關的設置,如上文所示。

4. 啟動和啟用Filebeat服務

啟動Filebeat服務并設置為開機自啟:

sudo systemctl start filebeat
sudo systemctl enable filebeat

5. 監控和日志

確保你有一個監控系統來跟蹤Filebeat的狀態和性能。你可以使用Elastic Stack(包括Kibana)來監控和分析日志數據。

安裝和配置Kibana

如果你還沒有安裝Kibana,可以按照以下步驟進行安裝:

sudo yum install kibana -y

編輯Kibana的配置文件 /etc/kibana/kibana.yml,確保它指向正確的Elasticsearch實例:

server.host: "0.0.0.0"
elasticsearch.hosts: ["https://localhost:9200"]

然后,啟動Kibana服務并設置為開機自啟:

sudo systemctl start kibana
sudo systemctl enable kibana

現在,你應該能夠通過瀏覽器訪問 http://your_server_ip:5601 來使用Kibana。

6. 安全加固

  • 防火墻設置:確保只允許必要的端口(如9200和5601)對外開放。

    sudo firewall-cmd --permanent --zone=public --add-port=9200/tcp
    sudo firewall-cmd --permanent --zone=public --add-port=5601/tcp
    sudo firewall-cmd --reload
    
  • SELinux設置:如果你啟用了SELinux,可能需要調整相關策略以允許Filebeat和Elasticsearch的正常運行。

通過以上步驟,你應該能夠在CentOS上安全地部署Filebeat,并確保數據傳輸的安全性。

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