天天看點

elasticsearch6.8.2設定叢集認證

一:設定elasticsearch叢集驗證功能

#問題描述:
在遠端Web伺服器上運作的ElasticSearch應用程式由于未能通過身份驗證限制資源而受到資訊洩漏漏洞的影響。未經驗證的遠端攻擊者可以利用此漏洞從資料庫中洩漏敏感資訊。
使用curl就可以直接通路es叢集 : curl http://xxxx:9200?preatty           
#使用X-Pack做認證 es版本是6.8.2
echo "*  -  nofile  65535" >> /etc/security/limits.conf
echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
sysctl -p           
curl  http://192.168.105.55:9200/_cat/health?v  #檢視叢集的名字,并且記錄下每個節點的名字,後面要用           
/data/lasticsearch/bin/elasticsearch-certgen    #開始生成證書,在叢集中任意一台上操作即可

####################################
Please enter the desired output file [certificate-bundle.zip]: cert.zip (壓縮包名稱)
Enter instance name: appEsCls(執行個體名)
Enter name for directories and files [p4mES]: elasticsearch(檔案夾名)
Enter IP Addresses for instance (comma-separated if more than one) []: 192.168.105.55,192.168.105.56,192.168.105.57(執行個體ip,多個ip用逗号隔開)
Enter DNS names for instance (comma-separated if more than one) []: node-1,node-2,node-3(節點名,多個節點用逗号隔開)
Would you like to specify another instance? Press 'y' to continue entering instance information: (到達這一步,不需要按y重新設定,按回車即可
Certificates written to /home/elastic/elasticsearch/bin/cert.zip(這個是生成的檔案存放位址,不用填寫)           
将壓縮檔案cert.zip分别拷貝紙三台機器的 /data/elasticsearch/config檔案夾下并解壓,賦予elasticsearch
生成ca和elasticsearch并修改配置檔案elasticsearch.yml
cd /data/elasticsearch/config
chown -R elasticsearch:elasticsearch ca
chown -R elasticsearch:elasticsearch elasticsearch
vim /data/elasticsearch/config/elasticsearch.yml
#增加如下配置:
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.ssl.key: elasticsearch/elasticsearch.key
xpack.ssl.certificate: elasticsearch/elasticsearch.crt
xpack.ssl.certificate_authorities: ca/ca.crt           
#重新開機叢集所有的es
systemctl restart elasticsearch           
#開始設定密碼,隻需在叢集中的一台上操作即可
/data/elasticsearch/bin/elasticsearch-setup-passwords interactive #預設會對logstash,filebeat全部設定密碼           
curl  http://192.168.105.57:9200?pretty  #此時通路就報401了
curl -u elastic:123456 http://192.168.105.57:9200   #這樣通路即可