文章目录

  • 1.简述
  • 2. cluster 级别的shard allocation 相关的设置
    • 1. shard allocation 相关设置
      • 1. cluster.routing.allocation.enable
      • 2. cluster.routing.allocation.node_concurrent_incoming_recoveries
      • 3. cluster.routing.allocation.node_concurrent_outgoing_recoveries
      • 4. cluster.routing.allocation.node_concurrent_recoveries
      • 5. cluster.routing.allocation.node_initial_primaries_recoveries
      • 6. cluster.routing.allocation.same_shard.host
    • 2. shard rebalance相关设置
      • 1. cluster.routing.rebalance.enable
      • 2. cluster.routing.allocation.allow_rebalance
      • 3. cluster.routing.allocation.cluster_concurrent_rebalance
    • 3. shard balancing 的因子设置
      • 1. cluster.routing.allocation.balance.shard
      • 2. cluster.routing.allocation.balance.index
      • 3. cluster.routing.allocation.balance.threshold
    • 4. allocation和rebalance的区别和联系
  • 3. 基于磁盘的shard allocation限制
    • 1. cluster.routing.allocation.disk.threshold_enabled
    • 2. cluster.routing.allocation.disk.watermark.low
    • 3. cluster.routing.allocation.disk.watermark.high
    • 4. cluster.routing.allocation.disk.watermark.flood_stage
    • 5. cluster.info.update.interval
    • 6. cluster.routing.allocation.disk.include_relocations
    • 7. 一个使用样例
  • 4. 通过属性配置设置,达到allocation 分配时对node的感知
    • 1. 开启集群allocation 感知
    • 2. 强制感知是什么呢
  • 5. cluster级别的shard allocation filter 设置
    • 1. include
    • 2. require
    • 3. exclude
    • 4. 也可以使用正则来进行配置

1.简述

这里主要是学习master对shard的管理,master决定了一个shard需要被分配到哪个node上面,以及什么时候在cluster中的node之间移动shard来reblace整个cluster

2. cluster 级别的shard allocation 相关的设置

shard alloction 是在某个node上创建某个shard的过程。这个过程会发生在initial recovery, replica allocation, rebalancing, 或者node add或remove的时候

1. shard allocation 相关设置

这个是

1. cluster.routing.allocation.enable

开启或者关闭某种类型的shard的allocation

  1. all : (default) 允许所有类型的shard被allocate
  2. primaries : 只允许primaries被allocated
  3. new_primaries: 只允许primaries被allocated
  4. none : 不孕育任何shard被allocated

这个设置不会影响一个node重启的时候对local primary的recovery, 如果一个被重启的node有一份nassigned primary shard 的copy,那么这个shard会立即成为 primary shard, 当然,这个shard的allocation id要和cluster state中记录的active allocation ids一致。

什么是allocation id 参看这里

2. cluster.routing.allocation.node_concurrent_incoming_recoveries

这个参数设置了每个节点可以有多少个shard可以接收从外面进来的recovery用的数据。

  1. 一般情况下都是node上的shard都是replica shard,这些shard 接收来自primary shard的数据进行恢复
  2. 如果是relocation操作那么这个node上对应的shard也有可能是primary shard
    默认值是2

3. cluster.routing.allocation.node_concurrent_outgoing_recoveries

这个和上一个参数正好是相对的,控制了每个node上可以有多少个shard在向外提供shard recovery的数据。

  1. 一般情况下都是node上的shard都是primary shard,这些shard 向replica shard传输数据进行shard恢复
  2. 如果是relocation操作那么这个node上对应的shard也有可能是replica shard

默认值是2

4. cluster.routing.allocation.node_concurrent_recoveries

这个参数是上面两个参数的综合体,也就是会把上面两个参数设置为一样的
cluster.routing.allocation.node_concurrent_incoming_recoveries and cluster.routing.allocation.node_concurrent_outgoing_recoveries.

