Redis CLUSTER Redis-trib 사용법

Redis Cluster Course Redis Technical Support Redis Enterprise Server

CLUSTER   Redis-trib 사용법

Redis-trib.rb는 Redis version 5.0 부터 Redis-cli로 대체되었습니다.

이 문서는 버전 4.0.9를 기준으로 작성했습니다.

명령 설명

  • create   클러스터를 생성한다. replicas를 지정해서 슬레이브 개수를 지정할 수 있다.
  • reshard   슬롯을 노드에 할당 또는 재할당한다. Source 노드와 destination 노드를 지정한다.
  • add-node   클러스터에 노드를 추가한다. 마스터 또는 슬레이브로 추가할 수 있다.
  • del-node   클러스터에서 노드를 제거한다.
  • info   클러스터 정보를 조회한다.
  • import   Standalone 노드에서 클러스터로 데이터를 가져온다.
  • rebalance   슬롯을 균형있게 재 분배한다.
  • check   클러스터를 체크한다.
  • call   클러스터 노드에 명령을 실행한다.
  • set-timeout   클러스터 노드에 cluster-node-timeout을 설정한다.
  • help   도움말을 보여준다.

redis-trib CREATE

  • 클러스터를 생성한다.
  • 명령   redis-trib.rb create [--replicas n] ip1:port1 ... ipn:portn
  • --replicas n   마스터 당 슬레이브 노드를 몇 개 만들지를 정한다.   생략하거나 0으로 설정하면 슬레이브 노드를 만들지 않고 마스터로만 클러스터를 구성한다.  
  • ip1:port1 ... ipn:portn   클러스터에 참여할 레디스 노드들의 ip:port를 입력한다.   명령을 실행하는 머신과 같은 ip를 사용해도 ip는 반드시 입력해야 한다.
  • Standalone mode로 시작한 레디스는 클러스터에 참여할 수 없다.   지정한 ip:port 가 standalone mode면 Redis-trib는 종료한다.
  • DB에 데이터가 있으면 클러스터를 생성하지 못하고 종료한다.   그러므로 클러스터를 생성할 노드는 AOF 나 RDB로 부터 데이터를 읽어들이면 안된다.   Cluster mode로 시작한 레디스는 클러스터가 구성되지 않은 상태에서는 set 명령같은 데이터를 입력/수정/삭제/조회하는 명령을 수행할 수 없다.   하지만 Flushdb 또는 flushall 명령은 실행가능하다. 이 명령을 실행해서 데이터를 모두 삭제했어도 클러스터는 구성되지 않는다. 처음부터 데이터를 읽어 들이지 않는 방법이 가장 좋다.
  • 레디스 노드는 최소 3개 이상을 지정해야 한다.   Replicas를 0으로 지정하면 참여한 노드가 모두 마스터가 된다.   Replicas를 1로 지정하면 최소 마스터-슬레이브 3쌍으로 구성되어 6노드 이상이 있어야 한다.   Cluster 명령을 직접 사용하면 이러한 제한은 없어서, 1개 노드로도 클러스터를 만들 수 있다.
  • IP가 같은 경우 클러스터 구성   IP가 같으면 명령에 지정된 순서대로 마스터와 슬레이브가 정해진다.
  • 다음과 같이 replicas 1로 지정하고 5001부터 5006까지 포트를 지정하면 아래와 같이 구성된다.
  • $ src/redis-trib.rb create --replicas 1 127.0.0.1:5001 127.0.0.1:5002 127.0.0.1:5003 127.0.0.1:5004 127.0.0.1:5005 127.0.0.1:5006
    Redis Cluster Create redis_trib
  • replicas 2로 지정하고 9개 노드를 지정하면 다음과 같이 구성된다.
  • Redis Cluster Create redis-trib replicas 2
  • 3개 IP에 레디스 노드 2개씩 지정하고 replicas 1로 하면 다음과 같이 구성된다.   세번째 박스(IP 105번)는 한 박스안에 마스터, 슬레이브가 구성되었으므로 이 박스가 다운되면 클러스터가 다운되는 상황이 된다.
  • Redis Cluster Create redis_trib 3boxes 6nodes
  • redis-trib가 클러스터 구성을 잘 하려고 하지만, 완벽하지 않아서 위와 같은 상황이 발생할 수 있으므로, 세밀한 구성을 위해서는 클러스터 명령으로 직접 구성하는 것이 좋은 방법이다.
  • redis-trib로 create했을때 구성 형태에 대한 자세한 내용은 여기를 보세요.   레디스 클러스터 자동 구성 형태
  • 다음은 6개 노드로 마스터 3, 슬레이브 3으로 구성했을때 나오는 메시지입니다.
  • $ src/redis-trib.rb create --replicas 1 127.0.0.1:5001 127.0.0.1:5002 127.0.0.1:5003 127.0.0.1:5004 127.0.0.1:5005 1
    >>> Creating cluster
    >>> Performing hash slots allocation on 6 nodes...
    Using 3 masters:
    127.0.0.1:5001
    127.0.0.1:5002
    127.0.0.1:5003
    Adding replica 127.0.0.1:5005 to 127.0.0.1:5001
    Adding replica 127.0.0.1:5006 to 127.0.0.1:5002
    Adding replica 127.0.0.1:5004 to 127.0.0.1:5003
    >>> Trying to optimize slaves allocation for anti-affinity
    [WARNING] Some slaves are in the same host as their master
    M: d8403c218cd01bba763cac3f2a1d52f9eeaa6c41 127.0.0.1:5001
       slots:0-5460 (5461 slots) master
    M: bcc81e34e1e340bb65e86ee21c4a0beb0eb5fd3a 127.0.0.1:5002
       slots:5461-10922 (5462 slots) master
    M: 8175f1014de7c9843c8ed0333a7ea39b5ede528a 127.0.0.1:5003
       slots:10923-16383 (5461 slots) master
    S: 8e639d47ad4a3081544cf6617d5d365e25a555db 127.0.0.1:5004
       replicates bcc81e34e1e340bb65e86ee21c4a0beb0eb5fd3a
    S: 6601c60e136244758d7188c7b16f7b4a2ff3743a 127.0.0.1:5005
       replicates 8175f1014de7c9843c8ed0333a7ea39b5ede528a
    S: b28885073d81b53843d058c39eb2c435524bf56c 127.0.0.1:5006
       replicates d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
    Can I set the above configuration? (type 'yes' to accept): yes
    >>> Nodes configuration updated
    >>> Assign a different config epoch to each node
    >>> Sending CLUSTER MEET messages to join the cluster
    Waiting for the cluster to join...
    >>> Performing Cluster Check (using node 127.0.0.1:5001)
    M: d8403c218cd01bba763cac3f2a1d52f9eeaa6c41 127.0.0.1:5001
       slots:0-5460 (5461 slots) master
       1 additional replica(s)
    M: bcc81e34e1e340bb65e86ee21c4a0beb0eb5fd3a 127.0.0.1:5002
       slots:5461-10922 (5462 slots) master
       1 additional replica(s)
    S: 8e639d47ad4a3081544cf6617d5d365e25a555db 127.0.0.1:5004
       slots: (0 slots) slave
       replicates bcc81e34e1e340bb65e86ee21c4a0beb0eb5fd3a
    S: 6601c60e136244758d7188c7b16f7b4a2ff3743a 127.0.0.1:5005
       slots: (0 slots) slave
       replicates 8175f1014de7c9843c8ed0333a7ea39b5ede528a
    S: b28885073d81b53843d058c39eb2c435524bf56c 127.0.0.1:5006
       slots: (0 slots) slave
       replicates d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
    M: 8175f1014de7c9843c8ed0333a7ea39b5ede528a 127.0.0.1:5003
       slots:10923-16383 (5461 slots) master
       1 additional replica(s)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.

