elasticSearch 7.X配置用户名密码访问

2021-07-07 10:26:36 浏览数 (1)

版本号:7.5.1

1、需要在配置文件中开启x-pack验证,修改config目录下面的elasticsearch.yml文件,在里面添加如下内容,并重启elasticsearch服务。

[root@localhost config]# vim elasticsearch.yml

代码语言:javascript复制
# 配置X-Packhttp.cors.enabled: truehttp.cors.allow-origin: "*"http.cors.allow-headers: Authorizationxpack.security.enabled: truexpack.security.transport.ssl.enabled: true

2、重启elasticsearch服务

[root@localhost config]# su - elk

[elk@localhost ~]$ kill -9 2932

[elk@localhost ~]$ /usr/local/elasticsearch/bin/elasticsearch -d

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

[elk@localhost ~]$ /usr/local/elasticsearch/bin/elasticsearch-setup-passwords interactive

future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_181/jre] does not meet this requirement

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,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]:

Reenter password for [kibana]:

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]

Changed password for user [logstash_system]

Changed password for user [beats_system]

Changed password for user [remote_monitoring_user]

Changed password for user [elastic]

4、修改kibana.yml配置文件,添加以下配置

[elk@localhost ~]$ vim /usr/local/kibana/config/kibana.yml

代码语言:javascript复制
elasticsearch.username: "elastic"elasticsearch.password: "123456"

5、重启Kibana服务

[elk@localhost ~]$ kill -9 13666

[elk@localhost ~]$ /usr/local/kibana/bin/kibana &

6、验证

#浏览器输入本机IP 端口,会出现如下界面

至此,elasticsearch配置用户名和密码成功。

7、修改elasticsearch用户名密码

[elk@localhost ~]$ curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'

#修改密码之后,需要重新设置kibana的配置文件,才可以重新使用Kibana。

0 人点赞