Docker中创建ES集群并修改默认用户密码-sunziren
注1,本文参考了https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
注2,本文这种搭建的方式,适用于开发环境,不适用与生产环境,生产环境要用Docker搭建ES集群,请使用docker-compose命令
#创建docker内部网络elastic
docker network create elastic
#下面三条命令,是创建了一个ES集群,注意第一台命令执行完后,等待容器启动完成,将里面的重要密码复制出来
docker run --name es-8.1.2-1 --net elastic -p 19200:9200 -it -m 2GB -d elasticsearch:8.1.2
------------------------------------------------------------------------------------------------------
-> Elasticsearch security features have been automatically configured!
-> Authentication is enabled and cluster connections are encrypted.
-> Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
4o-OOjSGYYRFzyy-TUaf
-> HTTP CA certificate SHA-256 fingerprint:
14bdd77faa5b44dcb8f7b817ff865204a4d364bdae911fed2e0588b69bb07882
-> Configure Kibana to use this cluster:
* Run Kibana and click the configuration link in the terminal when Kibana starts.
* Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjEuMiIsImFkciI6WyIxNzIuMTkuMC4yOjkyMDAiXSwiZmdyIjoiMTRiZGQ3N2ZhYTViNDRkY2I4ZjdiODE3ZmY4NjUyMDRhNGQzNjRiZGFlOTExZmVkMmUwNTg4YjY5YmIwNzg4MiIsImtleSI6InhCV21INHdCUmVFRkVBMHgxNDl6Om5ka0d1bW84UXNHQURodnNpcm9uS2cifQ==
-> Configure other nodes to join this cluster:
* Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjEuMiIsImFkciI6WyIxNzIuMTkuMC4yOjkyMDAiXSwiZmdyIjoiMTRiZGQ3N2ZhYTViNDRkY2I4ZjdiODE3ZmY4NjUyMDRhNGQzNjRiZGFlOTExZmVkMmUwNTg4YjY5YmIwNzg4MiIsImtleSI6Ind4V21INHdCUmVFRkVBMHgxNDl6OmtoUkYxLUkwUWVXaDQwLXc3TEI0MXcifQ==
If you're running in Docker, copy the enrollment token and run:
`docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.1.2`
-----------------------------------------------------------------------------------------------------
docker run -e ENROLLMENT_TOKEN="eyJ2ZXIiOiI4LjEuMiIsImFkciI6WyIxNzIuMTkuMC4yOjkyMDAiXSwiZmdyIjoiMTRiZGQ3N2ZhYTViNDRkY2I4ZjdiODE3ZmY4NjUyMDRhNGQzNjRiZGFlOTExZmVkMmUwNTg4YjY5YmIwNzg4MiIsImtleSI6Ind4V21INHdCUmVFRkVBMHgxNDl6OmtoUkYxLUkwUWVXaDQwLXc3TEI0MXcifQ==" --name es-8.1.2-2 --net elastic -it -m 2GB -d elasticsearch:8.1.2
docker run -e ENROLLMENT_TOKEN="eyJ2ZXIiOiI4LjEuMiIsImFkciI6WyIxNzIuMTkuMC4yOjkyMDAiXSwiZmdyIjoiMTRiZGQ3N2ZhYTViNDRkY2I4ZjdiODE3ZmY4NjUyMDRhNGQzNjRiZGFlOTExZmVkMmUwNTg4YjY5YmIwNzg4MiIsImtleSI6Ind4V21INHdCUmVFRkVBMHgxNDl6OmtoUkYxLUkwUWVXaDQwLXc3TEI0MXcifQ==" --name es-8.1.2-3 --net elastic -it -m 2GB -d elasticsearch:8.1.2
#修改默认密码
curl -k --cacert http_ca.crt -XPOST -u elastic "https://192.168.17.92:19200/_security/user/elastic/_password" -H 'Content-Type: application/json' -d'{"password" : "zhangsanlisi"}'
执行完上面的命令后,会让你先输入原来的密码4o-OOjSGYYRFzyy-TUaf,你就粘贴,然后回车,就好了