随着集群规模越来越大,有一些冷索引不需要经常移动分片,因此把冷索引单独存储在冷节点中,把热索引(最新添加的数据)存储在热节点中。
第一步 禁用rebalance
主要是为了防止集群中已有的索引 rebalance 到其他节点
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.cluster_concurrent_rebalance":0
}
}
第二步:给节点加标识:node.attr.box_type
关于 node.attr.box_type 属性介绍,可参考:enabling-awareness
修改hot节点的elasticsearch.yml配置文件,添加一行:
node.attr.box_type: hot
修改warm节点的elasticsearch.yml配置文件,添加一行:
node.attr.box_type: warm
第三步:定义通用的索引模板保证新创建索引的分片不会分配到warm节点上
当每月生成一个索引时,新建的索引,肯定是热索引,热索引的分片需要分配到hot节点上,不能分配到warm节点上。比如,loginmac-201908是新建的索引,其分配应该在hot节点上,假设只保留三个月的数据,那么 loginmac-201905就属于历史数据了,需要迁移到warm节点上去。
PUT /_template/hot_template
{
"template": "*",
"order": 0,
"version": 0,
"settings": {
"index": {
"routing": {
"allocation": {
"require": {
"box_type": "hot"
},
"exclude":{
"box_type": "warm"
}
}
},
"number_of_shards": 3,
"number_of_replicas": 1,
"refresh_interval": "50s"
},
"index.unassigned.node_left.delayed_timeout": "3d"
}
}
关于index.routing.allocation.require和index.routing.allocation.exclude可参考:shard-allocation-filtering
第四步 把系统上已有索引的配置全部修改成hot配置
PUT _all/_settings
{
"index": {
"routing": {
"allocation": {
"require": {
"box_type": "hot"
}
}
}
}
}
这是为了,保证当warm节点加入集群时,不要让热索引迁移到到warm节点上。
修改完重启es节点。