redis-trib RESHARD

  • Redis 버전 3.0.6 ~ 3.2.6 사용자는 반드시 그 이후 버전으로 Upgrade하세요.
    Reshard 시 expire time 설정 오류로 expire time이 설정되지 않은 key가 삭제될 수 있습니다.
    임시 방편으로 redis-trib.rb 소스에서 MigrateDefaultPipeline = 10을 1로 바꾸세요.

    참고자료: Redis-trib.rb move_slot function generator error result #3655
                      Reset the ttl for additional keys #3673
  • 슬롯을 재할당한다. 슬롯과 데이터를 같이 옮겨준다.
  • 명령   redis-trib.rb reshard ip:port
  • ip:port는 접속해서 작업할 노드이다. Reshard 할 source 노드나 destination 노드로 접속할 필요는 없다.
  • Reshard는 새 노드를 추가했을때 그 노드에 슬롯을 할당하기 위해 사용하거나, 기존 노드의 슬롯을 다른 노드로 옮길때 사용한다.   Reshard 명령은 destination 노드로 데이터를 migrate 명령으로 옮긴다.
  • 새 노드의 경우는 rebalance 명령을 사용하는 것도 좋은 방법이다.
  • Source 노드는 1개 이상 또는 모두를 지정할 수 있고, destination 노드는 하나만 지정한다.   옮길 슬롯의 개수를 지정한다. 특정 슬롯을 지정하거나 특정 범위를 지정할 수 없다.
  • 다음은 reshard할때 나오는 메시지이다. 옮길 슬롯의 갯수만큼 메시지가 나오므로, 여기서는 5 슬롯만 지정했다.   Source node #1 에서 all을 입력하면 모든 노드로 부터 슬롯을 받는다.   특정 노드 id를 여러개 입력할 수 있다. 모두 입력했으면 done를 입력한다.   Source node 와 Destination(Receiving) node 모두 마스터 노드만 지정해야 된다. 슬레이브 노드는 지정할 수 없다.   입력해야 될 부분은 굵게 표시했다.
  • $ src/redis-trib.rb reshard 127.0.0.1:5001
    >>> Performing Cluster Check (using node 127.0.0.1:5001)
    M: d8403c218cd01bba763cac3f2a1d52f9eeaa6c41 127.0.0.1:5001
       slots:0-5460 (5461 slots) master
       1 additional replica(s)
    M: bcc81e34e1e340bb65e86ee21c4a0beb0eb5fd3a 127.0.0.1:5002
       slots:5461-10922 (5462 slots) master
       1 additional replica(s)
    S: 8e639d47ad4a3081544cf6617d5d365e25a555db 127.0.0.1:5004
       slots: (0 slots) slave
       replicates bcc81e34e1e340bb65e86ee21c4a0beb0eb5fd3a
    S: 6601c60e136244758d7188c7b16f7b4a2ff3743a 127.0.0.1:5005
       slots: (0 slots) slave
       replicates 8175f1014de7c9843c8ed0333a7ea39b5ede528a
    S: b28885073d81b53843d058c39eb2c435524bf56c 127.0.0.1:5006
       slots: (0 slots) slave
       replicates d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
    M: 8175f1014de7c9843c8ed0333a7ea39b5ede528a 127.0.0.1:5003
       slots:10923-16383 (5461 slots) master
       1 additional replica(s)
    
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    How many slots do you want to move (from 1 to 16384)? 5
    What is the receiving node ID? 8175f1014de7c9843c8ed0333a7ea39b5ede528a
    Please enter all the source node IDs.
    Type 'all' to use all the nodes as source nodes for the hash slots.
    Type 'done' once you entered all the source nodes IDs.
    Source node #1:d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
    Source node #2:done
    Ready to move 5 slots.
      Source nodes:
        M: d8403c218cd01bba763cac3f2a1d52f9eeaa6c41 127.0.0.1:5001
       slots:0-5460 (5461 slots) master
       1 additional replica(s)
      Destination node:
        M: 8175f1014de7c9843c8ed0333a7ea39b5ede528a 127.0.0.1:5003
       slots:10923-16383 (5461 slots) master
       1 additional replica(s)
      Resharding plan:
        Moving slot 0 from d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
        Moving slot 1 from d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
        Moving slot 2 from d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
        Moving slot 3 from d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
        Moving slot 4 from d8403c218cd01bba763cac3f2a1d52f9eeaa6c41
    Do you want to proceed with the proposed reshard plan (yes/no)? yes
    Moving slot 0 from 127.0.0.1:5001 to 127.0.0.1:5003: 
    Moving slot 1 from 127.0.0.1:5001 to 127.0.0.1:5003: 
    Moving slot 2 from 127.0.0.1:5001 to 127.0.0.1:5003: 
    Moving slot 3 from 127.0.0.1:5001 to 127.0.0.1:5003: 
    Moving slot 4 from 127.0.0.1:5001 to 127.0.0.1:5003: 
    

