Elasticsearch對shard分配定製
Elasticsearch會自動的控制shard在各個節點的分配,同時也提供了配置方法,允許使用者根據自己的特定需求對shard的分配策略進行一定的定製。其中,
- 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也提供了專門的
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"
}
}
]
}