1、启动容器
docker run -d -p 9200:9200 -p 9300:9300 --hostname es --network seata_default -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" --name es -v es_config:/usr/share/elasticsearch/config -v es_data:/usr/share/elasticsearch/data elasticsearch:7.16.1
2、修改配置文件
vim /var/lib/docker/volumes/es_config/_data/elasticsearch.yml
cluster.name: "docker-cluster" #集群名称
network.host: 0.0.0.0 #设置允许其他ip访问,解除ip绑定
#安全配置
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
3、生成ca: elastic-stack-ca.p12
#进入容器
docker exec -it es /bin/bash
#容器内生成 一路回车就行
./bin/elasticsearch-certutil ca
4、生成cert: elastic-certificates.p12
# 容器内生成
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
# 生成后需要移到config下面
mv elastic-certificates.p12 ./config
5、生成密码
#容器内生成
./bin/elasticsearch-setup-passwords auto
6、再次修改配置
vim /var/lib/docker/volumes/es_config/_data/elasticsearch.yml
cluster.name: "docker-cluster" #集群名称
network.host: 0.0.0.0 #设置允许其他ip访问,解除ip绑定
#安全配置 最终配置
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
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
7、重启容器
8、java连接配置
spring:
elasticsearch:
rest:
username: elastic
password: rrqgVK9DGRg43jz1YJkR
uris:
- http://ll129.com:9200
9、原文地址
docker安装Elasticsearch7.6集群并设置密码 - Ryan.Miao - 博客园
10、只设置密码
docker run -d -p 9200:9200 -p 9300:9300 --hostname es --network seata_default -e "discovery.type=single-node" -e "xpack.security.enabled=true" -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" --name es -v es_config:/usr/share/elasticsearch/config -v es_data:/usr/share/elasticsearch/data elasticsearch:7.16.1
#进入容器
./bin/elasticsearch-setup-passwords auto