ES扩容后需要考虑各索引的分片(shard)的均衡分布问题,简单记录下自己在扩容后采取的步骤:
1. es支持手动迁移索引分片(index shards),但需提前关闭自动的shard allocation(防止手动的shard迁移和自动的shard迁移相互干扰);
curl -XPUT "http://192.168.12.112:9200/_cluster/settings" -d '{"transient":{"cluster.routing.allocation.disable_allocation": true}}'
2. 将旧机器的索引分片迁移至新机器,命令样例如下:
- curl -XPOST '192.168.12.112:9200/_cluster/reroute' -d '{
- "commands" : [ {
- "move" :
- {
- "index" : "test", "shard" : 2,
- "from_node" : "node1", "to_node" : "node2"
- }
- }
- ]
- }'
3. 重启集群,注意可能出现的ES脑裂问题,可参考我之前的一篇文章: 如何尽量避免Elasticsearch脑裂问题
4. 打开自动shard allocation开关;
curl -XPUT "http://192.168.12.112:9200/_cluster/settings" -d '{"transient":{"cluster.routing.allocation.disable_allocation": false}}'
本文详细介绍了在Elasticsearch扩容过程中如何手动迁移索引分片以保持集群平衡。首先,通过设置禁用自动shard分配,然后使用特定命令将旧机器上的索引分片迁移到新节点。接着,在重启集群时需警惕可能的脑裂问题,并在一切正常后重新启用shard分配。
3762

被折叠的 条评论
为什么被折叠?



