본문 바로가기
개발

[elasticsearch] maximum normal shards open 에러

by eun2ce 2022. 9. 7.

팀 내에 운영중인 kibana 에서 특정 일자 이후로 로그가 보이지 않는 문제가 있었다.

filebeat 와 logstash 는 정상동작 중이었고, logstash 에서 elasticsearch 로 index 할 때 아래와 같은 에러가 발생했다.

 

{"index"=>{"_index"=>"applog-2022.09.06", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"illegal_argument_exception", "reason"=>"Validation Failed: 1: this action would add [2] shards, but this cluster currently has [2000]/[2000] maximum normal shards open;"}

 

노드당 최대 shard 개수(cluster.max_shards_per_node)가 1000개인데 1000개가 모두 열려있었다.

$ curl -s -XGET ${ELK_HOST}/_cluster/stats?filter_path=indices.shards.total

{
  "indices" : {
    "shards" : {
      "total" : 2000
    }
  }
}

 

원인이 이게 맞는지 보기 위해서 일단 노드 당 shard 개수를 늘려주었다.

curl -XPUT  "${ELK_HOST}:9200/myindex/_settings?pretty" -H 'Content-Type: application/json' -d' {
    "index" : {
        "number_of_shards" : 3, 
        "number_of_replicas" : 0 
    }
}

elasticsearch 에 event 가 정상적으로 index 되는지 확인.

$ curl -s -XGET ${ELK_HOST}:9200/_cat/shards | wc -l
2033

위 결과로 샤드 개수가 2000보다 늘어난 것을 알 수 있다.

 

그러나 샤드를 늘려주는 것이 근본적인 해결 방법이 아니므로, elasticsearch curator 를 설치.

curator 는 인덱스 es 의 인덱스 라이프 사이클을 관리하기 위한 기능을 제공한다.

 

즉, 주기를 정해놓고 자동으로 오래된 인덱스를 삭제해주는 것이다.

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.8/about.html

 

About | Curator Reference [5.8] | Elastic

Elasticsearch Curator helps you curate, or manage, your Elasticsearch indices and snapshots by: Obtaining the full list of indices (or snapshots) from the cluster, as the actionable list Iterate through a list of user-defined filters to progressively remov

www.elastic.co

 

추가로, 필자가 사용중인 es는 버전이 낮아 위에 있는 curator 를 사용했지만 많은 stack 컴포넌트가 ILM 을 기본으로 적용 되어 있다.

 

beats

* 모든 비트는 동일한 ILM 설정을 공유

 

Logstash

* Index Lifecycle Management 기능은 logstash-output-elasticsearch 플러그인의 9.3.1 이상의 버전을 필요로 한다.

Index Lifecycle Management는 ilm_enable 설정을 통해 동작하며, 자동적으로 elasticsearch 인스턴스가 ILM을 지원 유무를 확인한다.

 

ILM 과 curator

큐레이터는 ILM 정책 중 allow_ilm_indices 옵션이 true로 설정되어 있지 않은 인덱스에는 동작하지 않는다.

큐레이터와 ilm 은 공존 가능하다.

하지만 큐레이터가 방해하거나, ilm 정책과 충돌나는 것을 방지하기 위해, ilm 정책과 연관된 인덱스는 기본적으로 설정에서 제외되어 있다.

 

큐레이터는 allow_ilm_indices 설정되어 있는 인덱스들에게만 동작할 수 있다.

 

 

참고

https://discuss.elastic.co/t/validation-failed-1-this-action-would-add-2-total-shards-but-this-cluster-currently-has-2000-2000-maximum-shards-open/257064/3