学而实习之 不亦乐乎

Elasticsearch 设置用户名和密码

2024-02-25 20:40:53

环境
Windows 10
Elasticsearch 7.17.0

一、设置密码

1、开启 x-pack 验证

修改 config 目录下面的 elasticsearch.yml 文件,在里面添加如下内容,并重启 Elasticsearch。

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

2、设置用户名和密码

进入es的安装根目录bin下,D:\soft\elasticsearch-7.17.0\bin

执行设置用户名和密码的命令,这里需要为4个用户分别设置密码,elastic, kibana, logstash_system,beats_system

PS D:\soft\elasticsearch-7.17.0\bin> elasticsearch-setup-passwords interactive
... ...
Enter password for [elastic]:
Reenter password for [elastic]:
Passwords do not match.
Try again.
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]

3、设置 kibana

在 kibana.yml 添加以下配置(或对注释进行修改):

elasticsearch.username: "elastic"
elasticsearch.password: "xxxx"

4,重启 kibana 即可。

注意:修改密码时,将第一步配置删除,然后重启es,将.security-7的索引删除即可。然后再执行上面的流程。