5. cluster.routing.allocation.node_initial_primaries_recoveries

replica shard的恢复一般是通过network从primary恢复,但是unassigned primary shard的恢复则只能是通过原来有这个shard的node被重新启动了来进行恢复。这个应该稍微大一些,以便于更多的unassigned primary shard可以更快的被恢复。

6. cluster.routing.allocation.same_shard.host

开启一个检查来防止同一个shard的多个instances在同一个host上面,这个是为了让es能够更好的应对es的node挂掉的情况,这种情况一般都是在一个主机上启动了多个node,这样的话这个node挂掉后es的某个shard的数据可能就丢了,一般情况下,同一个集群的的多个node不会在同一个node上面,但是需要注意有时候我们使用的是虚拟机,虚拟机层面不在同一个服务器上,但是实际多个虚拟机上可能在同一个物理机上,这种情况也是应该尽量避免的。否则就会造成数据的丢失情况。
这个值某人是false,也就是不会开启检查

2. shard rebalance相关设置

下面这些动态设置是用来设置集群层面的shards的rebalance的

1. cluster.routing.rebalance.enable

开启或者关闭某种shard的rebalance

  1. all - (default) Allows shard balancing for all kinds of shards.
  2. primaries - Allows shard balancing only for primary shards.
  3. replicas - Allows shard balancing only for replica shards.
  4. none - No shard balancing of any kind are allowed for any indices.

2. cluster.routing.allocation.allow_rebalance

什么时候允许rebalance操作开始

  1. always - 任何时候都可以
  2. indices_primaries_active - 只有当集群中多有的primary shards都被allocated之后才允许
  3. indices_all_active - (default) 只有当集群中的所有的shard(primaries and replicas) 都被allocated之后才允许rebalance操作

3. cluster.routing.allocation.cluster_concurrent_rebalance

这个设置控制了集群rebalance的并行度,默认值是2。
需要注意的是这个只能控制因为imbalances 导致的shard的迁移的并行度,并不能限制因为allocation filtering 或者 forced awareness导致的分片的转移。

3. shard balancing 的因子设置

The following settings are used together to determine where to place each shard. The cluster is balanced when no allowed rebalancing operation can bring the weight of any node closer to the weight of any other node by more than the balance.threshold.
以下3个因子共同决定了在哪个node上面放置shard,当任何一个rebalance操作都不能使集群中的node之间的weight差距减小的话,集群就达到了balanced的状态。

1. cluster.routing.allocation.balance.shard

设置了每个node上的shard总数在集群balance中占据的权重因子,默认是0.45f,增加这个值的话就意味着集群的balance更倾向于使每个node上面的shard数量都保持一致。
Defines the weight factor for the total number of shards allocated on a node (float). Defaults to 0.45f. Raising this raises the tendency to equalize the number of shards across all nodes in the cluster.

2. cluster.routing.allocation.balance.index

设置了每个index在某个node上的shards数量的权重,默认是0.55f,增大这个值的话意味着集群的balance更倾向于让index的shards平均的分配到cluster的每个node上面。
Defines the weight factor for the number of shards per index allocated on a specific node (float). Defaults to 0.55f. Raising this raises the tendency to equalize the number of shards per index across all nodes in the cluster.

3. cluster.routing.allocation.balance.threshold

shard rebalance的触发阈值,默认是1.0f,增加这个值意味着cluster对集群的balance要求更低,也就是说更不容易触发rebalance。

Minimal optimization value of operations that should be performed (non negative float). Defaults to 1.0f. Raising this will cause the cluster to be less aggressive about optimizing the shard balance.

4. allocation和rebalance的区别和联系

这里主要想再强调一下allocation和rebalance的关系,主要从下面两个配置来进行解析

  1. cluster.routing.allocation.enable
  2. cluster.routing.rebalance.enable

