问题现象:es 集群状态red,查看基本信息如下:
解决过程:
1- 查看未分配分片信息
GET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
2- 首先设置所有索引副本个数全为0
curl -XPUT "http://localhost:9200/_settings" -d' { "number_of_replicas" : 0 } '{"acknowledged":true}
3- 执行下面语句查看集群状态:
curl localhost:9200/_cluster/health?pretty
别急,此时肯定还是red状态,因为一般red状态是因为有主分片没有被分配
4- 使用下面语句查看未分配分片
GET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
发现有未分配主分片,我的解决方案是,在确认该索引可以删除的情况下,直接删除索引
5- 删除主分片未分配索引
curl -XDELETE localhost:9200/***
6- 确认是否还有未分配主分片
curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED
7- 查看集群状态,此时,如果6结果为空,则状态为green或者yellow
8- 但是稍后重建索引之后,发现集群状态又变为red
9- 查看未分配主分片原因:
curl -XGET localhost:9200/_cluster/allocation/explain?pretty
原因发现是索引往节点挂载的data目录写操作时,出现accessdenied拒绝;
解决方式:chmod -R 777 data
修改data目录操作权限,再次删除上述索引,后集群状态正常;