需要在配置文件中开启x-pack验证, 修改config目录下面的elasticsearch.yml文件,在里面添加如下内容,并重启ES
[root@localhost esuser]# vim /opt/es/elasticsearch-7.7.0/config/elasticsearch.yml
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
执行设置用户名和密码的命令,这里需要为4个用户分别设置密码,elastic, kibana, logstash_system,beats_system ( 注意:此时要开启ES)
[root@localhost ~]# ./elasticsearch-7.7.0/bin/elasticsearch-setup-passwords interactive
其中,用户权限分别如下:
修改密码命令如下
curl -XPUT -u elastic 'http://172.30.43.13:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json
Elasticsearch设置用户名密码之后,不能再直接使用Elasticsearch head 访问,可以在查询等API上加上用户等参数:
修改配置文件elasticsearch.yml, 并重启ES
vim elasticsearch-7.7.0/config/elasticsearch.yml
增加如下内容:
http.cors.allow-headers: Authorization
注意: 重启ES后,若head显示 '集群健康值:未连接' 就换成下面的内容,再重启ES
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
访问head时,url如下所示:
http://172.30.28.11:9100/?auth_user=elastic&auth_password=123456
参考文章