[elasticsearch] ElasticSearch : 할당되지 않은 샤드, 수정 방법?

노드가 4 개인 ES 클러스터가 있습니다.

number_of_replicas: 1
search01 - master: false, data: false
search02 - master: true, data: true
search03 - master: false, data: true
search04 - master: false, data: true

search03을 다시 시작해야했고 다시 돌아 왔을 때 클러스터에 아무런 문제가 없었지만 할당되지 않은 샤드 7 개를 남겨 두었습니다.

{
  "cluster_name" : "tweedle",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 4,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 15,
  "active_shards" : 23,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 7
}

이제 클러스터가 노란색 상태입니다. 이 문제를 해결하는 가장 좋은 방법은 무엇입니까?

  • 샤드를 삭제 (취소) 하시겠습니까?
  • 샤드를 다른 노드로 이동 하시겠습니까?
  • 샤드를 노드에 할당 하시겠습니까?
  • ‘number_of_replicas’를 2로 업데이트 하시겠습니까?
  • 완전히 다른 것?

흥미롭게도, 새로운 인덱스가 추가되었을 때, 그 노드는 그 노드에서 작업을 시작했고 클러스터의 나머지 부분과 잘 어울 렸습니다.

질문에 따르십시오. 처음에 이런 일이 발생하도록 잘못하고 있습니까? 노드가 다시 시작될 때 이런 식으로 동작하는 클러스터에 대해서는 확신이 없습니다.

참고 : 어떤 이유로 단일 노드 클러스터를 실행중인 경우 다음을 수행하면됩니다.

curl -XPUT 'localhost:9200/_settings' -d '
{
    "index" : {
        "number_of_replicas" : 0
    }
}'



답변

기본적으로 Elasticsearch는 샤드를 노드에 동적으로 다시 할당합니다. 그러나 샤드 할당을 비활성화 한 경우 ( 롤링 재시작 을 수행 한 다시 활성화하지 않은 경우) 샤드 할당을 다시 활성화 할 수 있습니다.

# v0.90.x and earlier
curl -XPUT 'localhost:9200/_settings' -d '{
    "index.routing.allocation.disable_allocation": false
}'

# v1.0+
curl -XPUT 'localhost:9200/_cluster/settings' -d '{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}'

그러면 Elasticsearch는 샤드를 정상적으로 재 할당합니다. 이 모금 고려 느릴 수 있습니다 indices.recovery.max_bytes_per_seccluster.routing.allocation.node_concurrent_recoveries 그것을 속도.

여전히 문제가 발생하면 다른 문제가있을 수 있으므로 Elasticsearch 로그에서 오류를 찾으십시오. 당신이 볼 경우 EsRejectedExecutionException스레드 풀은 너무 작은 수 있습니다 .

마지막으로 reroute API를 사용하여 샤드를 노드에 명시 적으로 재 할당 할 수 있습니다 .

# Suppose shard 4 of index "my-index" is unassigned, so you want to
# assign it to node search03:
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
    "commands": [{
        "allocate": {
            "index": "my-index",
            "shard": 4,
            "node": "search03",
            "allow_primary": 1
        }
    }]
}'


답변

좋아, 나는 ES 지원의 도움으로 이것을 해결했다. 모든 노드 (또는 문제의 원인으로 생각되는 노드)에서 API에 다음 명령을 실행하십시오.

curl -XPUT 'localhost:9200/<index>/_settings' \
    -d '{"index.routing.allocation.disable_allocation": false}'

<index>범인으로 생각되는 지수는 어디에 있습니까 ? 모르는 경우 모든 노드에서 실행하십시오.

curl -XPUT 'localhost:9200/_settings' \
    -d '{"index.routing.allocation.disable_allocation": false}'

또한이 줄을 yaml 구성에 추가 한 후 서버 / 서비스를 다시 시작할 때 문제가 없었습니다. 샤드가 즉시 다시 할당되었습니다.

FWIW, 자주 묻는 질문에 대답하려면 컴퓨터에 RAM이 60G 미만인 경우를 제외하고 MAX_HEAP_SIZE를 30G로 설정하십시오.이 경우 사용 가능한 메모리의 절반으로 설정하십시오.

참고 문헌


답변

이 작은 bash 스크립트는 강제로 재 할당을 수행하므로 데이터가 손실 될 수 있습니다.