对于allocation强调的是shard的分配,不管你这个shard是因为什么原因要进行分配,比如某个node突然挂掉需要重新分配一些unassigned的shard, 手动的relocation的话需要在目标node上allocation新的shard, rebalance的话也需要在目标node上allocation新的shard。
比如说可能某个node突然挂掉了(而且挂掉的node上的数据被清理掉了),导致了某些shard是unassigned的,这个时候如果 cluster.routing.allocation.enable:none那么即使cluster.routing.rebalance.enable:all,这些unassigned的shard也不会被分配到其他节点,因为最根本的shard分配操作被禁止了。

假如这个时候设置为
cluster.routing.rebalance.enable: none
cluster.routing.allocation.enable: all
那么对应的unassigned的shard会被分配到其他几点上面。在分配完成集群编程green的时候重启挂掉的node(该node上面没有数据),那么该node上面的shard数量会一直是0,因为rebalance被关闭了。当重新设置cluster.routing.rebalance.enable: all的时候,才会将部分shard迁移到新启动的node上面。
综上,rebalance的功能需要依赖allocation功能的开启,allocation没有开启的话是没有办法进行rebalance操作的(手动的relocation理所当然也没有办法进行),当然allocation还会限制shard丢失之后的shard重新分配。

3. 基于磁盘的shard allocation限制

es会考虑一个node现有的磁盘容量来决定是否将一个新的shard分配到这个node上面,或者是否有必要激活relocation操作从这个node上面迁移走一些shard.
下面这些磁盘相关的设置都是动态的,可以通过elasticsearch.yml设置,也可以通过api来进行设置。

1. cluster.routing.allocation.disk.threshold_enabled

默认是true,如果设置为false的时候在进行shard allocation的时候就不会考虑磁盘的因素。
Defaults to true. Set to false to disable the disk allocation decider.

2. cluster.routing.allocation.disk.watermark.low

低风险水位设置,这个设置的默认值是85%,意味着当一个node的磁盘使用率达到了85%,那么就不会再往这个node上面分配shard了。这个设置对于新创建的index的primary shard不起作用,但是会对replica shard起作用。
这个值也可以直接设置为一个绝对值,比如500mb,这个500mb是指剩余的使用空间哈,不是指已经使用了的空间。 这种在集群磁盘比较大的时候比较有用,比如每个node的数量是3T,操作系统实际需要的可能也就50G,但是按照百分比算的话,1% 也有300G,相对来说会有一些浪费。这个时候我们就可以直接设置50G就完事儿了。

Controls the low watermark for disk usage. It defaults to 85%, meaning that Elasticsearch will not allocate shards to nodes that have more than 85% disk used. It can also be set to an absolute byte value (like 500mb) to prevent Elasticsearch from allocating shards if less than the specified amount of space is available. This setting has no effect on the primary shards of newly-created indices but will prevent their replicas from being allocated.

3. cluster.routing.allocation.disk.watermark.high

高风险水位设置,这个设置是90%, 当某个node的磁盘使用率达到90%的时候,elasticsearch就会考虑将一部分shard从这个node上面relocate away 到别的node上面。同样的,这个也可以设置为一个实际的值,比如500mb。
这个设置会影响所有的shard的allocation,不论是之前已经分配过的shard或者是新创建的index的shard的分配。

Controls the high watermark. It defaults to 90%, meaning that Elasticsearch will attempt to relocate shards away from a node whose disk usage is above 90%. It can also be set to an absolute byte value (similarly to the low watermark) to relocate shards away from a node if it has less than the specified amount of free space. This setting affects the allocation of all shards, whether previously allocated or not.

4. cluster.routing.allocation.disk.watermark.flood_stage

濒临崩溃阶段,这个设置默认值是95%,当某个node的磁盘使用达到这个水平以后,这个node上的shard对应的index都会被设置为index.blocks.read_only_allow_delete,也就是只允许读操作和删除操作,这是es为了应对集群崩溃不得不采取的一个操作,而且在cluster中的node解除磁盘风险后需要手动进行index.blocks的只读设置的解除。

