Elastic Stack

[elasticsearch] red index 살리기

iiliiiili 2021. 11. 11. 10:49

# curl -xget localhost:9200/_cat/indices?v

POST _cluster/reroute
{
"commands": [
{
"allocate_empty_pri":
{
"index": [INDEX_NAME],
"shard": [NUMBER],
"node": [NODE_NAME],
"accept_data_loss": true
}
}
]
}



1. Index를 삭제한다
장애 발생한 인덱스 잃지만 삭제하자마자 새로운 인덱스가 생성되며 데이터가 저장됨 (데이터 삭제됨!! )

1. Red인덱스를 우선 두고 새로운 index를 생성하고
Alias설정 한 후, red index를 살리는데 몰두한다
(현재 상태를 복구한 후 과거 데이터를 살리는데 몰두해보자)

2. Unassugned shard 없애기
Unassigned shard 왜 만들어졌는가?
이슈 발생시 엘라스틱서치 내부적으로 재할당을 시도하는데 재할당 횟수 max를 달성하면 unassigned shard로 남게됨

Unassigned shard 원인 확인
#curl -XGET http://localhost:9200/_cluster/allocation/explain

Unassigned shard 없애기
# curl -xpost localhost:9200/_cluster/reroute?retry_failed

Unassigned shard가 레플리카 샤드라면
#curl -XPUT http://localhost:9200/_settings
{
"index":{
"number_of_replicas": "0"
}
}
레플리카 샤드 삭제후 필요한만큼 다시 할당한다.



3. Cluster reroute 의 retry_failed 값을 true로 변경max retry 초기화
# curl -xpost localhost:9200/_cluster/reroute?retry_failed=true


4. 샤드 한 노드로 몰렸을 때 분산
#curl -XPOST http://localhost:9200/_cluster/reroute
{
"commands" : [
{
"move" : {
"index" : "fileebeat",
“shard" : 0,
"from_node" : "node-1", "node-3”,: "node-2"
}
}
]
}