Big Data 12 min read

Step-by-Step Guide to Deploy a Multi-Node Elasticsearch Cluster with Docker

This article provides a comprehensive tutorial on pulling Elasticsearch Docker images, configuring data directories, creating cluster configuration files, adjusting JVM settings, launching three Elasticsearch nodes in Docker containers, and verifying the cluster using both the REST API and the elasticsearch‑head UI.

Architecture Digest
Architecture Digest
Architecture Digest
Step-by-Step Guide to Deploy a Multi-Node Elasticsearch Cluster with Docker

Before starting, the article explains why Elasticsearch is chosen as a full‑text search engine: it offers fast storage, search, and analysis of massive data, provides a RESTful API, and ensures data safety through sharding and automatic resharding.

1. Pull Elasticsearch Image

Run the following command on a CentOS terminal to download version 5.6.8: docker pull elasticsearch:5.6.8<br/> The image metadata is displayed, showing version 5.6.8 and Lucene 6.6.1.

2. Create Data Directories and Open Ports

Execute these commands to create three data directories and open the required ports (9300‑9302):

[root@localhost soft]# pwd<br/>/home/soft<br/>[root@localhost soft]# mkdir -p ES/config<br/>[root@localhost soft]# cd ES<br/>[root@localhost ES]# mkdir data1 data2 data3<br/>[root@localhost ES]# cd ES/config/<br/>[root@localhost ES]# firewall-cmd --add-port=9300/tcp<br/>success<br/>[root@localhost ES]# firewall-cmd --add-port=9301/tcp<br/>success<br/>[root@localhost ES]# firewall-cmd --add-port=9302/tcp<br/>success<br/>

Note: For ELK 6.x, set 777 permissions on the data directories.

3. Create Elasticsearch Configuration Files

Use vim to create es1.yml, es2.yml, and es3.yml with the following contents (replace the IP address with your own):

cluster.name: elasticsearch-cluster<br/>node.name: es-node1<br/>network.bind_host: 0.0.0.0<br/>network.publish_host: 192.168.9.219<br/>http.port: 9200<br/>transport.tcp.port: 9300<br/>http.cors.enabled: true<br/>http.cors.allow-origin: "*"<br/>node.master: true<br/>node.data: true<br/>discovery.zen.ping.unicast.hosts: ["192.168.9.219:9300","192.168.9.219:9301","192.168.9.219:9302"]<br/>discovery.zen.minimum_master_nodes: 2<br/>

Repeat the same structure for es2.yml (changing node.name, http.port, and transport.tcp.port to 9201/9301) and es3.yml (using 9202/9302).

4. Increase JVM Thread Limits

Edit /etc/sysctl.conf and add: vm.max_map_count=262144<br/> Apply the change with: sysctl -p<br/> This prevents the "bootstrap checks failed max virtual memory areas" error when starting containers.

5. Start Elasticsearch Cluster Containers

Run the following Docker commands to start three nodes, each with its own configuration and data directory:

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /home/soft/ES/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/soft/ES/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch:5.6.8<br/>docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /home/soft/ES/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/soft/ES/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch:5.6.8<br/>docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202 -p 9302:9302 -v /home/soft/ES/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/soft/ES/data3:/usr/share/elasticsearch/data --name ES03 elasticsearch:5.6.8<br/>

The -e ES_JAVA_OPTS flag limits JVM heap to 256 MB, avoiding the default 2 GB allocation.

6. Verify Cluster Deployment

Open a browser and visit: http://192.168.9.219:9200/_cat/nodes?pretty to see node statuses (the master node is marked with an asterisk).

Alternatively, pull and run the elasticsearch-head UI:

docker pull mobz/elasticsearch-head:5<br/>docker run -d -p 9100:9100 --name es-manager mobz/elasticsearch-head:5<br/>

Then open http://192.168.9.219:9100/ in a browser.

7. Index Shard and Replica Settings

Adjust default shard and replica numbers with a curl request (example sets 10 shards and 1 replica):

curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{"index.number_of_shards":"10","index.number_of_replicas":"1"}'<br/>

Appendix

Additional useful commands:

View container memory usage: docker stats $(docker ps --format={{.Names}}) View container logs: docker logs <em>container_name_or_id</em> Key configuration parameters explained (cluster.name, node.name, network.host, http.port, discovery.zen.minimum_master_nodes, etc.).

The article concludes with recommendations on shard/replica tuning and notes on newer Elasticsearch versions where some settings are applied after the cluster starts.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerElasticsearchConfigurationSearch
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.