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