ElasticSearch重置密码
对于新安装的ElasticSearch,可使用如下,生成密码
1.使用内置用户生成密码
bin/elasticsearch-setup-passwords interactive
2.自动生成密码
bin/elasticsearch-setup-passwords auto
以上两种方式均报错,显示无法通过默认的 elastic 用户认证
原因是:
1、密码已被修改(但您不记得新密码)
2、使用的 keystore 文件不匹配(如配置了其他位置的 keystore)
推测是已经修改了密码,便重置elastic用户密码
1.停止elasticsearch,直接将datastore整个关掉
2.临时禁用安全功能
编辑 config/elasticsearch.yml,添加或修改以下配置
xpack.security.enabled: false
3.重启Elasticsearch,确定elasticsearch已经启动
4.使用API重置密码
默认端口我这已经改变,自行确认自己的端口
curl -X POST "localhost:9301/_security/user/elastic/_password?pretty" \
-H "Content-Type: application/json" \
-d '{"password": "changeme@123"}'
5.重新启动安全功能
修改 elasticsearch.yml,恢复安全设置:
xpack.security.enabled: true
6.重启Elasticsearch
7.验证新密码
我这es的端口由默认的9200改为9201,自行确定自己的端口
curl -u elastic:changeme@123 "http://localhost:9201/_cluster/health?pretty"
如果返回 401 Unauthorized,说明密码错误。
如果返回集群状态,说明认证成功