docker Installing ElasticSearch: Detailed Tutorial for 7.8. 0 Clusters
- 2021-10-16 05:23:36
- OfStack
ElasticSearch Cluster Support
动态请求的方式
Build clusters and
静态配置文件
Build a cluster
Official document on dynamic connectivity for clusters: https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html
Pre-preparation work
Official website description of parameters:
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery-settings.html
下载elsticsearch 7.8.0
docker pull elasticsearch:7.8.0
Create 1 network es_net to put elasticsearch cluster
docker network create --subnet=172.18.0.0/24 es_net
According to the information WORKDIR/usr/share/elasticsearch in the dockerFile file of official website, we can know that the installation location of elasticsearch is under the directory /usr/share/elasticsearch. In order to facilitate the later operation, a data volume is created to map the data generated by elasticsearch to the host, so as to prevent the data from being recovered when es goes down.
Create a data volume
docker volume create es_data01
docker volume create es_data02
docker volume create es_data03
# Common configuration files and plug-in storage locations
docker volume create es_conf
docker volume create es_plugins
Store data, configuration and plug-ins separately
Create 3 yml configuration files
Building ElasticSearch cluster in a dynamic way (recommended)
It means that the cluster can be built only by starting ElasticSearch and then using RestFul style operation that comes with ES
The official startup mode in dockerhub is single node startup
Start three ElasticSearch nodes separately
Start es01
docker run -it -d --restart always -p 9201:9200 -p 9301:9300 \
--name es01 --network=es_net --ip=172.18.0.101 \
-v es_data01:/usr/share/elasticsearch/data \
-v es_conf:/usr/share/elasticsearch/conf \
-v es_plugins:/usr/share/elasticsearch/plugins \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" elasticsearch:7.8.0
Start es02
docker run -it -d --restart always -p 9202:9200 -p 9302:9300 \
--name es02 --network=es_net --ip=172.18.0.102 \
-v es_data02:/usr/share/elasticsearch/data \
-v es_conf:/usr/share/elasticsearch/conf \
-v es_plugins:/usr/share/elasticsearch/plugins \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" elasticsearch:7.8.0
Start es03
docker run -it -d --restart always -p 9203:9200 -p 9303:9300 \
--name es03 --network=es_net --ip=172.18.0.103 \
-v es_data03:/usr/share/elasticsearch/data \
-v es_conf:/usr/share/elasticsearch/conf \
-v es_plugins:/usr/share/elasticsearch/plugins \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" elasticsearch:7.8.0
Through PUT mode
It can be operated by curl command of linux
On es02 and es03
curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent" : {
"cluster" : {
"remote" : {
"leader" : {
"seeds" : [
"127.0.0.1:9300"
]
}
}
}
}
}
'
Update persistent
curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent" : {
"indices.recovery.max_bytes_per_sec" : "50mb"
}
}
'
Update transient
curl -X PUT "localhost:9200/_cluster/settings?flat_settings=true&pretty" -H 'Content-Type: application/json' -d'
{
"transient" : {
"indices.recovery.max_bytes_per_sec" : "20mb"
}
}
'
Delete transient configuration content
curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"transient" : {
"indices.recovery.max_bytes_per_sec" : null
}
}
'
Delete all transient settings
docker network create --subnet=172.18.0.0/24 es_net
0
ElasticSearch starts the cluster through a static configuration file
The reason for the failure should be that there should be fewer parameters when starting the container.
According to the official website document, discovery. zen. ping. unicast. hosts will no longer be used in future versions, so it will become discovery.seed_hosts
es-node1 Node Profile Information
docker network create --subnet=172.18.0.0/24 es_net
1
Please modify the comment line host ip and the port address of es trunking communication
docker network create --subnet=172.18.0.0/24 es_net
2
It can be seen from the above configuration file that the ports to be mapped are 9300, 9301 and 9302 respectively, which are used for cluster communication
That is, the binding ports of the three nodes are-p 9300: 9300,-p 9301: 9300 and-p 9302: 9300 respectively.
At the same time, we can introduce-p 9200: 9200,-p 9201: 9200,-p 9202: 9200
Make a table:
节点 | 绑定宿主机端口1 | 绑定宿主机端口2 |
---|---|---|
es-node1 | 9200 | 9300 |
es-node2 | 9201 | 9301 |
es-node3 | 9202 | 9301 |
作用 | 对外提供服务的端口 | es1-es3集群间进行通讯的端口 |
es-node2 Node Configuration File Information
vim /var/lib/docker/volumes/es_conf/_data/es02.yml
The difference with es-node1 is that the node name is changed to 1
docker network create --subnet=172.18.0.0/24 es_net
4
es-node3 Node Configuration File Information
docker network create --subnet=172.18.0.0/24 es_net
5
The difference with es-node1 is that the node name is changed to 1
docker network create --subnet=172.18.0.0/24 es_net
6
Start the cluster in turn
es-node1 Start Command, docker Process Alias es01
The network used is the network card es_net created above, and the internal network ip 172.18. 0.100 of the specified node needs to be in the same network segment as es_net
docker network create --subnet=172.18.0.0/24 es_net
7
ES_JAVA_OPTS Specifies the memory of es to be used to prevent too much memory space from being used when starting es
--restart always boot-up
Data volume mapping, only 1 need to note that the configuration file es01. yml is mapped to the internal es startup, the use of the configuration file.
es-node2 Start Command
docker run -it -d --restart always -p 9201:9200 -p 9301:9300 \
--name es02 --network=es_net --ip=172.18.0.101 \
-v es_data02:/usr/share/elasticsearch/data \
-v /var/lib/docker/volumes/es_conf/_data/es02.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v es_plugins:/usr/share/elasticsearch/plugins \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" elasticsearch:7.8.0
es-node3 Start Command
docker network create --subnet=172.18.0.0/24 es_net
9