集群级设置管什么
集群级设置通过 _cluster/settings 接口读写,控制的是跨索引、跨节点的行为:分片分配开关、磁盘水位判定、节点排除规则、恢复与快照限速等。设置分持久化与临时两类,前者写进集群状态长期有效,后者重启后失效;8.x 已移除临时设置,统一写持久化。
基本信息
| 接口 | PUT /_cluster/settings 写入,GET /_cluster/settings 读取 |
|---|---|
| 常用项 | cluster.routing.allocation.enable、cluster.routing.allocation.disk.threshold_enabled、cluster.routing.allocation.exclude._name、indices.recovery.max_bytes_per_sec |
| 清理方式 | 把值设为 null 即恢复默认行为 |
| 查看默认值 | ?include_defaults=true&flat_settings=true |
| 版本差异 | transient 在 8.x 已被移除,只接受 persistent |
典型使用场景
- 节点维护或重启前暂停分片迁移,减少无谓的重新分配
- 调高恢复限速,加快节点回来后的分片恢复速度
- 把某批节点排除出分配范围,用于下线换盘或硬件更换
- 磁盘告警期间统一调整水位阈值或临时关闭判定
- 排查分配异常时对比当前生效值与被改过的默认值
读写与恢复默认
读写与恢复默认
# 读:只看显式设置过的项
GET /_cluster/settings
# 读:连同默认值一起看,确认阈值是否被改过
GET /_cluster/settings?include_defaults=true&flat_settings=true
# 写:暂停分片分配,用于维护窗口
PUT /_cluster/settings
{ "persistent": { "cluster.routing.allocation.enable": "none" } }
# 写:恢复分配并调大恢复限速
PUT /_cluster/settings
{ "persistent": { "cluster.routing.allocation.enable": "all",
"indices.recovery.max_bytes_per_sec": "200mb" } }
# 恢复默认:把值设为 null
PUT /_cluster/settings
{ "persistent": { "indices.recovery.max_bytes_per_sec": null } }常用设置与影响
| 设置项 | 作用 | 注意 |
|---|---|---|
| cluster.routing.allocation.enable | all / primaries / new_primaries / none 控制分配范围 | 设为 none 时新建索引也可能无法分配 |
| cluster.routing.allocation.disk.threshold_enabled | 是否启用磁盘水位判定 | 关掉只是掩盖问题,磁盘写满后索引仍会只读 |
| cluster.routing.allocation.exclude._name | 把匹配的节点排除出分配范围 | 节点改名后规则会静默失配 |
| indices.recovery.max_bytes_per_sec | 限制单节点恢复带宽,默认 40mb | 调太大挤占正常查询与写入的 IO |
| cluster.info.update.interval | 检查各节点磁盘使用情况的间隔,默认 30s | 调小会增加集群状态更新频率 |
维护或重启节点前把 allocation.enable 设为 none 暂停分片移动,节点回归后再设回 all,可以显著减少无谓的重新分配与恢复流量,这也是滚动升级的标准前置动作。