redis-trib ADD-NODE

  • 클러스터에 노드를 추가한다. 마스터 또는 슬레이브로 추가할 수 있다.
  • 명령   redis-trib.rb add-node [--slave] [--master-id id] new_ip:port existing_ip:port
  • --slave   새 노드를 슬레이브로 추가할 때 사용한다. 지정하지 않으면 마스터로 추가된다.
  • --master-id id   slave 옵션을 사용했을때 마스터 노드 ID를 지정한다. 생략할 수 있다. 생략하면 existing_ip:port 노드의 슬레이브가 된다.
  • new_ip:port   추가할 ip:port를 지정한다. Cluster mode로 시작되어 있어야 하고, 데이터가 없어야 한다.
  • existing_ip:port   접속해서 작업할 기존 노드를 지정한다.
  • 다음은 5007번 노드를 마스터로 클러스터에 등록하는 명령과 메시지이다.   중간에 입력해야 하는 것은 없다.   이후에 reshard 또는 rebalance 명령으로 슬롯을 할당해야 마스터로서 역할을 수행할 수 있다.
  • $ src/redis-trib.rb add-node 127.0.0.1:5007 127.0.0.1:5001
    >>> Adding node 127.0.0.1:5007 to cluster 127.0.0.1:5001
    >>> Performing Cluster Check (using node 127.0.0.1:5001)
    [클러스터 정보 출력하는 부분은 생략합니다]
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    >>> Send CLUSTER MEET to node 127.0.0.1:5007 to make it join the cluster.
    [OK] New node added correctly.
  • Info 명령으로 추가된 노드 확인
  • $ src/redis-trib.rb info 127.0.0.1:5001
    127.0.0.1:5001 (d8403c21...) -> 0 keys | 5456 slots | 1 slaves.
    127.0.0.1:5002 (bcc81e34...) -> 0 keys | 5462 slots | 1 slaves.
    127.0.0.1:5007 (c5e4c752...) -> 0 keys | 0 slots | 0 slaves.
    127.0.0.1:5003 (8175f101...) -> 0 keys | 5466 slots | 1 slaves.
    [OK] 0 keys in 4 masters.
    0.00 keys per slot on average.
  • 다음은 5007번 노드를 5002의 슬레이브로 등록하는 명령이다. 접속(작업) 노드와 마스터 노드가 같을 경우 사용합니다.
  • 테스트할 때는 5007번 노드를 redis-trib.rb del-node로 클러스터에서 제거한 다음, 5007번의 nodes.conf 파일을 지우고, 서버를 재 시작한 후 아래 명령을 실행한다.
  • $ src/redis-trib.rb add-node --slave 127.0.0.1:5007 127.0.0.1:5002
    >>> Adding node 127.0.0.1:5007 to cluster 127.0.0.1:5002
    >>> Performing Cluster Check (using node 127.0.0.1:5002)
    [클러스터 정보 출력하는 부분은 생략합니다]
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    Automatically selected master 127.0.0.1:5002
    >>> Send CLUSTER MEET to node 127.0.0.1:5007 to make it join the cluster.
    Waiting for the cluster to join.
    >>> Configure node as replica of 127.0.0.1:5002.
    [OK] New node added correctly.
  • 다음은 master-id 옵션을 지정한 명령 예이다. 접속(작업) 노드와 마스터 노드가 다를 경우 사용합니다.
  • $ src/redis-trib.rb add-node --slave --master-id bcc81e34e1e340bb65e86ee21c4a0beb0eb5fd3a 127.0.0.1:5007 127.0.0.1:5001
    >>> Adding node 127.0.0.1:5007 to cluster 127.0.0.1:5001
    >>> Performing Cluster Check (using node 127.0.0.1:5001)
    [클러스터 정보 출력하는 부분은 생략합니다]
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    >>> Send CLUSTER MEET to node 127.0.0.1:5007 to make it join the cluster.
    Waiting for the cluster to join.
    >>> Configure node as replica of 127.0.0.1:5002.
    [OK] New node added correctly.
  • Info 명령으로 추가된 노드 확인
  • $ src/redis-trib.rb info 127.0.0.1:5001
    127.0.0.1:5001 (d8403c21...) -> 0 keys | 5456 slots | 1 slaves.
    127.0.0.1:5002 (bcc81e34...) -> 0 keys | 5462 slots | 2 slaves.
    127.0.0.1:5003 (8175f101...) -> 0 keys | 5466 slots | 1 slaves.
    [OK] 0 keys in 4 masters.
    0.00 keys per slot on average.

