Installing an Elasticsearch Cluster with 2 Nodes


Download the latest version of Elasticsearch from here and unpack it to /opt:

cd /opt
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.4.tar.gz
tar -xvpf elasticsearch-1.3.4.tar.gz
ln -s elasticsearch-1.3.4 elasticsearch

Given you want to create a cluster named my-ecs-cluster, having 2 nodes with IP address 192.168.45.21 and 192.168.45.21 (change it according to your setup, you might also want to use hostnames instead of IPs)

Then edit /opt/elasticsearch/config/elasticsearch.yml on the first node, changing/uncommenting the following lines:

cluster.name: my-ecs-cluster
node.master: true
node.data: true
index.number_of_shards: 2
index.number_of_replicas: 1
network.bind_host: 192.168.45.21
network.publish_host: 192.168.45.21
network.host: 192.168.45.21
transport.tcp.port: 9300
http.port: 9200
discovery.zen.ping.timeout: 3s
discovery.zen.ping.unicast.hosts: ["192.168.45.21", "192.168.45.22"]

On the second node the changes are almost the same, the only difference:

network.bind_host: 192.168.45.22
network.publish_host: 192.168.45.22
network.host: 192.168.45.22

To start the service on the 2 nodes you can do it just as follows:

export ES_JAVA_OPTS="-Duser.timezone=GMT"
export JAVA_OPTS="-Duser.timezone=GMT"
ulimit -l unlimited
export ES_MIN_MEM="2048m"
export ES_MAX_MEM="4096m"
cd /opt/elasticsearch
nohup /opt/elasticsearch/bin/elasticsearch > /dev/null 2>&1 &

Please adjust the proper timezone and values ES_MIN_MEM/ES_MIN_MAX to fit your server's RAM, else the java process might not want to start up if values are too high.

Checking if everyhting is running:

When everything as started, calling http://192.168.45.21:9200/_cluster/health?pretty=true should output something like this:

{
  "cluster_name" : "my-ecs-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 2,
  "active_shards" : 2,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0
}