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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)