redis-trib DEL-NODE

  • 클러스터에서 노드를 제거한다.   슬롯이 할당되어 있으면 제거할 수 없다.   Reshard 명령으로 슬롯과 데이터를 다른 노드에 할당한 후 del-node 명령을 실행한다.   제거할 노드가 슬레이브면 reshard 할 필요없다.
  • 명령   redis-trib.rb del-node ip:port node-id
  • ip:port   접속해서 작업할 노드를 지정한다.
  • node-id   제거할 노드 ID를 지정한다.
  • 이 명령은 마지막에 레디스 인스턴스를 shutdown 한다.
  • 다운된 노드에 대해서는 이 명령을 실행할 수 없다.   왜냐하면 이 명령은 해당 노드에 접속해서 확인 후 진행하는데, 접속할 수 없기 때문이다.   이때는 클러스터의 다른 모든 노드에 redis-cli로 접속해서 cluster forget node-id 명령으로 제거한다.
  • 다음은 5001번에 접속해서 5007번 노드를 제거하는 명령과 메시지다.
  • $ src/redis-trib.rb del-node 127.0.0.1:5001 47a5474960febbf8c74bf4678e6784b9c50b95aa
    >>> Removing node 47a5474960febbf8c74bf4678e6784b9c50b95aa from cluster 127.0.0.1:5001
    >>> Sending CLUSTER FORGET messages to the cluster...
    >>> SHUTDOWN the node.

