How To Setup Elasticsearch Cluster On AWS EC2 Instances

  • Sun Jan 12 2020
  • Sibtay Shah

1. Provision EC2 Instances

  • Select an appropiate instance type. I selected t2.large for the tutorial however NOTE that this is not a good instance type for product elasticsearch cluster
  • Edit instance details
  • Enter 2 as number of instances (or however many nodes you would like in your cluster)
  • Create a new key pair or select use existing key pair if you already have one

2. Login To Node 1

ssh -i ec2-user@ec2-52-90-10-56.compute-1.amazonaws.com

3. Install Elasticsearch

    sudo rpm -i https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-x86_64.rpm

4. Enable Elasticsearch service

    sudo systemctl daemon-reload
    sudo systemctl enable elasticsearch.service

5. Edit JVM Options

  • Edit /etc/elasticsearch/jvm.options
  • Set ms and mx options to 4g each:
    -Xms4g
    -Xmx4g

6. Edit Elasticsearch Cluster And Node settings

Edit /etc/elasticsearch/elasticsearch.yml

    cluster.name: demo-cluster
    node.name: demo-node-1
    network.host: <node-1-private-ip>
    discovery.seed_hosts: ["<node-1-private-ip>", "<node-2-private-ip>"]
    cluster.initial_master_nodes: ["<node-1-private-ip>"]
    node.master: true

7. Repeat Steps 2 - 6 For Node 2

In the video above is I set "node.master: false" for Node 2. But you can make Node 2 as master as well

8. Start Elasticsearch On Both Nodes

Go to the terminal of each node and run the following command

    sudo systemctl start elasticsearch.service

9. Verify Cluster Is Up

Running the following command to verify that the cluster is up and is composed of two nodes

    curl -X GET http://<node-1-ip>:9200/_cluster/health?pretty

You should also get the same results with node-2-ip as well