reroute
Elasticsearch에서는 기본적으로 각각의 노드에 샤드가 일정 비율로 균등하게 배치되도록 하고 있습니다. 그래도 뜻하지 않게 특정 노드에 샤드가 많이 배치될 수도 있고 어떤 인덱스는 샤드의 크기가 매우 커서 노드의 스토리지 사용량이 불균형이 발생할 수도 있습니다. 이런 경우 Elasticsearch에서 reroute를 이용하여 해당 문제를 해결할 수 있습니다.
샤드 재배치
해당 인덱스의 특정 샤드를 reroute를 이용하여 "elasticsearch-data-1"에서 "elasticsearch-data-3"노드로 이동하도록 하겠습니다.
curl -X POST http://localhost:9200/_cluster/reroute -H 'Content-Type: application/json' -d '
{
"commands": [
{
"move": {
"index": "my-log",
"shard": 0,
"from_node": "elasticsearch-data-1",
"to_node": "elasticsearch-data-3"
}
}
]
}
'
성공했을 때의 결과는 다음과 같이 출력됩니다.
{
"acknowledged": true,
"state": {
"cluster_uuid": "kvqSEAWcRiKL1Riklcqi_w",
"version": 93,
"state_uuid": "HnEEoQ3YRVSEzzme0i_5hg",
"master_node": "iWgI2xYvRYyhfhdV_TFKKQ",
"blocks": {},
"nodes": {...생략 ...},
"routing_table": {...생략 ...},
"routing_nodes": {...생략 ...},
"health": {
"disk": {
"high_watermark": "90%",
"high_max_headroom": "150gb",
"flood_stage_watermark": "95%",
"flood_stage_max_headroom": "100gb",
"frozen_flood_stage_watermark": "95%",
"frozen_flood_stage_max_headroom": "20gb"
}
}
}
}
해당 request를 처리하는데 관여한 노드의 정보와 인덱스 샤드의 대한 정보가 출력되며 disk의 설정 값까지 출력됩니다.
request를 수행하기 전과 수행한 후의 샤드의 배치 모습을 아래와 같이 그림으로 그렸습니다. 여기서 중요한 것은 "Shard 0"의 Primary shard와 Replica shard가 고가용성(HA)을 유지하기 위해서 같은 노드에 존재하게 하면 안 됩니다.
마지막으로
위에서 설명한 것처럼 샤드는 인덱스 별로 크기가 모두 다르기 때문에 스토리지 사용량을 균일하게 분배할 때 용이하게 사용할 수 있을 것 같습니다. 또한 reroute는 샤드의 재배치뿐만 아니라 특정 노드가 드롭되었을 때 샤드를 복구하는 과정에서 해당 샤드를 어디에 배치하는지에 대한 설정도 가능합니다. 자세한 내용은 아래 elasticsearch 공식 문서를 참고해 주세요
참고
Cluster reroute API | Elasticsearch Guide [8.10] | Elastic
move Move a started shard from one node to another node. Accepts index and shard for index name and shard number, from_node for the node to move the shard from, and to_node for the node to move the shard to. cancel Cancel allocation of a shard (or recovery
www.elastic.co
'Elasticsearch > Elasticsearch 설정' 카테고리의 다른 글
Elasticsearch 최적화 #2] 노드 & JVM (0) | 2023.10.03 |
---|---|
Elasticsearch 최적화 #1] 시스템 설정 (0) | 2023.10.03 |
Elasticsearch 클러스터 구조 (0) | 2023.09.30 |
Elasticsearch install in kubernetes (0) | 2023.07.31 |
Elasticsearch 7.10 버전 AWS S3 Snapshot 생성하기(in Kubernetes) (0) | 2023.07.04 |