環境說明
-
JDK 8
-
CentOS 7
-
Elasticsearch 7.7.0單節點
前言
我們使用x-pack給Elasticsearch7.7.0設置密碼,可參考Elasticsearch 7.x設置密碼。但是我們難免會遇到兩個問題:
- 設置的密碼太過簡單,安全性不足;
- 忘記了已經設置的密碼,導致服務無法連接。
所以我們需要對Elasticsearch
服務修改/重置密碼。
修改前提
- 使用
普通用戶
權限對Elasticsearch進行操作; - 我們在Elasticsearch 7.x設置密碼文章中
Elastic
用戶設置的密碼為:123456
;
修改步驟
已知ES原密碼,只需進行修改
-
目前采用
curl
方式:curl -XPOST -u elastic "127.0.0.1:9200/_security/user/elastic/_password" -H 'Content-Type: application/json' -d'{"password" : "elastic123456"}'
- 其中
elastic123456
為修改后的密碼;
- 其中
-
控制台需要鍵入原來的密碼進行驗證
Enter host password for user 'elastic':
-
輸入原來的密碼:
123456
: -
驗證及完整打印:
[kaysen@localhost elasticsearch-7.7.0]$ curl -XPOST -u elastic "127.0.0.1:9200/_security/user/elastic/_password" -H 'Content-Type: application/json' -d'{"password" : "elastic123456"}' Enter host password for user 'elastic': {}[kaysen@localhost elasticsearch-7.7.0]$ curl -u elastic:elastic123456 http://127.0.0.1:9200 { "name" : "localhost.localdomain", "cluster_name" : "elasticsearch", "cluster_uuid" : "MZlO8UPyS52AuuCrFwABvQ", "version" : { "number" : "7.7.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf", "build_date" : "2020-05-12T02:01:37.602180Z", "build_snapshot" : false, "lucene_version" : "8.5.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
忘記密碼,需要進行重置
-
修改配置文件
config/elasticsearch.yml
,注釋掉支持x-pack的xpack.security.enabled: true
配置,保存退出;# ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true # #xpack.security.enabled: true
-
重啟
Elasticsearch
進程(先kill掉):./bin/elasticsearch -d
-
啟動成功后,使用
curl
查看當前Elasticsearch
的索引:curl -XGET "127.0.0.1:9200/_cat/indices" -H 'Content-Type: application/json'
-
控制台打印,多了一個
.security-7
的索引:[kaysen@localhost elasticsearch-7.7.0]$ curl -XGET "127.0.0.1:9200/_cat/indices" -H 'Content-Type: application/json' green open .security-7 J7VZVkwGT0um4GyH3nptnQ 1 0 6 0 20.5kb 20.5kb
-
刪除
.security-7
的索引curl -XDELETE 127.0.0.1:9200/.security-7
-
有如下打印,表示已成功刪除:
{"acknowledged":true}
-
重置密碼,請參考文章Elasticsearch 7.x設置密碼進行設置。