Elasticsearch对shard分配定制

       Elasticsearch会自动的控制shard在各个节点的分配,同时也提供了配置方法,允许用户根据自己的特定需求对shard的分配策略进行一定的定制。其中,index-modules-allocation 介绍了如下几种在索引级别(index-level)的配置:

  • shard allocation filtering (index-/cluster-level)
  • total shard per node
  • disk-based shard allocation

例如, Elasticsearch也可以通过allocation.exclude/include设置来指定索引的shard不可以分配到哪些节点上/只能分配到哪些节点上。其中,'AvailabilitySet'是在.yml文件中定义的, 如:node.AvailabilitySet: "master":


PUT /*/_settings
{
   "index.routing.allocation.exclude.AvailabilitySet" : "data-events"
}


PUT /*/_settings
{
   "index.routing.allocation.include.AvailabilitySet" : "data-events"
}


同时, 在cluster shards allocation 中介绍了集群级别(cluster-level)的基于shard allocation awareness的分配配置。除了自动分配策略定制决定shard分配外,Elasticsearch也提供了专门的 reroute API 用于手工进行shard的移动、分配以及取消指令, 例如 :


POST /_cluster/reroute
{
  "commands": [
    {
      "move": {
        "index": "logindex",
        "shard": 0,
        "from_node": "ES5-001-data",
        "to_node": "ES6-03-data"
      }
    }
  ]
}


POST /_cluster/reroute
{
   "commands": [
     {
       "allocate": {
         "index": "logindex", "shard": 0, "node": "ES5-001-data"
       }
     }
   ]
}














你可能感兴趣的:(Elasticsearch对shard分配定制)