elasticsearch status red index 복구 방법

2019. 11. 29. 05:37ELK

정상적인 경우 Index 상태는 Green 이나 Yellow 여야 합니다.

Green 상태는 3대 이상을 Cluster로 구성할 경우 표시되고, Yellow는 2대 이하로 Clustering 구성하는 경우 상태로 표시됩니다.

Elastic Index Status

2가지 경우는 표현상 차이만 있지 Cluster 동작상 문제가 되지는 않습니다.

하지만, red 상태가 되면 정상 동작을 하지 못하는 상태를 의미합니다.

 

 

빠르게 복구하는 방법


red 상태인 index 를 삭제를 하게 되면 elasticsearch가 자동으로 새로운 index 파일을 생성하면서 문제가 해결되고, Index status 가 정상으로 바로 복구가 됨

하지만, 오류가 발생한 이후 데이타는 삭제됨


해당 이슈가 발생하는 원인


elasticsearch는 복잡한 알고리즘으로 동작하는데, node들 중에 문제가 발생하면 해당 노드로 할당 재시도를 하게 되는데, 이과정에서 max 시도 횟수를 초과한 shard는 unassigned 상태로 남게됨. 이 상태로 변경된 샤드는 풀리지 않고 그 상태 그대로가 유지되어서 데이타 추가 유입이 되지 않은 그래서, index status 가 red 상태로 남게됨.


이슈 발생 환경


elasticsearch 3개 노드 구성의 Cluster 환경이였고, 3대를 순차적으로 재기동 하는 과정에서 3번째 서버가 기동 되지 않는 이슈가 발생함.

이후 index status 가 red 로 변하면서 모든 데이타 수집 및 조회가 안되는 상황에 빠짐.


좀더 우아한 해결 방법


  1. Index 별로 Max retries count 를 가지고 있어서 Red 상태인 Index 의 설정을 바꿔 주는 방식
    • Cluster setting 에서 cluster.routing.allocation.enable 값이 all 로 설정 변경
    • 단전 : Unassigned Shard를 일일이 설정해줘야 함.
  2. Cluster reroute 의 retry_failed 값을 true로 변경( counter 초기화 )
    • 요청 한번에 모든 설정이 적용됨
curl -XPOST http://localhost:9200/_cluster/reroute?retry_failed=true

 

참고사이트


https://www.claudiokuenzler.com/blog/847/elasticsearch-shards-fail-allocate-assign-maximum-number-retries

 

Elasticsearch: Shards fail to allocate due to maximum number of retries exceeded

A recent problem in our ELK stack this week had quite an (unexpected) impact. We experienced problems in our Docker environments (see Docker logging with GELF using tcp: The good, the bad, the ugly) and also forced myself to update the monitoring plugin ch

www.claudiokuenzler.com

https://www.datadoghq.com/blog/elasticsearch-unassigned-shards/

 

How to resolve unassigned shards in Elasticsearch

Explore six ways to investigate and resolve issues with unassigned Elasticsearch shards.

www.datadoghq.com

https://medium.com/@manis.eren/elasticsearch-issue-unassigned-shards-because-of-max-retry-24421c1d7f9c

 

Elasticsearch issue: Unassigned shards because of max_retry

Elasticsearch's shard allocation system can get complicated. When we create index, or have one of our nodes crashed, shards may go into …

medium.com