redis-trib INFO

  • 사용법: redis-trib.rb INFO ip:port   클론에 접속해도 된다.
  • 클러스터 정보를 조회한다. 조회 내용은 다음과 같다.
  • $ src/redis-trib.rb info 192.168.56.102:7001
    192.168.56.102:7001 (12435969...) -> 333 keys | 5461 slots | 1 slaves.
    192.168.56.102:7002 (3e70563e...) -> 338 keys | 5462 slots | 1 slaves.
    192.168.56.102:7003 (e68d00bd...) -> 329 keys | 5461 slots | 1 slaves.
    [OK] 1000 keys in 3 masters.
    0.06 keys per slot on average.
  • 출력 내용: 마스터 3대, 클론(슬레이브) 3대이고, 마스터 노드 3대에 총 1000개의 키가 있고, 각 슬롯에 평균 0.06개의 키가 있다.
  • 내부적으로 CLUSTER NODES 명령을 사용한다.

redis-trib IMPORT

  • 사용법: redis-trib.rb IMPORT --from (source)ip:port [--copy] [--replace] (target)ip:port
  • --from에 지정한 source node에서 데이터(키)를 target 클러스터로 이전(migrate)한다.
  • Source node는 Standalone 이어야 한다.
  • --copy 옵션을 사용하면 데이터 이전(migrate) 후에도 source node에 데이터가 그대로 남아있다. 사용하지 않으면 source node에서 지워진다.
  • --replace 옵션은 target cluster node에 같은 키가 있으면 target node의 value가 지워지고 source node의 value가 들어간다. 간단히 말하면 업데이트된다.
  • $ src/redis-trib.rb import --from 192.168.56.102:6001 --copy --replace 192.168.56.102:7004
    >>> Importing data from 192.168.56.102:6001 to cluster
    >>> Performing Cluster Check (using node 192.168.56.102:7004)
    [클러스터 정보 출력하는 부분은 생략합니다]
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    >>> Connecting to the source Redis instance
    *** Importing 1000 keys from DB 0
    Migrating keyX581 to 192.168.56.102:7002: OK
    ...

