作者介绍
许睿哲
2020年12月加入去哪儿网-数据平台团队,目前主要负责公司的 esaas 云服务与实时日志 ELK 平台的开发、维护与优化。主导参与了公司的es平台的SLA规则的制定与开发、 ES 架构升级迁移与jinkela集群拆分等工作。
· Data Node
· Coordinate Node
· Master Node
· Kibana
· Service
a. 手动迁移节点 b. 调参保证稳定性 c. 整理问题,确立后续工作侧重点
PUT _cluster/settings
{
"transient" :{
"cluster.routing.allocation.exclude._name" : "data1_node1,data2_node1,data1_node2,data2_node2,data1_node3,data2_node3,data1_node4,data2_node4,data1_node5,data2_node5"
}
}
Tips: 迁移节点数据最直接的方法就是官方提供的exclude操作,这个操作是集群级的,可以直接通过"_cluster/settings"进行修改,执行操作后,集群会将匹配到的节点的分片reroute(同步)到其他节点上。通过exclude分为以下三种操作: · exclude._name:将匹配的node名称对应的节点数据迁移,多个node名称逗号分割
· exclude._ip:将匹配的node的ip对应的节点数据迁移,多个ip用逗号分割
· exclude._host:将匹配的node的主机名对应的节点数据迁移,多个host用逗号分割
a.添加 exclude_name 后,集群多了很多 relocating shards,此时会出现大量的分片迁移操作,通过_cat/recovery 可以看到期间的分片进行的过程。 b.白天集群是写入高峰,压力不算小,此时还需要同步数据,会造成 exclude name 对应的节点,因为要大量的迁出数据,会进行大量的磁盘读操作,同时,还有很多分片还在进行当前的写入操作,磁盘 io 很容易趋近于100%(使用的是机械盘)。 c.迁入分片的节点也因为读取量的飙升,导致了磁盘的 io 上涨。继而影响同步两侧的节点纷纷 load 飙高,影响的就是会有个别的 appcode 写入堆积。
index.routing.allocation.total_shards_per_node:设置单个索引在单个节点上最多的分片数(包括主副本)。默认无限量
total_shards_per_node: shard_num/(nodes_count * 0.95(buffer系数) * 0.5)
{
"order": 99,
"index_patterns": [
"log_appcode-*"
],
"settings": {
"index": {
"number_of_shards": "278",
"routing": {
"allocation": {
"total_shards_per_node": "2"
}
},
"refresh_interval": "60s"
}
},
"mappings": {
"properties": {
#索引独立的结构
}
}
}
注:上面这个template 模板设定的索引分片单个节点最多分配两个分片。
index.unassigned.node_left.delayed_timeout : 节点脱离集群后多久分配unassigned shards(默认1min),相当于延迟恢复分配多久的时间。
1.INIT:刚开始恢复的阶段 2.INDEX:恢复Lucene文件 3.VERIFY_INDEX:验证Lucene index中是否有分片损坏 4.TRANSLOG:重放Translog,同步数据 5.FINALIZE:执行refresh操作 6.DONE:更新分片状态,完成操作
delayed_timeout = random.randint(100, 300)
PUT /index/_settings
{
"settings": {
"index.unassigned.node_left.delayed_timeout": delayed_timeout
}
}
PUT _cluster/settings
{
"transient" :{
"cluster.routing.allocation.exclude._name" : "data1_node1,data1_node2,..."
}
}
cluster.routing.allocation.cluster_concurrent_rebalance: 用来控制集群内并发分片的 rebalance 数量,默认为2
周中新上的机器节点 node-300,到了周末统一创建索引的时候,由于 node-300基本没有分片(除少数新增索引外),会有大量的分片创建到 node-300中。 ES 集群创建完次周索引后,分片数在10w,数据节点数大致为450,平均到单个数据节点的分片大致为220+。而新周的索引分片数大约在5w+,对应的分片数为110+,而 node-300 的新周索引分片数即为220+,相当于是其余节点的1倍以上。
1.主要的思路是:计算次周总的分片数/可用数据节点,得到平均分片,然后将分片多的迁移到分片少的节点。 2.因为是空索引,迁移时间基本可以忽略不计。 3.需要注意的是可用数据节点,从_cluster/health 可以获取到对应的可用 data node 数量,但是还需要将_cluster/settings exclude._name 中对应的节点数排除出去方是真实可用的数量。 4.同步完后,可以达到写索引的平衡(整体分片数不一定均衡)。
1.顺序:先进行节点迁移=》然后进行分片平衡
2.时间:一般会提前1-2天创建次周索引,可以在创建索引后进行以上流程操作
3.节点迁移增加新节点相当于是将需要迁移的分片迁移到新节点上,因为是新节点,基本上不会有 reroute 冲突
4.可以根据机器的配置进行阈值的调整,比如迁移节点后计算节点分片阈值为80(每个节点平均80个次周分片),可以将高配置的机器阈值提高:
48c的机器 阈值增加20%
32c的机器 阈值降低20%
如果有 ssd 机器,可以在原有阈值上进一步提升,也可以做点对点分片均衡调整,将高配置节点、分片数较少节点统一作为被同步节点,将配置低节点、分片数远高于阈值节点作为同步节点,进行 reroute。
分片均衡,可以参考以下用法:
POST _cluster/reroute
{
"commands": [
{
"move": {
"index": "log_appcode-2023.18",
"shard": 59,
"from_node": "data2_node1",
"to_node": "data2_node10"
}
}
]
}
Tips:
建议小集群可以不用单独的协调节点
大集群协调节点建议如下配置(只做协调作用):
有时候系统性的优化或者方案,从来都不是一蹴而就的,都要通过不断的尝试与调整,在对系统原理的把控上,进行方案的优化,从而取得持续的进步。
https://www.elastic.co/cn/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster
https://www.elastic.co/guide/en/elasticsearch/reference/7.7/allocation-total-shards.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.7/delayed-allocation.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.7/index-modules-translog.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.7/cluster-reroute.html
https://cloud.tencent.com/developer/article/1334743?cps_key=6a15b90f1178f38fb09b07f16943cf3e
https://blog.csdn.net/laoyang360/article/details/108047071
以上就是本次分享的所有内容啦!
最后,给大家带来一些岗位招聘信息。
你与驼厂只差一份简历的距离
快扫码投递吧