最近遇到一个问题:往系统中写入数据后,查询出来的结果一直为空,由于查询用到了Elasticsearch 分布式搜索引擎。检查es日志,提示"flood stage disk watermark [95%] exceeded",得知磁盘使用率超出阈值,es索引模式变为只读,无法写入数据,从而造成数据同步失败。
image.png
针对该问题,有两种解决办法:
- 清理磁盘空间
因为Elasticsearch 会对磁盘空间进行监控,当磁盘剩余空间达到了 floodstage 阈值,会将所有相关索引强制置为只读。需要清理磁盘空间后,才能写入数据。
- 调整ElasticSearch的默认阈值
在/config/elasticsearch.yml 文件中增加如下配置:
cluster.routing.allocation.disk.watermark.low: 90%
cluster.routing.allocation.disk.watermark.high: 95%
cluster.routing.allocation.disk.watermark.flood_stage: 97%
或
cluster.routing.allocation.disk.watermark.low: 100gb
cluster.routing.allocation.disk.watermark.high: 50gb
cluster.routing.allocation.disk.watermark.flood_stage: 10gb
其中,
cluster.routing.allocation.disk.watermark.low,默认85%,用于控制磁盘的最小使用率;cluster.routing.allocation.disk.watermark.high,默认90%,用于控制磁盘的最大使用率;cluster.routing.allocation.disk.watermark.flood_stage,默认95%,超过此值时,Elasticsearch 变成只读模式,无法写入数据。
注:上述配置必须同时设为百分比,或具体字节值,不能混用。