redis-trib REBALANCE

  • 사용법: redis-trib.rb REBALANCE ip:port
  • 슬롯을 균형있게 재분배(reshard)한다.
  • 옵션은 --weight <arg>, --auto-weights, --use-empty-masters, --timeout <arg>, --simulate, --pipeline <arg>, --threshold <arg> 가 있고, rebalance 와 ip:port 중간에 위치한다.
  • 아래는 1번 노드에 461개 슬롯이 있던 것을 rebalance 후 5462개 슬롯으로 균형있게 할당된 예이다.
  • 192.168.56.102:7001 (12435969...) -> 26 keys | 461 slots | 1 slaves.
    192.168.56.102:7002 (3e70563e...) -> 645 keys | 10462 slots | 1 slaves.
    192.168.56.102:7003 (e68d00bd...) -> 329 keys | 5461 slots | 1 slaves.

    $ src/redis-trib.rb rebalance 192.168.56.102:7001
    >>> Performing Cluster Check (using node 192.168.56.102:7001)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    >>> Rebalancing across 3 nodes. Total weight = 3
    Moving 5001 slots from 192.168.56.102:7002 to 192.168.56.102:7001
    #####...(중간 생략)...####

    192.168.56.102:7001 (12435969...) -> 333 keys | 5462 slots | 1 slaves.
    192.168.56.102:7002 (3e70563e...) -> 338 keys | 5461 slots | 1 slaves.
    192.168.56.102:7003 (e68d00bd...) -> 329 keys | 5461 slots | 1 slaves.
  • 클러스터에 새 노드를 추가한 경우에는 --use-empty-masters 옵션을 사용한다.
  • 아래 add-node로 7011번 노드를 추가하고 rebalance한 예이다.
  • $ src/redis-trib.rb info 192.168.56.102:7001
    192.168.56.102:7001 (3f949687...) -> 3950 keys | 5461 slots | 1 slaves.
    192.168.56.102:7002 (1b774405...) -> 3733 keys | 5462 slots | 1 slaves.
    192.168.56.102:7003 (5c559689...) -> 3652 keys | 5461 slots | 1 slaves.
    192.168.56.102:7011 (9774d9ff...) -> 0 keys | 0 slots | 0 slaves.
    [OK] 11335 keys in 4 masters.
    0.69 keys per slot on average.

    $ src/redis-trib.rb rebalance --use-empty-masters 192.168.56.102:7001
    >>> Performing Cluster Check (using node 192.168.56.102:7001)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    >>> Rebalancing across 4 nodes. Total weight = 4
    Moving 1366 slots from 192.168.56.102:7002 to 192.168.56.102:7011
    ###### ... #####
    Moving 1365 slots from 192.168.56.102:7003 to 192.168.56.102:7011
    ###### ... #####
    Moving 1365 slots from 192.168.56.102:7001 to 192.168.56.102:7011
    ###### ... #####

    $ src/redis-trib.rb info 192.168.56.102:7001
    192.168.56.102:7001 (3f949687...) -> 2967 keys | 4096 slots | 1 slaves.
    192.168.56.102:7002 (1b774405...) -> 2804 keys | 4096 slots | 1 slaves.
    192.168.56.102:7003 (5c559689...) -> 2750 keys | 4096 slots | 1 slaves.
    192.168.56.102:7011 (9774d9ff...) -> 2814 keys | 4096 slots | 0 slaves.
    [OK] 11335 keys in 4 masters.
    0.69 keys per slot on average.
  • Weight 옵션을 사용해서 노드별로 가중치를 줄 수 있습니다.
  • 192.168.56.102:7001 (e492e7fa...) -> 333 keys | 5461 slots | 1 slaves.
    192.168.56.102:7002 (30ce0f06...) -> 338 keys | 5462 slots | 1 slaves.
    192.168.56.102:7003 (04923ba3...) -> 329 keys | 5461 slots | 1 slaves.

    $ src/redis-trib.rb rebalance --weight e492e7fa=0.5 --weight 30ce0f06=1.5 192.168.56.102:7001 >>> Performing Cluster Check (using node 192.168.56.102:7001)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    >>> Rebalancing across 3 nodes. Total weight = 3.0
    Moving 2731 slots from 192.168.56.102:7001 to 192.168.56.102:7002

    192.168.56.102:7001 (e492e7fa...) -> 168 keys | 2730 slots | 1 slaves.
    192.168.56.102:7002 (30ce0f06...) -> 503 keys | 8193 slots | 1 slaves.
    192.168.56.102:7003 (04923ba3...) -> 329 keys | 5461 slots | 1 slaves.

