2013-04-26 35 views
8

节点重启后快速恢复的elasticsearch.yml考虑下面设置在elasticsearch

gateway.recover_after_data_nodes: 3 
gateway.recover_after_time: 5m 
gateway.expected_data_nodes: 3 

当前设置: 说,我有3个数据节点。现在,如果我决定重新启动数据节点(由于设置稍有更改),恢复将在节点重新启动后立即开始,具体情况与expected_data_nodes设置相同。将会有许多未分配的分片,根据其包含的数据将缓慢分配。

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

我主要是想避免从黄色变为绿色集群状态的重timelag。(这是在几个小时在我的案件的范围内)

我可以使用集群重新路由API用于此目的?

或者是否有任何其他api将所有未分配的碎片一次传输到特定节点?

回答

26

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

碎片保持未分配的直到 “cluster.routing.allocation.disable_allocation” :false,然后在刚刚重新启动的服务器上恢复碎片(从关机前的大小开始) 这很快。

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

+0

因为这是一个“短暂”的设置,它只是恢复到重新启动时的永久设置。所以你可能不需要第二部分。此外,您可能需要查看cluster.routing.allocation.disable_replica_allocation – joeslice 2013-10-23 02:36:31

+2

@joeslice 1.由于群集中有多个节点,瞬态设置在节点重新启动后仍然保留。 2.'disable_allocation'意味着'disable_replica_allocation',所以不需要设置两者。 – itsadok 2014-04-24 15:22:56

+0

@itsadok感谢您的补充。 – 2014-05-19 07:35:05