Friday, 20 October 2023

Elastic search create a new node in a cluster

To create a new node in an Elasticsearch cluster, you can follow these steps:

  1. Install Elasticsearch on the new node.
  2. Configure the new node to join the existing cluster.
  3. Start Elasticsearch on the new node.

1. Install Elasticsearch on the new node

To install Elasticsearch on the new node, you can download the latest version from the Elasticsearch website. Once you have downloaded the installation package, you can follow the instructions in the installation guide to install Elasticsearch.

2. Configure the new node to join the existing cluster

To configure the new node to join the existing cluster, you need to edit the elasticsearch.yml file on the new node. In the elasticsearch.yml file, set the following properties:

  • cluster.name: The name of the Elasticsearch cluster.
  • discovery.seed_hosts: A list of the IP addresses and ports of the existing nodes in the cluster.

For example, if the existing cluster has two nodes with the IP addresses 192.168.1.100 and 192.168.1.101, you would set the discovery.seed_hosts property to the following value:

discovery.seed_hosts: ["192.168.1.100:9200", "192.168.1.101:9200"]

3. Start Elasticsearch on the new node

Once you have configured the new node, you can start Elasticsearch by running the following command:

elasticsearch

This will start Elasticsearch on the new node and it will automatically join the existing cluster.

Once the new node has joined the cluster, you can verify that it is connected by running the following command:

curl -XGET 'http://localhost:9200/_cat/nodes'

This will return a list of all the nodes in the cluster, including the new node.

Additional tips

  • If you are using a cloud-based Elasticsearch service, such as Amazon Elasticsearch Service (AES) or Elasticsearch Service on Google Cloud Platform (GCP), you can usually add new nodes to your cluster using the management console for the service.
  • If you are adding a new node to a cluster that is running in production, it is a good practice to do so during a maintenance window. This will help to minimize any disruption to your users.
  • Once you have added a new node to your cluster, you should monitor the cluster to ensure that the new node is healthy and that it is performing well.

Elastic search list all the nodes in a cluster

There are two ways to list all the nodes in an Elasticsearch cluster:

  1. Using the _cat/nodes API:

This API is intended for human consumption using the command line or Kibana console. To use it, you can run the following command:

curl -XGET 'http://localhost:9200/_cat/nodes'

This will return a list of all the nodes in the cluster, along with information such as their IP address, role, and status.

  1. Using the nodes info API:

This API is intended for application consumption. To use it, you can run the following command:

curl -XGET 'http://localhost:9200/_nodes/info'

This will return a more detailed list of all the nodes in the cluster, including information such as their configuration, JVM information, and operating system information.

You can also use the nodes info API to list specific nodes in the cluster by passing their IDs to the API. For example, to list the nodes with the IDs node-1 and node-2, you can run the following command:

curl -XGET 'http://localhost:9200/_nodes/info/node-1,node-2'

Whichever method you choose, you can use the output of the API to get a better understanding of the nodes in your Elasticsearch cluster. This information can be useful for troubleshooting problems, monitoring performance, and scaling your cluster.