redis-trib CHECK

  • 사용법: redis-trib.rb CHECK ip:port   클론에 접속해도 된다.
  • 클러스터를 체크한다. 조회 내용(체크 결과)은 다음과 같다.
  • $ src/redis-trib.rb check 192.168.56.102:7001
    >>> Performing Cluster Check (using node 192.168.56.102:7001)
    M: 12435969c1bba2170092389fa28589f439d14316 192.168.56.102:7001
          slots:0-5460 (5461 slots) master
          1 additional replica(s)
    S: 857e9e6ea87092867ca038c3cc85d888e0a1a6e1 192.168.56.102:7004
          slots: (0 slots) slave
          replicates 3e70563e5e2a41d75e4cfabe5444876e680ca882
    S: 2275e9658da60bf5de4c6550aca598cf87759d19 192.168.56.102:7006
          slots: (0 slots) slave
          replicates 12435969c1bba2170092389fa28589f439d14316
    M: 3e70563e5e2a41d75e4cfabe5444876e680ca882 192.168.56.102:7002
          slots:5461-10922 (5462 slots) master
          1 additional replica(s)
    M: e68d00bd815b8ddabf255049698b701e6ee7bc9c 192.168.56.102:7003
          slots:10923-16383 (5461 slots) master
          1 additional replica(s)
    S: cd4d640744bdb91e460efb42df2636f4eb4dd7ad 192.168.56.102:7005
          slots: (0 slots) slave
          replicates e68d00bd815b8ddabf255049698b701e6ee7bc9c
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    [WARNING] Node 192.168.56.102:7001 has slots in migrating state (7).
    [WARNING] Node 192.168.56.102:7002 has slots in importing state (7).
    [WARNING] The following slots are open: 7
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
  • Migrating/Importing 예약이 되어 있고(이런 상태를 OPEN 슬롯이라고 한다), 아직 종료되지 않았으면 위에서 처럼 빨간색으로 표시된다
  • 할당되지 않은 슬롯(삭제된 슬롯)이 있으면 아래와 같이 빨간색으로 표시된다.
  • [ERR] Nodes don't agree about configuration!
    >>> Check for open slots...
    >>> Check slots coverage...
    [ERR] Not all 16384 slots are covered by nodes.

