分片分配过滤

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/index-modules-allocation.html

译文链接 : 分片分配过滤

贡献者 : @苏涛,ApacheCNApache中文网

分片分配过滤

分片分配过滤允许您指定哪些节点托管特定索引的分片。

注意

以下解释的每个索引分片分配过滤器与Cluster Level Shard Allocation中介绍的群集范围分配过滤器同时生效。

可以在启动时为每个节点分配任意的metadata (元数据)属性。例如,节点可以按如下方式标记一个rack 属性和一个size属性:

  1. bin/elasticsearch -Enode.attr.rack=rack1 -Enode.attr.size=big #1

| 1 | 这些属性设置也可以在elasticsearch.yml配置文件中指定 |

这些metadata(元数据)属性可以与index.routing.allocation* 设置一起使用,以将索引分配给特定的节点组。例如,我们可以按如下所示将索引test移动到被标记为big或者medium的节点上:

  1. PUT test/_settings
  2. {
  3. "index.routing.allocation.include.size": "big,medium"
  4. }

或者,我们可以使用排除规则将索引test从标记为small的节点中移出:

  1. PUT test/_settings
  2. {
  3. "index.routing.allocation.exclude.size": "small"
  4. }

可以指定多个规则,在这种情况下必须满足所有条件。例如,我们可以将索引test移到rack1中的big节点上,具体如下:

  1. PUT test/_settings
  2. {
  3. "index.routing.allocation.include.size": "big",
  4. "index.routing.allocation.include.rack": "rack1"
  5. }

注意

如果某些条件不能满足,则分片将不会被移动。

以下设置是动态的,允许活动索引从一组节点移动到另一组节点:

index.routing.allocation.include.{attribute}

  1. 分配索引到一个节点,节点的{attribute}至少满足一个逗号分隔的值。

index.routing.allocation.require.{attribute}

  1. 分配索引到一个节点,节点的{attribute}满足所有逗号分隔的值。

index.routing.allocation.exclude.{attribute}

  1. 分配索引到一个节点,节点的{attribute}不满足任何逗号分隔的值。

还支持这些特殊的属性:

_name 通过节点名匹配节点

_host_ip 通过主机IP地址(与主机名关联的IP)匹配节点

_publish_ip 通过publish(发布)IP地址匹配节点

_ip 通过_host_ip或_publish_ip进行匹配

_host 通过主机名匹配节点

可以使用通配符指定所有属性值,例如:

  1. PUT test/_settings
  2. {
  3. "index.routing.allocation.include._ip": "192.168.2.*"
  4. }