1.查看集群健康狀態:curl -u elastic:password -XGET http://localhost:9200/_cluster/health\?pretty #-u:發送親求時帶上賬號密碼
2.查看所有分片狀態:curl -u elastic:password -XGET http://localhost:9200/_cat/shards (顯示所有分片狀態)
3.查看所有未分配分片:curl -u elastic:password -s "http://localhost:9200/_cat/shards" | grep UNASSIGNED
4.查看master節點的唯一標識:curl -u elastic:password 'localhost:9200/_nodes/process?pretty'
5.執行reroute(分多次,逐個修復 變更shard的值為UNASSIGNED查詢結果中編號, 上一步查詢結果是/0 1 2 3 4)
inde:需要修復的索引的名字(這里需要修復三個索引)
shard:shard的編號,圖中可以看出
node:master節點的唯一標識
curl -u elastic:password -XPOST 'localhost:9200/_cluster/reroute' -d ' { "commands" : [{ "allocate" : { "index" : "k8s-boamp-2019.05.31", "shard" : 3, "node" : "Xp-ARwguQKS3rTETdAxzJA", "allow_primary" : true } }] } '
6.在kibana頁面提交請求
常用查詢總結:
POST _cluster/reroute?retry_failed #執行 POST _cluster/reroute?retry_failed,分片分配重試,可以重新分配分片,可能需要多執行幾次
GET _cluster/health/?pretty #查看集群健康狀態
GET _cat/shards #查看所有分片狀態
GET _nodes/process?pretty #查看master節點的唯一標識
GET _cat/shards?h=index,shard,unassigned.reason #查看分片不能夠進行分配的原因【目前問題出現在標紅的兩個原因上】
1. INDEX_CREATED Unassigned as a result of an API creation of an index. 索引創建 由於API創建索引而未分配的 2. CLUSTER_RECOVERED Unassigned as a result of a full cluster recovery. 集群恢復 由於整個集群恢復而未分配 3. INDEX_REOPENED Unassigned as a result of opening a closed index. 索引重新打開 4. DANGLING_INDEX_IMPORTED Unassigned as a result of importing a dangling index. 導入危險的索引 5. NEW_INDEX_RESTORED Unassigned as a result of restoring into a new index. 重新恢復一個新索引 6. EXISTING_INDEX_RESTORED Unassigned as a result of restoring into a closed index. 重新恢復一個已關閉的索引 7. REPLICA_ADDED Unassigned as a result of explicit addition of a replica. 添加副本 8. ALLOCATION_FAILED Unassigned as a result of a failed allocation of the shard. 分配分片失敗 9. NODE_LEFT Unassigned as a result of the node hosting it leaving the cluster. 集群中節點丟失 10. REROUTE_CANCELLED Unassigned as a result of explicit cancel reroute command. reroute命令取消 11. REINITIALIZED When a shard moves from started back to initializing, for example, with shadow replicas. 重新初始化 12. REALLOCATED_REPLICA A better replica location is identified and causes the existing replica allocation to be cancelled. 重新分配副本
POST _cluster/reroute #修復UNASSIGNED的分片shard【未成功】
{
"commands" : [{
"allocate" : {
"index" : "k8s-boamp-2019.05.31",
"shard" : 3,
"node" : "F1XF02QJTxaWXxvoZ88AaQ",
"allow_primary" : true
}
}]
}
#獲取模板屬性
GET _template/bbh-game
#修改模板屬性
PUT _template/bbh-game
{
"index_patterns": ["bbh-game*"],
"order" : 0,
"settings": {
"number_of_shards": "3",
"number_of_replicas" : "1"
}
}
#修改分片副本數量
PUT _settings
{"number_of_replicas" : "1"}