NODE="YOUR NODE NAME"
IFS=$'\n'
for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep UNASSIGNED); do
  INDEX=$(echo $line | (awk '{print $1}'))
  SHARD=$(echo $line | (awk '{print $2}'))

  curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
     "commands": [
        {
            "allocate": {
                "index": "'$INDEX'",
                "shard": '$SHARD',
                "node": "'$NODE'",
                "allow_primary": true
          }
        }
    ]
  }'
done


답변

나를 위해 일한 유일한 것은 number_of_replicas를 변경하는 것입니다 (복제본이 2 개 있었으므로 1로 변경 한 다음 다시 2로 변경했습니다).

먼저:

PUT /myindex/_settings
{
    "index" : {
        "number_of_replicas" : 1
     }
}

그때:

PUT /myindex/_settings
{
    "index" : {
        "number_of_replicas" : 2
     }
}

(나는 이미이 질문에 그것을 놀라게 했다 )


답변

아래 구성이 모두로 설정되어 있으면 Elasticsearch에서 자동으로 샤드를 할당합니다. 이 구성은 cluster.routing.allocation.enable 및 rest api를
사용하여 설정할 수 있습니다 .

아래 구성을 적용한 후에도 es가 샤드를 자동으로 할당하지 못하면 샤드를 직접 할당해야합니다. 이에 대한 ES 공식 링크

클러스터에서 할당되지 않은 모든 샤드를 강제로 할당하는 스크립트를 작성했습니다.

아래 배열에는 할당되지 않은 샤드의 균형을 유지하려는 노드 목록이 포함되어 있습니다.

#!/bin/bash
array=( node1 node2 node3 )
node_counter=0
length=${#array[@]}
IFS=$'\n'
for line in $(curl -s 'http://127.0.0.1:9200/_cat/shards'|  fgrep UNASSIGNED); do
    INDEX=$(echo $line | (awk '{print $1}'))
    SHARD=$(echo $line | (awk '{print $2}'))
    NODE=${array[$node_counter]}
    echo $NODE
    curl -XPOST 'http://127.0.0.1:9200/_cluster/reroute' -d '{
        "commands": [
        {
            "allocate": {
                "index": "'$INDEX'",
                "shard": '$SHARD',
                "node": "'$NODE'",
                "allow_primary": true
            }
        }
        ]
    }'
    node_counter=$(((node_counter)%length +1))
done


답변

나는 오늘 같은 샤드 할당 문제를 고수했다. W. Andrew Loe III 가 그의 대답에서 제안한 스크립트는
저에게 효과적이지 않으므로 조금 수정하여 마침내 작동했습니다.

#!/usr/bin/env bash

# The script performs force relocation of all unassigned shards,
# of all indices to a specified node (NODE variable)

ES_HOST="<elasticsearch host>"
NODE="<node name>"

curl ${ES_HOST}:9200/_cat/shards > shards
grep "UNASSIGNED" shards > unassigned_shards

while read LINE; do
  IFS=" " read -r -a ARRAY <<< "$LINE"
  INDEX=${ARRAY[0]}
  SHARD=${ARRAY[1]}

  echo "Relocating:"
  echo "Index: ${INDEX}"
  echo "Shard: ${SHARD}"
  echo "To node: ${NODE}"

  curl -s -XPOST "${ES_HOST}:9200/_cluster/reroute" -d "{
    \"commands\": [
       {
         \"allocate\": {
           \"index\": \"${INDEX}\",
           \"shard\": ${SHARD},
           \"node\": \"${NODE}\",
           \"allow_primary\": true
         }
       }
     ]
  }"; echo
  echo "------------------------------"
done <unassigned_shards

rm shards
rm unassigned_shards

exit 0

이제 저는 Bash 전문가가 아니지만 스크립트가 실제로 제 경우에 효과적이었습니다. “ES_HOST”및 “NODE”변수에 적절한 값을 지정해야합니다.


답변

필자의 경우 하드 디스크 공간 상한에 도달했습니다.

이 기사를보십시오 : https://www.elastic.co/guide/en/elasticsearch/reference/current/disk-allocator.html

기본적으로, 나는 달렸다.

PUT /_cluster/settings
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "90%",
    "cluster.routing.allocation.disk.watermark.high": "95%",
    "cluster.info.update.interval": "1m"
  }
}

따라서 <90 % 하드 디스크 공간이 사용 된 경우 할당하고> 95 % 하드 디스크 공간이 사용되는 경우 샤드를 클러스터의 다른 시스템으로 이동합니다. 1 분마다 확인합니다.