Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Multi-Node Deployment in Elasticsearch

Introduction

Elasticsearch is a powerful search and analytics engine that can be deployed in various configurations. One of the most robust and scalable configurations is a multi-node deployment. In this tutorial, we will guide you through the process of setting up a multi-node Elasticsearch cluster from start to finish.

Prerequisites

Before we begin, ensure you have the following:

  • At least two machines (physical or virtual) with Elasticsearch installed.
  • A network configuration that allows these machines to communicate with each other.
  • Basic knowledge of Linux command-line operations.

Step 1: Install Elasticsearch

First, install Elasticsearch on each node. You can download the latest version from the official Elasticsearch website.

Run the following command to download and install Elasticsearch on each node:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.2-linux-x86_64.tar.gz
tar -xvf elasticsearch-7.10.2-linux-x86_64.tar.gz
cd elasticsearch-7.10.2/

Step 2: Configure Elasticsearch

Next, configure the Elasticsearch settings to enable clustering. Open the elasticsearch.yml file located in the config directory of your Elasticsearch installation:

Edit the following settings in elasticsearch.yml:

network.host: 0.0.0.0
cluster.name: my-cluster
node.name: node-1
discovery.seed_hosts: ["node-1-ip", "node-2-ip"]
cluster.initial_master_nodes: ["node-1", "node-2"]

Repeat this configuration on each node, adjusting the node.name and discovery.seed_hosts as necessary.

Step 3: Start Elasticsearch

Start the Elasticsearch service on each node. Use the following command:

./bin/elasticsearch

Ensure Elasticsearch is running without errors on each node.

Step 4: Verify the Cluster

Once Elasticsearch is running on all nodes, verify that the cluster has been formed. Use the following command to check the health of the cluster:

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

You should see output similar to the following:

{
  "cluster_name" : "my-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 1,
  "active_shards" : 2,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

Step 5: Adding More Nodes

To add more nodes to the cluster, repeat the configuration steps for each new node, ensuring they are properly listed in the discovery.seed_hosts and cluster.initial_master_nodes settings.

Conclusion

Congratulations! You have successfully set up a multi-node Elasticsearch cluster. This setup provides high availability and scalability, allowing you to handle larger datasets and higher query loads. Continue to monitor and manage your cluster to ensure optimal performance.