且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将新节点添加到我的Elasticsearch集群

更新时间:2023-01-26 14:18:45

要添加另一个节点的提示:



1)版本:

建议检查所有节点的状态:
http:// elastic -node1:9200 /

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"
}

请记住,如果您在node1,例如

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

  "number" : "5.2.1"

在这种情况下,您必须将节点更新到版本5.2.2(与node1相同)。

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

2)节点和副本:

节点的用例是什么?对于3个节点,我可以这样做:

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
  }
}
'

更好的是更改Elasticsearch配置文件中的设置:

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"]

如果有3个节点,请执行您想要两个副本和一个主副本?

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)确保结点启用

有一种踢节点的方法:

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

因此,如果您这样做了,现在您想添加节点后方:
https://www.elastic。 co / guide / en / elasticsearch / guide / current / _rolling_restarts.html

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)永不F ORGET,网络:

防火墙,网络...您能否到达端口9200处的新节点?
您可以在网络浏览器中看到它吗?

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

可以

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

1)使用API​​删除

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

2)检查您的配置文件

检查配置文件位于:
/etc/elasticsearch/elasticsearch.yml

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"]

*检查您的状态*

选中 http:// elk-pipeline:9200 / _cat / shards
您的状态如何?您可能会看到:初始化
这可能意味着已传输数据。因此,如果您的数据很大(并且不在SSD上),请等待。

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.

不要忘记

您可以通过键入以下内容查看数据是否正在移动:

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.

请随时更改/添加。