ElasticSearch cluster with Docker
In previous posts I explained how-to create the Docker Cluster including the overlay network. Before we can start with the ElasticSearch Cluster it’s required to have the overlay network in place. Let’s get started with the ElasticSearch containers.
For this example we will use the following configuration:
- Docker-Host-Master with IP 192.168.0.1
- Docker-Host-02 with IP 192.168.0.2
- Network created in docker with overlay drivers and name “clusternetwork”.
- Network “clusternetwork” has subnet “192.168.20.0/24”.
Again you can read my previous post to make sure this is all set: https://www.solrac.nl/docker-cluster/
Run the first ElasticSearch nodes on Master host
We are gone start 2 Elastic nodes (containers) on an host, so we end up with 4 nodes over 2 hosts. When we want to start-up the ElasticSearch Docker containers which we name node1 and node2, run the following command on the master host:
docker run -d\ --name=elastic_node1 \ --net=clusternetwork \ --ip=192.168.20.2 \ -p 9200:9200 \ -p 9300:9300 \ elasticsearch \ --cluster.name=elastic_cluster1 \ --discovery.zen.ping.multicast.enabled=false \ --discovery.zen.ping.unicast.hosts=\ --discovery.zen.ping.timeout=3s \ --discovery.zen.minimum_master_nodes=1
Start ElasticSearch Node2:
docker run -d \ --name elastic_node2 \ --net=clusternetwork \ -p 9200:9200 \ -p 9300:9300 \ elasticsearch \ --cluster.name=elastic_cluster1 \ --discovery.zen.ping.multicast.enabled=false \ --discovery.zen.ping.unicast.hosts=192.168.20.2:9300 \ --discovery.zen.ping.timeout=3s \ --discovery.zen.minimum_master_nodes=1
ElasticSearch nodes on the second host
When node1 and node2 are running and connected we can start the nodes on the other hosts, in our example the second host. Use the following command to start ElasticSearch node3:
docker -H 192.168.0.2:2375 run -d \ --name elastic_node3 \ --net=clusternetwork \ -p 9200:9200 \ -p 9300:9300 \ elasticsearch \ --cluster.name=elastic_cluster1 \ --discovery.zen.ping.multicast.enabled=false \ --discovery.zen.ping.unicast.hosts=192.168.20.2:9300 \ --discovery.zen.ping.timeout=3s \ --discovery.zen.minimum_master_nodes=1
This command will start ElasticSearch Node 4:
docker -H 192.168.0.2:2375 run -d \ --name elastic_node4 \ --net=clusternetwork \ -p 9200:9200 \ -p 9300:9300 \ elasticsearch \ --cluster.name=elastic_cluster1 \ --discovery.zen.ping.multicast.enabled=false \ --discovery.zen.ping.unicast.hosts=192.168.20.2:9300 \ --discovery.zen.ping.timeout=3s \ --discovery.zen.minimum_master_nodes=1
Now all nodes are up and running we can check the ElasticSearch API if everything is healthy:
curl -XGET "http://192.168.20.2:9200/_nodes/stats"
If everything is set-up correctly you will find all nodes in the overview. The ElasticSearch Cluster is now up and running.