记录一次生产ES集群存储不够导致的索引不可写入故障。

业务接口人突然找到我,业务数据已经持续半小时没有更新了。我们立即登录服务器查看,经过一番查看,发现服务器存储已经达到85%了

记录一次生产ES故障_数据

触发了ES的保护机制,索引标为只读状态,不可写入数据。

然后立即向客户申请,清理一部分历史数据。

查询索引:curl 'http://localhost:9200/_cat/indices'

删除部分历史索引数据

Curl -XDELETE http://localhost:9200/fr_tree_*_03-01

返回 true,删除成功。

以历史数据最久最先删除原则,删除了半个月的历史数据,主机df -h查询存储使用率已经降到70%。

但是查询集群状态,status仍为Red不可用状态。

Curl -XGET http://localhost:9200/_cat/health?v

记录一次生产ES故障_elastic_02

最后无奈只能杀掉es进程

ps -ef|grep elasticsearch

kill -9 PID

sudo systemctl start elasticsearch

服务重新拉起后,持续观察应用状态

curl  -XGET 'http://localhost:9200/_cat/health?v'

记录一次生产ES故障_历史数据_03

分片一直在加载中,等待加载到100%,因为数据量较大,大约等待加载半小时左右。

ES集群状态由Red > Yellow > Green

前台数据加载也已恢复正常。

下面附调整集群默认85%的存储阈值(根据实际业务调整)

PUT /_cluster/settings

{

{

"transient": {

"cluster.routing.allocation.disk.watermark.low": "90%",

"cluster.routing.allocation.disk.watermark.high": "95%",

"cluster.info.update.interval": "1m"

}

}

}

persistent表示为永久修改,重启以后也会保存设置transient表示临时修改,重启以后不会保存设置"cluster.info.update.interval": "1m" #时间间隔 现在是1分钟,默认是30s

查看ES集群状态yellow/red原因

curl http://localhost:9200/_cluster/allocation/explain

记录一次生产ES故障_elastic_04

ES集群的三种状态:

Green - 所有数据都可用,主副分片都已经分配好;

Yellow - 所有数据都可用,但尚未分配一些副本,不影响查询,可能影响恢复;

Red - 某些数据由于某种原因 存在主分片未分配,对查询会有影响。