Controls the flood stage watermark. It defaults to 95%, meaning that Elasticsearch enforces a read-only index block (index.blocks.read_only_allow_delete) on every index that has one or more shards allocated on the node that has at least one disk exceeding the flood stage. This is a last resort to prevent nodes from running out of disk space. The index block must be released manually once there is enough disk space available to allow indexing operations to continue.

You can not mix the usage of percentage values and byte values within these settings. Either all are set to percentage values, or all are set to byte values. This is so that we can we validate that the settings are internally consistent (that is, the low disk threshold is not more than the high disk threshold, and the high disk threshold is not more than the flood stage threshold).

非常需要注意的一点是

cluster.routing.allocation.disk.watermark.low
cluster.routing.allocation.disk.watermark.high
cluster.routing.allocation.disk.watermark.flood_stage

这三个参数的配置类型要保持一致性,也就是说如果使用的是百分比配置则这三个参数都要使用百分比配置,如果想使用具体的大小值设置则都要使用大小值设置。
同时,使用百分比配置的时候是指已经使用的磁盘占比,使用具体值大小的时候指的是剩余空闲磁盘空间容量。

5. cluster.info.update.interval

elasticsearch检查磁盘使用量的频率,默认是每隔30s检查一次。
How often Elasticsearch should check on disk usage for each node in the cluster. Defaults to 30s.

6. cluster.routing.allocation.disk.include_relocations

这个设置控制了cluster在计算一个node的磁盘的使用量的时候是否会加上relacating的shard的磁盘使用,默认是true。
这种计算方式会在磁盘使用量较高node的磁盘使用量计算上产生误差,因为他可能已经将一个shard的90%都迁移出去了,但是我们统计的时候使用的是整个shard的值。

Defaults to true, which means that Elasticsearch will take into account shards that are currently being relocated to the target node when computing a node’s disk usage. Taking relocating shards’ sizes into account may, however, mean that the disk usage for a node is incorrectly estimated on the high side, since the relocation could be 90% complete and a recently retrieved disk usage would include the total size of the relocating shard as well as the space already used by the running relocation.

7. 一个使用样例

若果我们想将低风险水位设置在磁盘剩余容量100G,高风险水位设置在磁盘剩余容量50G,濒临崩溃的风险水位设置在剩余容量为10G,那么我们可以这样设置。

PUT _cluster/settings
{"transient": {"cluster.routing.allocation.disk.watermark.low": "100gb","cluster.routing.allocation.disk.watermark.high": "50gb","cluster.routing.allocation.disk.watermark.flood_stage": "10gb","cluster.info.update.interval": "1m"}
}

An example of updating the low watermark to at least 100 gigabytes free, a high watermark of at least 50 gigabytes free, and a flood stage watermark of 10 gigabytes free, and updating the information about the cluster every minute:

4. 通过属性配置设置,达到allocation 分配时对node的感知

这一块儿的配置咋一看基本上和前文当中对index filter的使用中记录的类似,但是真的是相似而不相同。
这一块儿主要是针对整个集群的配置。

1. 开启集群allocation 感知

1.给对应的node设置attribute,假如我们为每个node标记一个容量size属性,有small,medium,big三个属性,


node.attr.rack_id: rack_one或者`./bin/elasticsearch -Enode.attr.rack_id=rack_one`

2.在每个master-eligible node的elasticsearch.yml文件中开启设置

cluster.routing.allocation.awareness.attributes: rack_id 

也可以通过对应啊api来进行动态设置

