SoFunction
Updated on 2025-03-09

Docker Elasticsearch cluster deployment operation process

1 Environment

(1)Centos7
(2)Docker 23.0.1
(3)Elasticsearch 7.16.3

2 Servers

name IP address Memory
Node One 192.16.109.113 16G
Node 2 192.16.109.114 16G
Node Three 192.16.109.115 16G

3 Deployment

Perform the following operations on the three server nodes:

Prepare the mapping directory
Switch to the /home directory, create the elasticsearch directory, and switch to the elasticsearch directory.

cd /home/
mkdir elasticsearch
cd elasticsearch

Temporarily start elasticsearch

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "=single-node" elasticsearch:7.16.3

Copy the configuration directory in the container to disk directory

cd /home/elasticsearch
docker cp elasticsearch:/usr/share/elasticsearch/config .
docker cp elasticsearch:/usr/share/elasticsearch/data .
docker cp elasticsearch:/usr/share/elasticsearch/plugins .

Grant all permissions to modify files and sub-files for elasticsearch directory and sub-files

chmod -R 777 elasticsearch

Remove the temporary start elasticsearch container

docker stop elasticsearch
docker rm elasticsearch

3.1 Node One

Revise/home/elasticsearch/config/Configuration File

# Cluster name All node names are the same: es-clusters
# The current name of the node, each node cannot repeat es-node-1, es-node-2, and es-node-3.: es-node-1
# Is this node currently eligible to run for the master node: true
# Whether the node currently stores data: true
# Set as public access: 0.0.0.0
# Set the IP address of the machine where other nodes interact with this node, each of the three nodes isnetwork.publish_host: 192.16.109.113
# Set the map port: 9200
# Communication port between internal nodes: 9300
# Support cross-domain access: true
-origin: "*"
# Configure the host address of the clusterdiscovery.seed_hosts: ["192.16.109.113","192.16.109.114","192.16.109.115"]
# Initial master node, use an initial set of nodes that meet the master condition to boot the clustercluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3"]
# The default value is 30 seconds. Increasing this value will reduce the brain split to a certain extent due to misjudgment..ping_timeout: 30s
# Configure the minimum number of master nodes in the cluster, usually (number of hosts that can become master nodes / 2) + 1.minimum_master_nodes: 2
# Disable swap memory to improve efficiencybootstrap.memory_lock: false

Officially run elasticsearch

docker run --name=elasticsearch-node-1 -p 9200:9200 -p 9300:9300 \
-e ES_JAVA_OPTS="-Xms4g -Xmx4g" \
-v /home/elasticsearch/config/:/usr/share/elasticsearch/config/ \
-v /home/elasticsearch/data:/usr/share/elasticsearch/data \
-v /home/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
--restart=always \
-d elasticsearch:7.16.3

3.2 Node 2

Revise/home/elasticsearch/config/Configuration File

# Cluster name All node names are the same: es-clusters
# The current name of the node, each node cannot repeat es-node-1, es-node-2, and es-node-3.: es-node-2
# Is this node currently eligible to run for the master node: true
# Whether the node currently stores data: true
# Set as public access: 0.0.0.0
# Set the IP address of the machine where other nodes interact with this node, each of the three nodes isnetwork.publish_host: 192.16.109.114
# Set the map port: 9200
# Communication port between internal nodes: 9300
# Support cross-domain access: true
-origin: "*"
# Configure the host address of the clusterdiscovery.seed_hosts: ["192.16.109.113","192.16.109.114","192.16.109.115"]
# Initial master node, use an initial set of nodes that meet the master condition to boot the clustercluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3"]
# The default value is 30 seconds. Increasing this value will reduce the brain split to a certain extent due to misjudgment..ping_timeout: 30s
# Configure the minimum number of master nodes in the cluster, usually (number of hosts that can become master nodes / 2) + 1.minimum_master_nodes: 2
# Disable swap memory to improve efficiencybootstrap.memory_lock: false

Officially run elasticsearch

docker run --name=elasticsearch-node-2 -p 9200:9200 -p 9300:9300 \
-e ES_JAVA_OPTS="-Xms4g -Xmx4g" \
-v /home/elasticsearch/config/:/usr/share/elasticsearch/config/ \
-v /home/elasticsearch/data:/usr/share/elasticsearch/data \
-v /home/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
--restart=always \
-d elasticsearch:7.16.3

3.3 Node Three

Revise/home/elasticsearch/config/Configuration File

# Cluster name All node names are the same: es-clusters
# The current name of the node, each node cannot repeat es-node-1, es-node-2, and es-node-3.: es-node-3
# Is this node currently eligible to run for the master node: true
# Whether the node currently stores data: true
# Set as public access: 0.0.0.0
# Set the IP address of the machine where other nodes interact with this node, each of the three nodes isnetwork.publish_host: 192.16.109.115
# Set the map port: 9200
# Communication port between internal nodes: 9300
# Support cross-domain access: true
-origin: "*"
# Configure the host address of the clusterdiscovery.seed_hosts: ["192.16.109.113","192.16.109.114","192.16.109.115"]
# Initial master node, use an initial set of nodes that meet the master condition to boot the clustercluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3"]
# The default value is 30 seconds. Increasing this value will reduce the brain split to a certain extent due to misjudgment..ping_timeout: 30s
# Configure the minimum number of master nodes in the cluster, usually (number of hosts that can become master nodes / 2) + 1.minimum_master_nodes: 2
# Disable swap memory to improve efficiencybootstrap.memory_lock: false

Officially run elasticsearch

docker run --name=elasticsearch-node-3 -p 9200:9200 -p 9300:9300 \
-e ES_JAVA_OPTS="-Xms4g -Xmx4g" \
-v /home/elasticsearch/config/:/usr/share/elasticsearch/config/ \
-v /home/elasticsearch/data:/usr/share/elasticsearch/data \
-v /home/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
--restart=always \
-d elasticsearch:7.16.3

3.4 Check whether the cluster is successful

Enter on the browserhttp://any node ip:9200/_cat/nodes?prettyCheck the cluster information and the following information appears means that the cluster has been successfully built.

192.16.109.113 20 99 1 0.03 0.04 0.06 cdfhilmrstw * es-node-3
192.16.109.114 12 99 3 0.03 0.05 0.06 cdfhilmrstw - es-node-1
192.16.109.114 56 89 2 0.19 0.12 0.13 cdfhilmrstw - es-node-2

4 Things to note

4.1 Run elasticsearch startup parameters

Note: We start the parameter setting-e ES_JAVA_OPTS="-Xms4g -Xmx4g", adjust according to the actual server memory.
● Xms is the maximum memory allocated for jvm startup
● Xmx The maximum memory allocated for the jvm running process

4.2 Modify the maximum number of virtual memory maps

The default maximum number of virtual memory maps in the system is 65530, which cannot meet the ES system requirements and needs to be adjusted to above 262144.
sudo vi /etc/

#Add parametersvm.max_map_count = 655360

Reload /etc/config

sysctl -p

4.3 Each node cannot form a cluster, each is a master solution

(1) Close all nodes, or delete containers directly
(2) Clear on three nodes/home/elasticsearch/dataNode data

cd /home/elasticsearch/data
rm -rf *

(3) Restart all nodes

5 Reference blog

1.Docker performs ElasticSearch cluster deployment
2.Elasticsearch cluster construction and each node cannot form a cluster, each is a master solution.

This is all about this article about the deployment of Docker Elasticsearch cluster. For more related content on Docker Elasticsearch cluster, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!