單節點 Elasticsearch 健康狀態爲 yellow 問題的解決

項目環境中,有一個不重要的輔助功能用到了 Elasticsearch,給的服務器資源有限,只能部署一個單機 Elasticsearch。剛部署完成時,health 狀態爲正常的 green,但是過了幾天後,在查看 Elasticsearch 的 health,已經變爲 yellow :

[root@web-01 ~]# curl -X GET "10.88.0.92:9200/_cluster/health?pretty"
{
  "cluster_name" : "yxfes",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 2,
  "active_shards" : 2,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 2,
  "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 爲 2。

單點部署的 Elasticsearch,默認分片的副本數爲 1,而相同的分片不能在同一個節點上,所以就出現上面 unsigned shards 的問題。解決方法如下:

[root@web-01 ~]# curl -X PUT "10.88.0.92:9200/_settings" -H 'Content-Type: application/json' -d'
{"number_of_replicas":0}'
# 返回
{"acknowledged":true}

再次查看 Elasticsearch health,已經轉爲 green:

[root@web-01 ~]# curl -X GET "10.88.0.92:9200/_cluster/health?pretty"
{
  "cluster_name" : "yxfes",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 2,
  "active_shards" : 2,
  "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
}

【完】

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章