在这种情况下,如果你进行如下操作:

  1. start 2个配置为node.attr.rack_id:rack_one的node
  2. 创建一个index,这个index有5个primary shard,每个primary有1个replica
  3. 这个时候10个shard会被分配在这两个node上面,但是并不会考虑是否有某个shard的replica和primary在同一个node上面,因为cluster认为两个node是同一个node,因为他们对应的rack_id是一样的
  4. 如果再添加两个配置为node.attr.rack_id:rack_two的node,es会把部分shard迁移到新的node上面,并且会保证同一个shard的primary和replica不会在相同的rack_id的nodes上面
  5. 如果配置为node.attr.rack_id:rack_two的node挂掉了,es会把所有的shard都allocated到node.attr.rack_id:rack_one的node上面
  6. 如果想要同一个shard的primary和replica不会分配到相同的rack_id的nodes上,可以开启强制感知

2. 强制感知是什么呢

强制感知可以避免同一个atrribute id的nodes持有某个shard的primary和replica,因为同一个attribute id被认为具有强关联的机器,可能会同时挂掉,通过强制感知可以降低数据丢失的风险
先来看看强制感知如何使用

cluster.routing.allocation.awareness.attributes: zone
cluster.routing.allocation.awareness.force.zone.values: zone1,zone2 

这里设置了强制感知的attribute的值为zone1,zone2

还拿上面的例子来说

  1. start 2个配置为node.attr.zone:zone1的node
  2. 创建一个index,这个index有5个primary shard,每个primary有1个replica
  3. 这个时候只有5个primary会被分配到两个node上面,replica shard并不会被分配,直到有node.attr.zone:zone2的node加入到集群当中

5. cluster级别的shard allocation filter 设置

在cluster级别设置一些filter和在index级别设置filter的使用方式类似,但是作用范围是cluster级别
使用的样式如下

PUT _cluster/settings
{"transient" : {"cluster.routing.allocation.exclude._ip" : "10.0.0.1"}
}

对应的可以是自定义的node attribute, 或者是是内建的_name, _ip, _host attributes.
对应的setting有

1. include

cluster.routing.allocation.include.{attribute}

只需要node的attribute中有一个在当前include的配置列表当中即可
Allocate shards to a node whose {attribute} has at least one of the comma-separated values.

2. require

cluster.routing.allocation.require.{attribute}
对应的node必须有全部的当前配置的attribute才会将分片分配上去
Only allocate shards to a node whose {attribute} has all of the comma-separated values.

3. exclude

cluster.routing.allocation.exclude.{attribute}
对应的node没有任何当前配置的的attribute才会将分片分配上去
Do not allocate shards to a node whose {attribute} has any of the comma-separated values.

4. 也可以使用正则来进行配置

PUT _cluster/settings
{"transient": {"cluster.routing.allocation.exclude._ip": "192.168.2.*"}
}

