一、说明
1、docker部署es
2、docker默认无密码,现在需求需要增加安全性,需要增加密码
二、操作步骤
1、启动es镜像,参考
https://blog.csdn.net/myloverisxin/article/details/127075387
2、修改es配置
vi /opt/elasticsearch/config/elasticsearch.yml
3、开启安全验证
xpack.security.enabled: true xpack.security.transport.ssl.enabled: true
3、重启docker
docker restart 332098b1879d
说明: 容器ID
4、进入到容器
docker exec -it 332098b1879d /bin/bash
5、生成证书1
./bin/elasticsearch-certutil ca
说明: 一直回车即可
6、生成证书2
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
7、将证书移动到config
mv elastic-certificates.p12 ./config
8、生成密码
./bin/elasticsearch-setup-passwords auto
说明: 一路回车,回车完后会打印生成的密码
9、退出容器,增加配置并保存
vi /opt/elasticsearch/config/elasticsearch.yml
xpack.security.transport.ssl.keystore.type: PKCS12 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 xpack.security.transport.ssl.truststore.type: PKCS12 xpack.security.audit.enabled: true
10、增加文件可访问权限
chmod +777 /opt/elasticsearch/config/elastic-certificates.p12
11、重启镜像
docker restart 332098b1879d
12、如果报错了,可能需要查看日志并解决
docker logs -f 332098b1879d
13、重启结果
netstat -anp | grep 9200
14、验证密码设置
![]()
~~