總結
一、遇到集羣Red時,我們可以從如下方法排查:
集羣層面:/_cluster/health。
索引層面:/_cluster/health?pretty&level=indices。
分片層面:/_cluster/health?pretty&level=shards。
看恢復情況:/_recovery?pretty。
二、有unassigned分片的排查思路
_cluster/allocation/explain 先診斷。
/_cluster/reroute 嘗試重新分配。
三、數據重放
如果實在恢復不了,那隻能索引重建了。提供一種思路:
先新建備份索引
curl -XPUT ‘http://xxxx:9200/a_index_copy/‘ -d ‘{
“settings”:{
“index”:{
“number_of_shards”:3,
“number_of_replicas”:2
}
}
}
通過reindex,將目前可用的數據導入:
POST _reindex
{
"source": {
"index": "a_index"
},
"dest": {
"index": "a_index_copy",
"op_type": "create"
}
}
刪除a_index索引,這個必須要先做,否則別名無法添加.
curl -XDELETE 'http://xxxx:9200/a_index'
創建a_index_copy索引
curl -XPUT ‘http://xxxx:9200/a_index_copy/‘ -d ‘{
“settings”:{
“index”:{
“number_of_shards”:3,
“number_of_replicas”:2
}
}
}
通過reindex api將a_index數據copy到a_index_copy。
POST _reindex
{
"source": {
"index": "a_index"
},
"dest": {
"index": "a_index_copy",
"op_type": "create"
}
}
刪除a_index索引,這個必須要先做,否則別名無法添加
curl -XDELETE 'http://xxxx:9200/a_index'
給a_index_copy添加別名a_index
curl -XPOST 'http://xxxx:9200/_aliases' -d '
{
"actions": [
{"add": {"index": "a_index_copy", "alias": "a_index"}}
]
}'
四、translog總結
translog在節點有問題時,能夠幫助阻止數據的丟失
設計目的:
1、幫助節點從失敗從快速恢復。
2、輔助flush。避免在flush過程中數據丟失。