PUT _cluster/settings
{
"transient": {
"cluster.routing.rebalance.enable":"none"
}
}
结果:
{
"acknowledged": true,
"persistent": {},
"transient": {
"cluster": {
"routing": {
"rebalance": {
"enable": "none"
}
}
}
}
}
此时,索引的变更不再会导致分片在节点中的迁移。
如果需要更合理的管理es集群,建议将集群reblance关闭,完全手动管理,这样效率会更高,但是需要更加复杂的脚本配合。
vim /etc/security/limits.conf
增加如下内容:
elastic soft memlock unlimited
elastic hard memlock unlimited
elastic soft nofile 655350
elastic hard nofile 655350
elastic soft nproc 655350
elastic soft nproc 655350
vim /etc/sysctl.conf
增加
vm.max_map_count = 262144
sysctl -p
创建用户
useradd elasticsearch -d /opt/elasticsearch
修改hosts文件,确保本机hostname在 hosts文件中有描述
切换到elastic用户
unzip elasticsearch-5.0.1.zip
mv ./elasticsearch-5.0.1 ./elasticsearch-node5-1
ln -s /opt/elasticsearch/elasticsearch-node5-1 /opt/elasticsearch/node5-1
修改 /opt/elasticsearch/node5/config 下的jvm.options
将内存改为20G
-Xms20g
-Xmx20g
安装xpack
./bin/elasticsearch-plugin install file:///opt/elasticsearch/x-pack-5.0.1.zip
增加node,group配置
修改
elasticsearch.yml
cluster.routing.allocation.awareness.attributes: rack
node.attr.rack: r3
这样可以避免统一索引的分片备份到相同节点
启动节点:
/opt/elasticsearch/node5-1/bin/elasticsearch -d
采用如下命令即可
POST _cluster/reroute
{
"commands":[
{
"move" : {
"index" : "activemq-2017.11.01", "shard" : 2,
"from_node" : "node4-3", "to_node" : "node5-1"
}
},
{
"move" : {
"index" : "activemq-2017.11.01", "shard" : 3,
"from_node" : "node4-3", "to_node" : "node5-1"
}
},
{
"move" : {
"index" : "activemq-2017.11.01", "shard" : 4,
"from_node" : "node4-3", "to_node" : "node5-1"
}
}
]
}
重复上述操作,将需要迁移的节点上的shard全部迁移到新节点,之后关闭节点,并重新打开自动平衡即可。