项目环境中,单机部署的 Elasticsearch 刚部署完成时,health 状态为正常的 green,但是过了几天后,在查看 Elasticsearch 的 health,已经变为 yellow :
[root@localhost ~]# curl '127.0.0.1:9200/_cluster/health?pretty'
{
"cluster_name" : "master",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 20,
"active_shards" : 20,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 20,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 50.0
}
-
根据上面的返回信息,集群的 unassigned_shards 为 20。
-
单点部署的 Elasticsearch,默认分片的副本数为 1,而相同的分片不能在同一个节点上,所以就出现上面 unsigned shards 的问题。解决方法如下:
$ curl -X PUT "127.0.0.1:9200/_settings" -H 'Content-Type: application/json' -d'{"number_of_replicas":0}'
# 返回
{"acknowledged":true}
- 再次查看 Elasticsearch health,已经转为 green:
[root@web-01 ~]# curl -X GET "127.0.0.1:9200/_cluster/health?pretty"
{
"cluster_name" : "master",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 20,
"active_shards" : 20,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}