ELK系列(九)、配置ES和Kibana的用戶密碼

前面介紹的都是沒有設置密碼的情況,ES默認沒有密碼,什麼數據泄露的新聞簡直是家常便飯,所以這裏還是建議大家給ES和kibana設置用戶登陸,或者使用nginx限制IP或用戶訪問。本文介紹ELK自帶的創建用戶的方式。

ELK系列(一)、安裝ElasticSearch+Logstash+Kibana+Filebeat-v7.7.0

ELK系列(二)、在Kibana中使用RESTful操作ES庫

ELK系列(三)、安裝Logstash插件及打包離線安裝包

ELK系列(四)、Logstash讀取nginx日誌寫入ES中

ELK系列(五)、Logstash修改@timestamp時間爲日誌的產生時間

ELK系列(六)、修改Nginx日誌爲Json格式並使用Logstash導入至ES

ELK系列(七)、Filebeat+Logstash採集多個日誌文件並寫入不同的ES索引中

ELK系列(八)、使用Filebeat+Redis+Logstash收集日誌數據

 

-------------------------------------創建ELK的用戶------------------------------

修改ES配置開啓X-PACK

vim /opt/app/elasticsearch-7.7.0/config/elasticsearch.yml 

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

重啓ES

sudo -u elk nohup $ES_HOME/bin/elasticsearch >> $ES_HOME/output.log 2>&1 &

創建用戶

cd $ES_HOME

bin/elasticsearch-setup-passwords interactive

[root@node01 elasticsearch-7.7.0]# bin/elasticsearch-setup-passwords interactive
future versions of Elasticsearch will require Java 11; your Java version from [/opt/app/jdk1.8.0_181/jre] does not meet this requirement
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

修改Kibana配置

/opt/app/kibana-7.7.0-linux-x86_64/config/kibana.yml 

elasticsearch.username: "kibana"
elasticsearch.password: "123456"

重啓kibana

sudo -u elk  nohup $KB_HOME/bin/kibana > $KB_HOME/output.log 2>&1 &

驗證

訪問ES需要密碼:

訪問kibana需要密碼:

在kibana中可以新增用戶,對用戶和角色進行管理

如果想取消用戶密碼登陸的話,只需要把第一步裏面的ES的那幾個配置註釋並重啓ES即可,然後登陸ES和Kiabana就不需要密碼了,但是不建議這麼做。

最後再次提醒大家,線上的ES一定要注意數據保護,開啓防火牆,最好不要把端口暴露到公網,禁用ES批量刪除索引功能。

 

希望本文對你有幫助,請點個贊鼓勵一下作者吧~ 謝謝!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章