This Wiki demonstrates how to start a multinode elasticsearch cluster with docker from multiple hosts (servers).
For a smooth setup, please ensure your servers are configured as per elasticsearch instructions.
- At least 2 (publicly) accessible servers.
- Docker installation on all the servers.
In this setup, we'll assume we would like to set up a 2-node cluster.
cat >/path/to/.env <<EOF
cluster.name=cluster-name
node.name=node1
http.host=0.0.0.0
transport.host=0.0.0.0
network.host=node1.elasticsearch.net
cluster.initial_master_nodes=node1
# comma-separate as many as needed...
discovery.seed_hosts=node2.elasticsearch.net
EOF
To start the container, we'll need a couple of things in place:
- Path to the
.env
file created earlier. --network
option set tohost
. This is important because without it, we will not be able to enroll other nodes in the cluster.
docker run --name elastic \
--network host \
--detach \
--memory 1GB \
--restart unless-stopped \
--ulimit memlock=-1:-1 \
--log-driver local \
--volume elastic-data:/usr/share/elasticsearch/data \
--volume elastic-config:/usr/share/elasticsearch/config \
--env-file /path/to/.env \
docker.elastic.co/elasticsearch/elasticsearch:8.7.1
N/B: Feel free to add as many docker run options as necessary.
The value set here will be necessary in the following step - checking cluster is running.
$ docker exec -it elastic /usr/share/elasticsearch/bin/elasticsearch-reset-password -i -u elastic
$ curl -ku elastic: <replace-with-new-password >https://node1.elasticsearch.net:9200/_cat/nodes
N/B: The curl command above disables certificate verification since we are using elasticsearch's self-signed certs.
You should see something along the following lines if everything worked out.
<IP-address> 65 93 0 0.00 0.00 0.00 cdfhilmrstw * node1
This will be used by nodes from other hosts/servers to join the cluster.
$ docker exec -it elastic /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token --scope node
N/B: Ensure the token is used within 30 minutes, since it is likely to expire after that.
cat >/path/to/.env <<EOF
ENROLLMENT_TOKEN=<TODO: Replace with value from enrollment token created in server/host 1>
cluster.name=cluster-name
node.name=node2
http.host=0.0.0.0
transport.host=0.0.0.0
network.host=node2.elasticsearch.net
# comma-separate as many as needed...
#discovery.seed_hosts=node1.elasticsearch.net
EOF
N/B: discovery.seed_hosts
is commented out for now. We'll need it afterwards to allow the node to rejoin the
cluster.
To start the container, we'll need a couple of things in place:
- Path to the
.env
file created earlier. --network
option set tohost
. This is important because without it, we will not be able to enroll other nodes in the cluster.
docker run --name elastic \
--network host \
--detach \
--memory 1GB \
--restart unless-stopped \
--ulimit memlock=-1:-1 \
--log-driver local \
--volume elastic-data:/usr/share/elasticsearch/data \
--volume elastic-config:/usr/share/elasticsearch/config \
--env-file /path/to/.env \
docker.elastic.co/elasticsearch/elasticsearch:8.7.1
N/B: Feel free to add as many docker run options as necessary.
$ curl -ku elastic:<replace-with-new-password-from-server-1> https://node2.elasticsearch.net:9200/_cat/nodes
N/B: The curl command above disables certificate verification since we are using elasticsearch's self-signed certs.
You should see something along the following lines if everything worked out.
<IP-address> 65 93 0 0.00 0.00 0.00 cdfhilmrstw * node1
<IP-address> 65 93 0 0.00 0.00 0.00 cdfhilmrstw - node2
Do the following to allow the node to automatically rejoin the cluster after a restart.
$ docker stop elastic
$ docker rm elastic
- Remove
ENROLLMENT_TOKEN
. Unless you've pruned your docker volume for some reason, it is no longer necessary since the node is already registered with the cluster. - Uncomment,
discovery.seed_hosts
, to allow the node to automatically rejoin the cluster after termination.
The updated .env
file should look as follows
cat >/path/to/.env <<EOF
cluster.name=cluster-name
node.name=node2
http.host=0.0.0.0
transport.host=0.0.0.0
network.host=node2.elasticsearch.net
# comma-separate as many as needed...
discovery.seed_hosts=node1.elasticsearch.net
EOF
Refer to Start docker container for host/server 2.