且构网

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

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

更新时间:2022-06-11 06:17: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) 确保节点已启用

有一种方法可以踢一个节点:

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

所以如果你这样做了,现在你想重新添加节点: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) 永远不要忘记,网络:

防火墙、网络……你能在 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.

请随时更改/添加.