elasticsearch-7.12.1集群设置账号密码(亲测可用)

ES7.7以后的版本将安全认证功能免费开放了。并将X-pack插件集成了到了开源的ElasticSearch版本中。

1. 在集群的“主节点”上生成证书

切换到elastsearch的目录下,使用下列命令生成证书

bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass ""

2.将生成的证书elastic-certificates.p12复制到集群中的其他节点的config目录下

3.修改集群中所有节点的配置文件,启用x-pack

vi config/elasticsearch.yml

#在文件末尾,增加下面5行内容

xpack.security.enabled: true

xpack.security.transport.ssl.enabled: true

xpack.security.transport.ssl.verification_mode: certificate

xpack.security.transport.ssl.keystore.path: elastic-certificates.p12

xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

 

4.重启elasticsearch集群,所有节点都需要重新启动

./bin/elasticsearch -d  (这一步非常重要,必须启动才能新增用户名和密码);

5. 设置密码,在主节点上执行下面命令:

bin/elasticsearch-setup-passwords interactive

 并根据提示输入密码想要设置的密码(例如:123456)即可。

zftestest#2022

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]

 

6.验证:

打开浏览器,输入我们的elasticsearch的网址,然后会弹出一个输入框,让我们输入账号和密码。

7.后续修改密码:

如果你觉得之前用户的密码设置的太简单了,你想修改密码可以采用如下方式:

curl -XPOST -u elastic "localhost:9200/_security/user/elastic/_password" -H 'Content-Type: application/json' -d'{"password" : "abcd1234"}'

 

8.修改kibana配置文件,config下的kibana.yml,添加如下内容

elasticsearch.username: “elastic

elasticsearch.password: “123456”

9.修改logstash配置文件,设置连接elasticsearch的密码,按照如下方式操作

打开config/logstash.yml,添加下面一行代码:

xpack.monitoring.enabled: true

xpack.monitoring.elasticsearch.username: elastic

xpack.monitoring.elasticsearch.password: 123456

xpack.monitoring.elasticsearch.hosts: ["http://127.0.0.1:9200"]

10.修改logstash的pipeline相关的配置文件,涉及到elasticsearch的地方增加用户和密码的配置

output {

 if [type]=="user" {

elasticsearch {

hosts => "127.0.0.1:9200"

user => “elastic”

password => “123456”

# index名

index => "user"

# type名

document_type => "_doc"

# 需要关联的数据库中有有一个id字段,对应索引的id号

document_id => "%{id}"

}

stdout {

codec => json_lines

}

 

}

}

posted @ 2023-05-27 17:45  技术研究与问题解决  阅读(1320)  评论(0编辑  收藏  举报