2025. 8. 14. 14:43ㆍBig Data
elasticsearch version upgrade
클러스터로 구성된 es의 버전을 업그레이드 하는 방법으로는 모든 es node를 다 중지한 후 업그레이드 하는 방식과 클러스터로 구성된 node를 하나씩 중지한 후 es 버전 업그레이드 한 후 클러스터에 다시 조인시키는 방법이 있다.
두 번째 방법에 대해 설명하고자 한다.
우선 es 버전 업그레이드를 하기 위해서는 아래의 버전 규칙을 따라야 한다.
5.6 이하 버전인 경우 : es 5.6 버전으로 업그레이드 -> 6.8 버전으로 업그레이드 -> 7.8 버전으로 업그레이드
5.6 이상 6.8 이하인 경우 : 6.8 버전으로 업그레이드 -> 7.8 버전으로 업그레이드
6.8 이상 7.8 이하인 경우 : 7.8 버전으로 업그레이드
1. 업그레이드를 하기 전에 es cluster내의 샤드가 재분배 되는 것을 막기 위해 cluster.routing.allocation을 disable 시킨다.
$> curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent" : {
"cluster.routing.allocation.enable": "none"
}
}
'
2. primary shard와 replica shard의 데이터를 일치시킨다.
$> curl -X POST "localhost:9200/_flush/synced?pretty" -H 'Content-Type: application/json'
3. 위와 같이 설정이 끝났다면 이제 업그레이드 하고자 하는 es node로 들어가서 es process를 중지 시킨다. 이 후 업그레이드 하고자 하는 버전으로 es를 업그레이드 한 후 es 프로세스를 다시 구동시킨다.
4. 재구동한 node가 es cluster에 합류가 되었다고 하더라도 shard는 분배가 안되어 있는 걸 확인 할 수가 있다. cluster.routing.allocation을 disable 시켰기 때문에 shard 재분배가 이루어지지 않는 것이다. 해당 옵션을 원래대로 되돌린다.
$> curl -X PUT "localhost:9200/_cluster/seetings?pretty" -H 'Content-Type: application/json -d'
{
"persistent": {
"cluster.routing.allocation.enable": null
}
}
'
cluster.routing.allocation.enable을 null로 설정하게 되면 default 값으로 동작이 된다. default 값은 all이다.
해당 설정 값들은 아래의 표와 같다.
all | 모든 shard에 대해 배치 활성화. 기본값 |
primaries | primary shard만 배치 활성화. replica shard는 한번 배치된 후 재배치 되지 않는다. |
new_primaries | 새롭게 생성되는 index에 대해서만 primary shard 배치 활성화. 새롭게 투입된 node에 기존 index의 shard가 배치되지 않는다. |
none | 모든 shard의 대해 배치 비활성화 |
null | 기존에 적용된 설정 값 삭제. default인 all로 설정 |
위의 1~4번 작업을 업그레이드 하려는 모든 노드에 순차적으로 진행해 준다. 이렇게 하면 es upgrade가 성공적으로 종료된다.
shard assignment
version upgrade와 함께 shard도 수동으로 배치를 지정할 수가 있다. 기본적으로는 es에서 자동으로 배치가 되지만 특정 노드에 해당 shard를 지정하고 싶은 경우에 shard를 수동으로 배치 할 수가 있다.
$> curl -X POST "localhost:9200/_cluster/reroute?pretty" -H 'Content-Type: application/json' -d'
{
"commands": [
{
"move": {
"index": "test",
"shard": 1,
"from_node": "test1.com",
"to_node": "test2.com"
}
}
]
}
'
위와 같이 reroute를 사용하면 test1.com에 있는 test index의 1번 shard가 test2.com으로 이동한다.
cancel 명령을 사용하여 이동을 취소할 수도 있다.
$> curl -X POST "localhost:9200/_clsuter/reroute?pretty" -H 'Content-Type: application/json -d'
{
"commands": [
{
"cancel": {
"index": "test",
"shard": 1,
"node": "test2.com"
}
}
]
}
'
shard의 자동 배치와 관련해서는 위에서 언급한 cluster.routing.allocation.enable와 cluster.routing.rebalance.enable를 통해서 자동배치를 할 수가 있다.
cluster.routing.allocation.enable
$> $> curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent" : {
"cluster.routing.allocation.enable": "all"
}
}
'
cluster.routing.rebalance.enable
$> curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent" : {
"cluster.routing.rebalance.enable": "all"
}
}
'
shard의 자동 배치는 언제 이루어지게 될까?
cluster.routing.allocation.disk.threshold_enabled 설정이 true이면 es node 중 한 대라도 디스크 사용이 threshold를 넘어가게 된다면 동작하게 된다.
먼저 disk 사용률이 cluster.routing.allocation.disk.watermark.low 보다 커진다면 해당 node에는 기존 index의 shard들을 더 이상 배치하지 않는다. 하지만 새롭게 생성된 index의 shard 들은 배치한다.
그리고 점점 사용률이 높아져서 cluster.routing.allocation.disk.water.amrk.high 보다 값이 커진다면 해당 node의 shard 들을 다른 node로 rebalance를 진행한다.
마지막으로 cluster.routing.allocation.disk.watermark.fllod_stage의 값보다 커진다면, 해당 node가 가지고 있는 shard의 모든 index들을 읽기 모드로 전환한다.
임계치 설정은 아래와 같이 진행한다.
$> curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent": {
"cluster.routing.allocation.disk.watermark.low": "75%",
"cluster.routing.allocation.disk.watermark.high": "85%",
"cluster.routing.allocation.disk.watermark.flood_stage": "90%",
"cluster.info.update.interval": "1m"
}
}
'
한 번 읽기 모드로 변경이 되면, node를 추가하더라도 자동으로 쓰기 모드로 원상 복구가 안된다. node 추가 후 아래와 같이 명령어를 호출해야 한다.
$> curl -X PUT "localhost:9200/_all/_settings?pretty" -H 'Content-Type: application/json' -d'
{
"index.blocks.read_only_allow_delete" : null
}
'