03.shard_allocation_和_cluster的routing设置相关推荐

  1. 【学浪下载教程】03学浪下载之Proxifier设置

    首先解压我给大家的学浪大礼包压缩包 手动安装Proxifier中文汉化版 1.点击大礼包中的proxifier中文汉化版 2.点击下一步 3.点击下一步 4.选择好安装路径,我这里就默认,然后点击下一 ...

  2. mysql一主两从_MySQL 网络延迟参数设置建议

    点击上方"数风云"关注我们吧! 文/毛思平 近期投产的MySQL数据库集群偶尔出现节点被逐出集群的情况,怀疑是网络抖动导致的.查询官方文档发现,MySQL 8.0.13版本引入集群 ...

  3. url指定服务器,Linux服务器设置定时任务来访问指定url

    查看定时任务列表# crontab -l 编辑定时任务# crontab -e 删除工作表# crontab -f crontab的命令构成为 时间+动作,其时间有分.时.日.月.周五种,操作符有*取 ...

  4. arcgiss如何在空白点图层加入坐标_连载 | 21 QGIS工程文件属性设置(2)——坐标参照系、变换、默认样式、数据源、关系和变量...

    今天继续分享工程文件属性的设置,包括工程坐标参照系.变换.默认样式.数据源.关系和变量六个部分.  01  坐标参照系 工程坐标参照系定义了当前地图窗口所使用的坐标系,决定了如何将数据从其底层原始坐标 ...

  5. 【BLE MIDI】MIDI 文件格式分析 ( FF 03 轨道名称 | FF 51 03 四分音符时长 )

    文章目录 前言 一.FF 03 轨道名称 二.FF 51 03 四分音符时长 前言 在博客 [BLE MIDI]MIDI 文件格式分析 ( MIDI 文件头解析 | MIDI 文件头标识 | MIDI ...

  6. Docker 容器CPU设置

    CPU使用率其实就是你运行的程序占用的CPU资源,表示你的机器在某个时间点的运行程序的情况. 使用率越高,说明你的机器在这个时间上运行了很多程序,反之较少. CPU使用率的高低与你的CPU强弱有直接关 ...

  7. 组态王串口服务器虚拟串口,串口服务器USR-N520连接组态王设置步骤

    调试目的: USB-RS232或者USB-RS485串口线接USR-N520串口和电脑USB口,MODBUS SLAVE软件打开COM口,模拟客户串口MODBUS RTU设备.串口服务器USR-N52 ...

  8. Altium Designer(二):规则设置

    A.规则依据: 物理限制.例如元器件需要的焊盘大小,电流及信号需要的线宽大小等等: 代工厂的加工能力.需要参考PCB代工厂的工艺参数,例如工厂的机械钻孔极限值.线隙间距.工艺边等等. B.规则设置: ...

  9. bootstrap树节点如何设置默认不展开_GraPhlAn:最美进化树或层级分类树学习笔记

    Graphlan可视化进化树 撰文:文涛 南京农业的大学 责编:刘永鑫 中科院遗传发育所 GraPhlAn简介 总体来讲,Graphlan是一个可视化进化树和基于分类等级绘制层级分类树的工具.可以制作 ...

最新文章

  1. iphone 11维修 服务器,苹果官方承认!iPhone 11有这个重大问题,将免费维修
  2. html阅读开放试用阶段,泰克为不同行业提供100种应用功能免费试用
  3. linux中软件包安装(rpm和yum)
  4. 邓西百度网盘多帐号文件一键搜索工具
  5. Apache Ant安装 验证
  6. Step by Step WebMatrix网站开发之二:使用WebMatrix(2)
  7. 西华大学计算机学院陈鹏,中国计算机学会CCF服务计算专委会走进西华大学
  8. CVPR 2019 | 近日新出论文汇总(含视频目标分割、GAN、度量学习、高效语义分割等主题)...
  9. 基于JAVA+Servlet+JSP+MYSQL的在线汽车订票系统
  10. python美股财务数据曝光_python实现美股日k线数据获取
  11. 传统ORB-SLam中位姿优化中雅克比矩阵讲解
  12. python wifi密码本下载_WifiPass下载 WifiPass(Python获取本机保存的所有WIFI密码) 免费版 下载-脚本之家...
  13. 辐射定标、辐射校正、大气校正、正射校正概念
  14. 视频教程-网络工程师的5天修炼-软考
  15. struct 结构体 所占字节数的计算
  16. 一位工作了 10 年的 Java 高级架构师的技术之路
  17. 秦汉考场科目三路线图_秦汉科目三考场考试攻略,附考场路线图
  18. 周鸿祎给360员工的一份信:不做打工者
  19. ubuntu 软件指南
  20. WordPress搭建“外贸独立站”完整操作教程

热门文章

  1. 监听以太网(三) Packet32数据结构说明
  2. Netty学习笔记(五)Pipeline
  3. Go服务迁到K8s后老抽风重启? 记一次完整的线上问题解决过程
  4. 灵光一现的创造——霍夫曼编码
  5. 音视频技术开发周刊 | 188
  6. Java锁之公平和非公平锁
  7. 腾讯高性能分布式路由技术,亮相亚太网络研讨会APNet
  8. 综述 | 生成对抗网络(GAN)在图网络中的应用
  9. 光模块的分类与HBA卡的区别
  10. 请求发送者与接收者解耦——命令模式