마스터와 슬레이브가 구동되어 있을 때 Failover 하는 방법
cluster failover 명령어 사용
복제노드에서 cluster failover 명령어를 사용하여 Failover 를 진행할 수 있습니다. ( Failback 도 동일한 개념입니다. )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 127.0.0.1:7000> cluster nodes a8248c454007d610685bba8e805c5a6004867d15 127.0.0.1:7001@17001 slave 869859e396c881b3c26f2a386c1495235225b57b 0 1586026738000 9 connected 869859e396c881b3c26f2a386c1495235225b57b 127.0.0.1:7000@17000 myself,master - 0 1586026737000 9 connected 0-16383 dcae268548d26662de97d3843f658318953004a7 127.0.0.1:8000@18000 master - 0 1586026739028 0 connected $ redis-cli -p 7001 cluster failover OK 127.0.0.1:7001> cluster nodes a8248c454007d610685bba8e805c5a6004867d15 127.0.0.1:7001@17001 myself,master - 0 1586026760000 16 connected 0-16383 dcae268548d26662de97d3843f658318953004a7 127.0.0.1:8000@18000 master - 0 1586026762401 0 connected 869859e396c881b3c26f2a386c1495235225b57b 127.0.0.1:7000@17000 slave a8248c454007d610685bba8e805c5a6004867d15 0 1586026763411 16 connected $ redis-cli -p 7000 cluster failover OK 127.0.0.1:7001> cluster nodes a8248c454007d610685bba8e805c5a6004867d15 127.0.0.1:7001@17001 myself,slave 869859e396c881b3c26f2a386c1495235225b57b 0 1586026811000 16 connected dcae268548d26662de97d3843f658318953004a7 127.0.0.1:8000@18000 master - 0 1586026812586 0 connected 869859e396c881b3c26f2a386c1495235225b57b 127.0.0.1:7000@17000 master - 0 1586026812077 17 connected 0-16383 | cs |
마스터가 다운되어 있을 때 슬레이브로 Failover 하는 방법
cluster failover takeover 명령어 사용
마스터 노드를 먼저 강제 종료하였습니다.
1 2 3 4 5 6 | 127.0.0.1:7000> cluster nodes dcae268548d26662de97d3843f658318953004a7 127.0.0.1:8000@18000 master - 0 1586027188134 0 connected 869859e396c881b3c26f2a386c1495235225b57b 127.0.0.1:7000@17000 myself,master - 0 1586027187000 20 connected 0-16383 a8248c454007d610685bba8e805c5a6004867d15 127.0.0.1:7001@17001 slave 869859e396c881b3c26f2a386c1495235225b57b 0 1586027189166 20 connected 127.0.0.1:7000> shutdown | cs |
이 후 takeover 명령어를 추가로 부여하여 Failover 를 진행합니다.
7001 로그를 확인하면 마스터에 접속하려고 했으나 실패하였고, 이전의 마스터 정보를 지움으로써 마스터로 승격하였습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $ redis-cli -p 7001 cluster failover takeover OK 127.0.0.1:7001> cluster nodes a8248c454007d610685bba8e805c5a6004867d15 127.0.0.1:7001@17001 myself,master - 0 1586026945000 19 connected 0-16383 dcae268548d26662de97d3843f658318953004a7 127.0.0.1:8000@18000 master - 0 1586026947621 0 connected 869859e396c881b3c26f2a386c1495235225b57b 127.0.0.1:7000@17000 master,fail - 1586026859251 1586026858524 17 disconnected $ vi redis_7001.log 3197:S 05 Apr 2020 04:01:15.197 # Start of election delayed for 812 milliseconds (rank #0, offset 336). 3197:S 05 Apr 2020 04:01:15.299 * Connecting to MASTER 127.0.0.1:7000 3197:S 05 Apr 2020 04:01:15.299 * MASTER <-> REPLICA sync started 3197:S 05 Apr 2020 04:01:15.299 # Currently unable to failover: Waiting the delay before I can start a new failover. 3197:S 05 Apr 2020 04:01:15.299 # Error condition on socket for SYNC: Connection refused 3197:S 05 Apr 2020 04:01:15.579 # Taking over the master (user request). 3197:S 05 Apr 2020 04:01:15.579 # New configEpoch set to 19 3197:M 05 Apr 2020 04:01:15.579 # Setting secondary replication ID to 2a1d1c2b6fede4d41d1125c06cf4da6da0f003ac, valid up to offset: 337. New replication ID is e75dbcfe040754e31d5425c1a4205bfc13f6a200 3197:M 05 Apr 2020 04:01:15.579 * Discarding previously cached master state. 3197:M 05 Apr 2020 04:01:18.566 # Cluster state changed: ok | cs |
만약 Takeover 를 사용을 안한다면 어떻게 될까?
일반적인 방식으로 Failover 를 하려고 하면 마스터 노드에 접속할 수 없어 실패하며 FORCE 옵션을 사용하라고 나옵니다.
1 2 | $ redis-cli -p 7001 cluster failover (error) ERR Master is down or failed, please use CLUSTER FAILOVER FORCE | cs |
그러나 실제로 FORCE 옵션을 사용하면 Failover 는 진행되지 않습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $ redis-cli -p 7001 cluster failover force OK 127.0.0.1:7001> cluster nodes a8248c454007d610685bba8e805c5a6004867d15 127.0.0.1:7001@17001 myself,slave 869859e396c881b3c26f2a386c1495235225b57b 0 1586027340000 19 connected dcae268548d26662de97d3843f658318953004a7 127.0.0.1:8000@18000 master - 0 1586027343917 0 connected 869859e396c881b3c26f2a386c1495235225b57b 127.0.0.1:7000@17000 master,fail - 1586027192328 1586027191600 20 disconnected 0-16383 $ vi redis_7001.log 3197:S 05 Apr 2020 04:08:40.340 * Connecting to MASTER 127.0.0.1:7000 3197:S 05 Apr 2020 04:08:40.340 * MASTER <-> REPLICA sync started 3197:S 05 Apr 2020 04:08:40.340 # Error condition on socket for SYNC: Connection refused 3197:S 05 Apr 2020 04:08:41.363 * Connecting to MASTER 127.0.0.1:7000 3197:S 05 Apr 2020 04:08:41.363 * MASTER <-> REPLICA sync started 3197:S 05 Apr 2020 04:08:41.363 # Error condition on socket for SYNC: Connection refused 3197:S 05 Apr 2020 04:08:42.402 * Connecting to MASTER 127.0.0.1:7000 3197:S 05 Apr 2020 04:08:42.402 * MASTER <-> REPLICA sync started 3197:S 05 Apr 2020 04:08:42.402 # Error condition on socket for SYNC: Connection refused 3197:S 05 Apr 2020 04:08:43.477 * Connecting to MASTER 127.0.0.1:7000 3197:S 05 Apr 2020 04:08:43.477 * MASTER <-> REPLICA sync started 3197:S 05 Apr 2020 04:08:43.477 # Error condition on socket for SYNC: Connection refused | cs |
Line |
설명 |
1 |
force 옵션을 사용하여 OK 명령어가 나왔습니다. |
3 |
node 정보를 조회하면 7001 노드는 계속 SLAVE 입니다. |
8 |
7001 노드의 로그를 조회하면 7000 노드가 구동될 때까지 계속해서 동기화를 요청하고 있습니다. 이 로그는 7000 노드가 다시 구동될 때까지 계속됩니다. (그리고 7000 노드가 마스터로 됩니다. ) |
7000 노드를 다시 구동하고 nodes 정보를 확인하면 7001 은 계속 슬레이브 입니다.
1 2 3 4 5 6 7 | $ redis-server 7000/redis_7000.conf $ redis-cli -c -p 7001 127.0.0.1:7001> cluster nodes a8248c454007d610685bba8e805c5a6004867d15 127.0.0.1:7001@17001 myself,slave 869859e396c881b3c26f2a386c1495235225b57b 0 1586027542000 19 connected dcae268548d26662de97d3843f658318953004a7 127.0.0.1:8000@18000 master - 0 1586027543297 0 connected 869859e396c881b3c26f2a386c1495235225b57b 127.0.0.1:7000@17000 master - 0 1586027542774 20 connected 0-16383 | cs |
'Database > Redis' 카테고리의 다른 글
[Redis] 레디스 failover-abort-slave-timeout 오류 해결방법 (0) | 2020.11.22 |
---|---|
[Redis] INFO 명령어로 조회되는 대상 의미 파악 (0) | 2020.07.17 |
[Redis] 현재 오픈되어 있는 슬롯, 없는 슬롯 확인 및 추가하는 방법 (0) | 2020.04.05 |
[Redis] 클러스터 마스터, 슬레이브 노드를 제거하는 방법 (0) | 2020.04.05 |
[Redis] 클러스터 노드간 슬롯을 변경(이동)하는 방법 (2) | 2020.04.05 |