elasticsearch加賬號密碼登入

niewj發表於2021-12-28

1. Elastic安全措施有3種

1.1 Minimal security

適用: Elasticsearch 開發模式

1.2 Basic security

適用: Elasticsearch 生產環境

1.3 Basic security + TLS for REST

更好的安全性: basic security + TLS for REST

2. 最小安全設定: minimal security for ES

2.1 先決條件

  1. 安裝了Elasticsearch;
  2. 安裝了Kibana;

2.2 配置幾個環境變數

%ES_HOME%=ES安裝目錄
ES_PATH_CONF=%ES_HOME%/config
%KIB_HOME%=Kibana安裝目錄
KIB_PATH_CONF=%KIB_HOME%/config

配置如截圖

image.png

2.3 elasticsearch.yml配置

2.3.1 啟用es安全特性:

xpack.security.enabled: true

單節點的話, 此處可確保節點不會無意中連線到其他叢集

discovery.type: single-node

2.3.3 為內建使用者設定密碼

1.開一個視窗啟動es(配置完後重新開)

./bin/elasticsearch

2.另開視窗執行elasticsearch-setup-passwords

bin/elasticsearch-setup-passwords interactive

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,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_system]:
Reenter password for [kibana_system]:
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_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]

上面的20來行, 可以重複輸入你的密碼即可~ 同時你可以多瞅一眼這裡有個user[kibana_system], 它下面有提及

2.4 kibana.yml配置

2.4.1 yml中加入kibana_system使用者

elasticsearch.username: "kibana_system"

之前已經建立了內建kibana_system使用者和密碼(前面輸入了的, 記得吧)。
Kibana執行一些後臺任務,就需要使用kibana_system使用者。

2.4.2 建立kibana的keystore

./bin/kibana-keystore create

2.4.3 將kibana_system使用者的密碼新增到Kibana的keystore中:

./bin/kibana-keystore add elasticsearch.password

2.4.4 重啟kibana即可

./bin/kibana

http://localhost:5601 再訪問, 就需要賬號密碼了, 用elastic+密碼即可

2.4的整個流程es必須是開著的

參考資料: 官方文件:Configure security for the Elastic Stack

Set up basic security for the Elastic Stack

相關文章