Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a new node to my Elasticsearch cluster

My cluster has a yellow health as it has only one single node, so the replicas remain unasigned simply because no other node is available to contain them.

So I want to create/add another node so Elasticsearch can begin allocating replica’s to it. I've only one machine and I'm running ES as a service.

I've found tons of site with some info but none of them is giving me clearly how can I add another node to ES.

Can someone explain me which files do I've to edit and what commands do I've to launch in order to create another node in my cluster? Do I've to run two ES instance? How can I do this?

Thanks in advance.

like image 458
Avión Avatar asked Mar 01 '16 08:03

Avión


People also ask

Which command is used to add a node to an existing cluster?

The Add-ClusterNode cmdlet adds a node, or server, to a failover cluster. Before adding the new node, you should run validation tests on the existing nodes together with the proposed new node. Before adding the new node, you should run validation tests on the existing nodes together with the proposed new node.

How many nodes should an Elasticsearch cluster have?

To start, we recommend a minimum of three nodes to avoid potential OpenSearch issues, such as split brain (when a lapse in communication leads to a cluster having two master nodes). If you have three dedicated master nodes, we still recommend a minimum of two data nodes for replication.


1 Answers

TIPS TO ADD ANOTHER NODE:

1) VERSIONS:

It is a good advise to check all of your nodes for the status: http://elastic-node1:9200/

Keep in mind that in most cases: VERSION NEED TO BE THE SAME, EVEN MINOR

{ "name" : "node2", "cluster_name" : "xxxxxxxxxxx", "cluster_uuid" : "n-xxxxxxxxxxxxxxx", "version" : {   "number" : "5.2.2",   "build_hash" : "xxxx",   "build_date" : "20-02-24T17:26:45.835Z",   "build_snapshot" : false,   "lucene_version" : "6.4.1" }, "tagline" : "You Know, for Search" } 

Keep in mind that if you see a different version number in node1, e.g.

  "number" : "5.2.1" 

you have to update your node in that case to version 5.2.2 (same as node1).

2) NODES AND REPLICA:

What is the usecase of the node? For 3 nodes I would do this:

curl -XPUT 'localhost:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d' {   "transient": {     "discovery.zen.minimum_master_nodes": 3   } } ' 

Even better is to change settings in Elasticsearch's configuration file:

/etc/elasticsearch/elasticsearch.yml   # need to be changed on each node (has to be unique for each node): node.name: node1  # need to be the same in all nodes: cluster.name: my_cluster discovery.zen.ping.unicast.hosts: ["IP_ADDRESS_OR_HOSTNAME1", "IP_ADDRESS_OR_HOSTNAME2", "IP_ADDRESS_OR_HOSTNAME3"] 

And if you have 3 nodes, do you want two replicas and one primary?

curl -XPUT 'localhost:9200/_settings?pretty' -H 'Content-Type: application/json' -d' {     "index" : {         "number_of_replicas" : 2     } }' 

3) MAKE SURE THAT NODES ARE ENABLED

There is a way to kick a node:

curl -XPUT localhost:9200/_cluster/settings -d '{   "transient" :{       "cluster.routing.allocation.exclude._ip" : "NODE_TO_REMOVE_IP_ADDRESS_OR_HOSTNAME"    } }';echo 

So if you did that, and now you want to add the node back: https://www.elastic.co/guide/en/elasticsearch/guide/current/_rolling_restarts.html

you can do that with following request (please read carefully mentioned link above):

curl -XPUT localhost:9200/_cluster/settings -d '{   "transient" :{         "cluster.routing.allocation.enable" : "all"    } }';echo 

4) NEVER FORGET, NETWORKING:

Firewall, network... Can you reach the new node at port 9200? Can you see it on your web browser?

Can you

curl http://your-elasticsearch-hostname:9200/ 

?

TIPS TO REMOVE NODE FROM CLUSTER:

1) REMOVE WITH API

curl -XPUT 'http://localhost:9200/_cluster/settings?pretty' -d ' {   "transient" : {     "cluster.routing.allocation.exclude._name" : "node3"   } }' 

2) CHECK YOUR CONFIG FILE

Check config file under: /etc/elasticsearch/elasticsearch.yml

and leave only the nodes you want to keep:

discovery.zen.ping.unicast.hosts:["IP_ADDRESS_OR_HOSTNAME1", "IP_ADDRESS_OR_HOSTNAME2"] 

* CHECK YOUR STATUS *

Check http://elk-pipeline:9200/_cat/shards What is your status? You may see: INITIALIZING That probably means that data is transferred. So if your data is large, (and not on SSD), wait.

DON'T FORGET

You can see if your data is currently moving by typing:

[watch] du /var/lib/elasticsearch/ 

That is all for now. I will try to add more information here from time to time.

Please feel free to change/add.

like image 114
Nimitack Avatar answered Oct 02 '22 15:10

Nimitack