elasticsearch分片机架感知(Shard allocation awareness)

介绍

1
You can use custom node attributes as awareness attributes to enable Elasticsearch to take your physical hardware configuration into account when allocating shards. <br>If Elasticsearch knows which nodes are on the same physical server, in the same rack, or in the same zone, <br>it can distribute the primary shard and its replica shards to minimise the risk of losing all shard copies in the event of a failure.

按官网介绍,Shard allocation awareness是es提高高可用的技术,通过配置节点的属性,让分片的分配把硬件也考虑进来。你可以配置节点所处的服务器、机架和地区,分布主备分片在不同区域,令分片不可用的风险降至最低。

启用配置

启动的时候给节点配置节点自定义属性loc

bin/elasticsearch -E node.name=node0 -E cluster.name=joker -E node.attr.loc=china
bin/elasticsearch -E node.name=node1 -E cluster.name=joker -E node.attr.loc=china
bin/elasticsearch -E node.name=node2 -E cluster.name=joker -E node.attr.loc=USA

发起集群强制分片感知

复制代码
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.awareness.attributes": "loc",
    "cluster.routing.allocation.awareness.force.zone.values": [
      "china",
      "USA"
    ]
  }
}
复制代码

发起索引分片分配

PUT test/_settings
{
  "index.routing.allocation.include.loc": "china" }

 

 

查看节点分片数据,可以看到主副分片都不会同时分布在同一个区域的节点

GET /_cat/shards

 

posted @   哪都通临时工  阅读(1272)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示