2013-04-26 30 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