在elasticsearch中重新启动节点后快速恢复

时间:2013-04-26 08:08:01

标签: elasticsearch

考虑elasticsearch.yml

中的以下设置
gateway.recover_after_data_nodes: 3
gateway.recover_after_time: 5m
gateway.expected_data_nodes: 3

当前设置: 说,我有3个数据节点。现在,如果我决定重新启动数据节点(由于设置的微小变化),恢复将在节点重启后立即按照expected_data_nodes设置启动。将有许多未分配的分片,它们将根据其包含的数据缓慢分配。

为了避免这种情况,有没有办法将所有未分配的分片分配给特定节点?(在我的情况下是重新启动的节点),一旦完成,ES应该接管重新平衡。

主要是我想避免群集状态的重时间从黄色到绿色(在我的情况下,它在几小时的范围内)

我可以为此目的使用群集重路由API吗?

还是有其他api可以一次性将所有未分配的分片传输到特定节点吗?

1 个答案:

答案 0 :(得分:28)

对于Elasticsearch版本> = 1.0.0:

curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.enable": "none"}}'
/etc/init.d/elasticsearch restart
curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.enable": "all"}}'

对于早期版本的ES:

curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.disable_allocation": true}}'
/etc/init.d/elasticsearch restart
curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.disable_allocation": false}}'

Shard保持未分配状态,直到" cluster.routing.allocation.disable_allocation":false,然后在刚重启的服务器上进行分片恢复(从关闭前的大小开始) 这很快。

参考:http://elasticsearch-users.115913.n3.nabble.com/quick-recovery-after-node-restart-in-elasticsearch-td4033876.html#a4034211