环境

  • Elasticsearch版本:7.10.2

问题现象

Elasticsearch所在的节点磁盘空间达到一定的水位时,会自动触发规则,这些规则可能会影响我们的业务。主要以下默认的配置参数影响:

  • cluster.routing.allocation.disk.threshold_enabled: true
  • cluster.routing.allocation.disk.watermark.low:85%
  • cluster.routing.allocation.disk.watermark.high: 90%
  • cluster.routing.allocation.disk.watermark.flood_stage:95%

Elasticsearch某个节点磁盘使用率为 85% 的时,就不会在该节点进行创建副本,当磁盘使用率达到 90% 的时,尝试将该节点的副本重分配到其他节点。当磁盘使用率达到95% 的时,当前节点的所有索引将被设置为只读索引。

解决方案

方法1、增加主机上的磁盘空间

  • 删除主机上所有不需要的文件
  • 在线扩容磁盘*(能用钱解决的问题就不叫问题)*

方法2、 修改Elasticsearch配置策略

在线调整

只需要将配置参数PUT到Elasticsearch即可生效。

  • 临时生效
# curl -XPUT -H "Content-Type: application/json" 127.0.0.1:9200/_cluster/settings \
-d '
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "90%",
    "cluster.routing.allocation.disk.watermark.high": "95%",
    "cluster.routing.allocation.disk.watermark.flood_stage": "98%",
    "cluster.info.update.interval": "90s"
  }
}'

cluster.info.update.interval检测的周期,默认是30s

  • 永久生效
# curl -XPUT -H "Content-Type: application/json" 127.0.0.1:9200/_cluster/settings \
-d '
{
  "persistent": {
    "cluster.routing.allocation.disk.watermark.low": "90%",
    "cluster.routing.allocation.disk.watermark.high": "95%",
    "cluster.routing.allocation.disk.watermark.flood_stage": "98%",
    "cluster.info.update.interval": "90s"
  }
}'

方法3、写入配置文件

将以下内容写到配置文件(elasticsearch.yml)中

cluster.routing.allocation.disk.threshold_enabled: true
cluster.routing.allocation.disk.watermark.low: 90%
cluster.routing.allocation.disk.watermark.high: 95%
cluster.routing.allocation.disk.watermark.flood_stage: 98%
cluster.info.update.interval: 90s

重启启动服务,完成后可以使用以下命令来确认。

# curl -XGET  127.0.0.1:9200/_cluster/settings