redis-trib CALL

  • 사용법: redis-trib.rb CALL ip:port command arg arg .. arg   클론에 접속해도 된다.
  • 클러스터 내 모든 노드(클론 포함)에 접속해서 지정한 명령을 실행한다.
  • 일반적으로 실행하는 명령에는 "cluster info", "cluster nodes", "info", "dbsize" 등이 있다. SET 같은 입력 명령도 실행할 수 있지만 여기서 사용하기에는 적합하지 않다.
  • 다음은 'dbsize' 명령을 실행한 예이다.
  • $ src/redis-trib.rb call 192.168.56.102:7001 dbsize
    >>> Calling DBSIZE
    192.168.56.102:7001: 333
    192.168.56.102:7004: 338
    192.168.56.102:7006: 333
    192.168.56.102:7002: 338
    192.168.56.102:7003: 329
    192.168.56.102:7005: 329
  • 클러스터를 해체하려면 'flushall' 명령을 실행 후 'cluster reset' 명령을 실행한다. 노드에 키가 있으면 reset이 되지 않기 때문에 먼저 'flushall' 명령을 실행하는 것이다.
  • $ src/redis-trib.rb call 192.168.56.102:7001 flushall
    $ src/redis-trib.rb call 192.168.56.102:7001 cluster reset
  • Cluster reset 명령 실행 후에는 노드들이 더 이상 클러스터로 묶여있지 않다.
  • 클러스터 노드들의 설정(config) 변경 사항을 한번에 저장하고 싶으면 'cluster saveconfig' 명령을 실행한다.
  • $ src/redis-trib.rb call 192.168.56.102:7001 cluster saveconfig

redis-trib SET-TIMEOUT

  • cluster-node-timeout 시간(ms)를 일괄 config set 명령으로 설정/변경하고 config rewrite 명령으로 redis.conf 파일에 쓴다.
  • $ src/redis-trib.rb set-timeout 192.168.56.102:7001 4000
    >>> Reconfiguring node timeout in every cluster node...
    *** New timeout set for 192.168.56.102:7001
    *** New timeout set for 192.168.56.102:7004
    *** New timeout set for 192.168.56.102:7006
    *** New timeout set for 192.168.56.102:7002
    *** New timeout set for 192.168.56.102:7003
    *** New timeout set for 192.168.56.102:7005
    >>> New node timeout set. 6 OK, 0 ERR.

redis-trib HELP

    $ redis-trib.rb help
    Usage: redis-trib <command> <options> <arguments ...>
    create host1:port1 ... hostN:portN
          --replicas <arg>
    check host:port
    info host:port
    fix host:port
          --timeout <arg>
    reshard host:port
          --from <arg>
          --to <arg>
          --slots <arg>
          --yes
          --timeout <arg>
          --pipeline <arg>
    rebalance host:port
          --weight <arg>
          --auto-weights
          --use-empty-masters
          --timeout <arg>
          --simulate
          --pipeline <arg>
          --threshold <arg>
    add-node new_host:new_port existing_host:existing_port
          --slave
          --master-id <arg>
    del-node host:port node_id
    set-timeout host:port milliseconds
    call host:port command arg arg .. arg
    import --from <arg> host:port
          --copy
          --replace
    help (show this help)
    For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

<< Cluster Redis-cli redis-trib.rb Cluster Design >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.

혹시 처음이세요?
레디스게이트에는 레디스에 대한 많은 정보가 있습니다.
레디스 소개, 명령어, SQL, 클라이언트, 서버, 센티널, 클러스터 등이 있습니다.
혹시 필요한 정보를 찾기 어려우시면 redisgate@gmail.com로 메일 주세요.
제가 찾아서 알려드리겠습니다.
 
close
IP를 기반으로 보여집니다.