Elasticsearch 7.x修改/忘记密码
环境说明
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}
作者:kaysen
链接:https://juejin.cn/post/7028034368115310622