Redis - Cluster Node Slot 분배하기

     

     

    이번 포스팅에서는 Redis Cluster reshard 명령을 통한 Master Node 추가 방법을 알아보도록 하겠습니다.

     

     

     

     

       Redis 이전글

     

     

     

     

    https://server-talk.tistory.com/471 - Redis - In-Memory - 알아보기​

     

     

    https://server-talk.tistory.com/472 - Redis - 서버 설치 및 기본설정 알아보기

     

     

    https://server-talk.tistory.com/473 - Redis - Redis-cli 기본 사용법

     

     

    https://server-talk.tistory.com/474 - Redis - Redis Desktop Manager Tool

     

     

    https://server-talk.tistory.com/475 - phpredis 설치 알아보기

     

     

    https://server-talk.tistory.com/502 - Cluster 알아보기

     

     

    https://server-talk.tistory.com/503 - Redis - Cluster Master Node 구성하기

     

     

    https://server-talk.tistory.com/504 - Redis - Cluster Master Node 관련 설정 알아보기

     

     

    https://server-talk.tistory.com/505 - Redis - Master Node - Cluster 상태정보 확인

     

     

    https://server-talk.tistory.com/506 - Redis - Slave Note Cluster 구성하기

     

     

    https://server-talk.tistory.com/507 - Redis - Master Note와 Slave Cluster 연동 상태 알아보기

     

     

    https://server-talk.tistory.com/508 - Redis - Cluster - hash slot 알아보기

     

     

     

     

       Redis - Cluster Reshard 란?

     

     

     

     

    Redis 에서 Cluster 를 이용하다가 서비스가 더 커진다면 Master Node를 더 추가해야됩니다 이때 reshard 명령을 사용하여 Node 를 추가할 수 있는데 reshard 명령은 다음과 같이 장/단점이 있으므로 참고하셔야 됩니다.

     

     

     

     

     

     

    Redis Cluster의 Reshard 명령은 추가한 Cluster Node의 Slot 을 할당하거나 다른 Master Node로 Slot을 이동할 수 있습니다 그리고 특정 Node의 ID를 지정하여 운영 중인 Node에서 Slot을 분배할 수 있습니다.

     

    그러나 Redis Cluster의 reshard 명령은 추가한 Cluster Node 의 Slot의 범위를 지정할 수 없고 Master Node에서만 지정할 수 있는점이 있습니다.

     

     

     

     

       Redis - Cluster Node Slot 분배 - RESHARD

     

     

     

     

    1. Redis - Cluster Node Slot 할당정보 확인

     

    CLUSTER SLOTS

     

    Cluster의 Master Node와 Slave Node 할당되어 있는 Node IP, Node Port, Node ID, Node Slot 정보를 확인합니다.

     

     

     

     

    2. Redis - Cluster Master Node 설정파일 생성

     

    cp /etc/redis/redis.conf 7300-cluster.conf

     

     

     

     

    3. Redis - Cluster 추가 Master Node 설정파일 수정

     

    vi 7300-cluster.conf
    
    port 7300
    daemonize yes
    cluster-enabled yes 
    cluster-config-file nodes-7300.conf 
    cluster-node-timeout 3000 
    appendonly yes 
    appendfilename appendonly_7300.aof 
    pidfile /var/run/redis_7300.pid
    logfile logs/redis_7300.log

     

     

     

     

    4. Redis - Cluster 추가 Master Node 실행

     

    명령어 redis-server [New Cluster Master Node]

     

    redis-server 7300-cluster.conf

     

     

     

     

    5. Redis - Cluster Master Node 추가하기

     

    명령어 : redis-cli --cluster add-node [생성한 Master Node] [기존 Master Node]

     

    redis-cli --cluster add-node 127.0.0.1:7300 127.0.0.1:7000

     

     

     

     

    6. Redis - 추가된 Cluster Master Node 확인하기

     

    명령어 : redis-cli --cluster check [기존 Master Node]

     

    redis-cli --cluster check 127.0.0.1:7000
    127.0.0.1:7000 (52f11541...) -> 3 keys | 5461 slots | 1 slaves.
    127.0.0.1:7200 (41018c69...) -> 1 keys | 5461 slots | 1 slaves.
    127.0.0.1:7100 (d1e5ba49...) -> 1 keys | 5462 slots | 1 slaves.
    127.0.0.1:7300 (a77e022d...) -> 0 keys | 0 slots | 0 slaves.

     

    추가된 마스터 노드 정보를 확인합니다(하지만 슬롯이 지정되지 않아 0으로 표시됩니다)

     

     

     

     

    7. Redis - Cluster Master Node - 슬롯의 나누기

     

    명령어 : redis-cli --cluster reshard [기존 Master Node] --cluster-yes

     

    redis-cli --cluster reshard 127.0.0.1:7000 --cluster-yes

     

    Slot을 나눌 Master Node를 지정하는 부분 입니다

     

     

     

     

    8. Redis - Cluster Master Node - 슬롯 할당 개수

     

    How many slots do you want to move (from 1 to 16384)? 2000

     

    지정한 Master Node의 Slot 의 개수를 몇개를 할당할지의 개수를 지정하는 부분 입니다.

     

     

     

     

    9. Redis - Cluster Master Node - 슬롯을 이동하게될 Master ID 입력

     

    What is the receiving node ID? [생성한 Master Node ID]

     

    What is the receiving node ID? a77e022d669e3bc8f0fc1b0099fb606b67b55f44

     



     

    10. Redis - Cluster Master Node - 슬롯을 삭제하게될 Master ID 입력

     

    Source node  #1: [기존 Master Node(슬롯을 나눌 Node)]
    Source node  #2: done

     

    Source node  #1: 52f11541320cab2ef73954a2de65da19f10c6099
    Source node  #2: done

     

    all을 지정할경우 전체에서 재분배하게 됩니다.

     

     

     

     

    11. Redis - Cluster Master Node - 분배된 슬롯확인

     

    # redis-cli --cluster check 127.0.0.1:7000 -a foobared
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    127.0.0.1:7000 (52f11541...) -> 3 keys | 3461 slots | 1 slaves.
    127.0.0.1:7200 (41018c69...) -> 1 keys | 5461 slots | 1 slaves.
    127.0.0.1:7100 (d1e5ba49...) -> 1 keys | 5462 slots | 1 slaves.
    127.0.0.1:7300 (a77e022d...) -> 0 keys | 2000 slots | 0 slaves.

     

    Posted by 서버이야기