ES集群的三种状态:
Green - 所有数据都可用,主副分片都已经分配好
Yellow - 所有数据都可用,但尚未分配一些副本,不影响查询,可能影响恢复。
Red - 某些数据由于某种原因 存在主分片未分配,对查询会有影响
查看ES集群状态yellow原因
curl http://localhost:9200/_cluster/allocation/explain

可以看出是因为磁盘使用大于85%导致ES集群分片副本没有合适的节点进行分配,状态yellow
解决方法:
1、我这台节点磁盘使用率已经98%,考虑对所在磁盘进行扩容(如果磁盘剩余空间较大,可以设置告警阈值进行恢复)。
2、扩容将出现问题的索引副本数设置为0
列出未分配的副本:
curl -X GET -s 127.0.0.1:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED

将出现问题的索引副本数设置为0
curl -X PUT http://127.0.0.1:9200/microblogdata/_settings --header 'Content-Type: application/json' -d '{"index":{"number_of_replicas":0}}'
3、待集群状态转绿后再将其副本数设置为1
待转绿后,再将副本数设置为1,这样副本在可用空间再次分配,生产环境最好再闲暇时间操作,避免因数据量过多导致I0压力增大
curl -X PUT http://127.0.0.1:9200/microblogdata/_settings --header 'Content-Type: application/json' -d '{"index":{"number_of_replicas":1}}'
注意:如果磁盘只是使用百分比过高,但实例剩余空间较大,可以调用接口修改磁盘限额
磁盘限额:
为了保护节点数据安全,ES 会定时(cluster.info.update.interval,默认 30 秒)检查一下各节点的数据目录磁盘使用情况。在达到 cluster.routing.allocation.disk.watermark.low (默认 85%)的时候,新索引分片就不会再分配到这个节点上了。在达到 cluster.routing.allocation.disk.watermark.high (默认 90%)的时候,就会触发该节点现存分片的数据均衡,把数据挪到其他节点上去。当达到cluster.routing.allocation.disk.watermark.flood_stage(默认 95%),完全不允许往该节点上写入数据了,这是最后一道保护。只要在high watermark阶段,数据可以迁移到其它节点,并且迁移的速度比写入的速度快,那就不会进入该阶段。这三个个值不但可以写百分比,还可以写具体的字节数。有些公司可能出于成本考虑,对磁盘使用率有一定的要求,需要适当抬高这个配置,当低于5.6版本cluster.routing.allocation.disk.watermark.flood_stage不存在。
curl -H "Content-Type: application/json" -XPUT http://${ES_CLUSTER_IP}: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": "97%",
"cluster.info.update.interval": "1m"
}
}'