redis 6.2 集群 迁移节点,添加节点,删除节点

一、环境

CentOS 7.9

redis 6.2.11

3台服务器集群,分别装的主和从。

主IP

从复制谁

(不是自己)

从复制谁

调整后

端口集群端口备注
10.10.10.4510.10.10.5210.10.10.70

主:6479

从:6579

16479

16579

原主节点

原从节点

10.10.10.5110.10.10.4510.10.10.45

主:6479

从:6579

16479

16579

原主节点

原从节点

10.10.10.5210.10.10.51-

主:6479

从:6579

16479

16579

待删除节点

待迁移节点

10.10.10.70-10.10.10.51

主:6479

从:6579

16479

16579

新增节点

二、迁移操作方式

1、使用redis自带的redis-cli --cluster操作

      可在线操作,本文采用这种方式,个人推荐。

[root@test5 bin]# ./redis-cli --cluster help
Cluster Manager Commands:
  create         host1:port1 ... hostN:portN
                 --cluster-replicas <arg>
  check          host:port
                 --cluster-search-multiple-owners
  info           host:port
  fix            host:port
                 --cluster-search-multiple-owners
                 --cluster-fix-with-unreachable-masters
  reshard        host:port
                 --cluster-from <arg>
                 --cluster-to <arg>
                 --cluster-slots <arg>
                 --cluster-yes
                 --cluster-timeout <arg>
                 --cluster-pipeline <arg>
                 --cluster-replace
  rebalance      host:port
                 --cluster-weight <node1=w1...nodeN=wN>
                 --cluster-use-empty-masters
                 --cluster-timeout <arg>
                 --cluster-simulate
                 --cluster-pipeline <arg>
                 --cluster-threshold <arg>
                 --cluster-replace
  add-node       new_host:new_port existing_host:existing_port
                 --cluster-slave
                 --cluster-master-id <arg>
  del-node       host:port node_id
  call           host:port command arg arg .. arg
                 --cluster-only-masters
                 --cluster-only-replicas
  set-timeout    host:port milliseconds
  import         host:port
                 --cluster-from <arg>
                 --cluster-from-user <arg>
                 --cluster-from-pass <arg>
                 --cluster-from-askpass
                 --cluster-copy
                 --cluster-replace
  backup         host:port backup_directory
  help           

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

Cluster Manager Options:
  --cluster-yes  Automatic yes to cluster commands prompts

  

2、使用redis-trib.rb操作

       redis-trib.rb是ruby写的,虽然是官方出品,但是已经过时了,改用redis-cli --cluster操作

[root@test5 redis6]# yum install ruby

[root@test5 bin]# cp /opt/redis-6.2.11/src/redis-trib.rb /opt/redis6/bin/

[root@test5 bin]# ./redis-trib.rb info 10.10.10.52:6479
WARNING: redis-trib.rb is not longer available!
You should use redis-cli instead.

All commands and features belonging to redis-trib.rb have been moved
to redis-cli.
In order to use them you should call redis-cli with the --cluster
option followed by the subcommand name, arguments and options.

Use the following syntax:
redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]

Example:
redis-cli --cluster info 10.10.10.52:6479

To get help about all subcommands, type:
redis-cli --cluster help

3、使用redis-shake(阿里)

RedisShake是基于golang编写的用于Redis数据库的同步工具,基于Redis RDB+AOF异步复制实现,可以满足用户在不同架构之前实时数据同步、迁移、容灾、分析、双活等多场景需求。

揭开RedisShake的秘密
【周二开源日第二期】RedisShake — Redis数据同步迁移的必备神器来了!
RedisShake 开源地址:https://github.com/alibaba/RedisShake

redis-shake 3.x 系列文档

4、使用dump.rdb,appendonly.aof文件操作

Redis15-redis集群间的数据迁移

三、迁移操作过程

可在新节点操作,中间会多次执行check节点

1、启动新节点(开启集群配置) 

        /opt/redis6/bin/redis-server /opt/redis6/6479/redis.conf

        /opt/redis6/bin/redis-server /opt/redis6/6579/redis.conf

        redis.conf

cluster-enabled yes
cluster-config-file /opt/redis6/6479/nodes-6479.conf
#cluster-config-file /opt/redis6/6579/nodes-6579.conf
cluster-node-timeout 15000

2、检查集群

        ./redis-cli --cluster check 10.10.10.52:6479 -a myPaasword

        host:原来得一个主节点

3、添加新主节点

        ./redis-cli --cluster add-node 10.10.10.70:6479 10.10.10.52:6479 -a myPaasword

        前面的是新添加的节点,后面的是集群任意节点

4、迁移slot

       ./redis-cli --cluster reshard 10.10.10.70:6479 --cluster-from a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 --cluster-to 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d --cluster-slots 5461 --cluster-yes --cluster-timeout 3600000 -a myPaasword

        host:最好写局域网IP,不写127.0.0.1(可能容易失败)

         --cluster-slots:迁移的solt数量,可通过check查询,如果迁移部分失败后再次迁移,这个数量会变 。

        --cluster-timeout:超时时间(毫秒),最好写上,要不默认60s,容易失败

        迁移slot,中途失败,被迁移的原主节点可能会从master降为slave,被迁移的原从节点可能升级为master,后续可以调整。

5、修复集群

        (如果有问题)修复后再次迁移slot

       ./redis-cli --cluster fix 10.10.10.70:6479 -a myPaasword

6、客户端连接测试

        /opt/redis6/bin/redis-cli -c -h 127.0.0.1 -p 6479 -a myPaasword

        /opt/redis6/bin/redis-cli -c -h 127.0.0.1 -p 6579 -a myPaasword

7、删除原主节点

        ./redis-cli --cluster del-node 10.10.10.52:6479 afb78d482884444027f1aef4f54df2bf7da7ccf8 -a myPaasword

8、添加新从节点

        ./redis-cli --cluster add-node 10.10.10.70:6579 10.10.10.51:6479 --cluster-slave --cluster-master-id fe29e4fdf577ee326bb7a66a7669042c718caff3 -a myPaasword

9、删除原从节点

        ./redis-cli --cluster del-node 10.10.10.52:6579 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e -a myPaasword

10、检查节点从属关系,调整从属关系

        改变当前节点的主

        ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword

        如果不满意,可以通过replicaof命令调整。

        127.0.0.1:6579> replicaof 10.10.10.70 6479 (新版本)

        127.0.0.1:6579> slaveof 10.10.10.70 6479 (老版本)

四、操作过程

1、检查集群

[root@test2 bin]# ./redis-cli --cluster check 10.10.10.45:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.45:6479 (a7eb9bf3...) -> 49 keys | 5461 slots | 1 slaves.
10.10.10.52:6479 (afb78d48...) -> 54 keys | 5461 slots | 1 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 49 keys | 5462 slots | 1 slaves.
[OK] 152 keys in 3 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.45:6479)
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates afb78d482884444027f1aef4f54df2bf7da7ccf8
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

2、添加新主节点         
[root@test5 bin]# ./redis-cli --cluster add-node 10.10.10.70:6479 10.10.10.52:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 10.10.10.70:6479 to cluster 10.10.10.52:6479
>>> Performing Cluster Check (using node 10.10.10.52:6479)
M: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates afb78d482884444027f1aef4f54df2bf7da7ccf8
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 10.10.10.70:6479 to make it join the cluster.
[OK] New node added correctly.

3、检查集群

[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 0 keys | 0 slots | 0 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 53 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 52 keys | 5461 slots | 1 slaves.
10.10.10.52:6479 (afb78d48...) -> 55 keys | 5461 slots | 1 slaves.
[OK] 160 keys in 4 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots: (0 slots) master
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
M: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates afb78d482884444027f1aef4f54df2bf7da7ccf8
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

4、迁移slot

[root@test5 bin]#./redis-cli --cluster reshard 127.0.0.1:6479 --cluster-from afb78d482884444027f1aef4f54df2bf7da7ccf8 --cluster-to 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d --cluster-slots 5461 --cluster-yes -a myPaasword
    Moving slot 16381 from afb78d482884444027f1aef4f54df2bf7da7ccf8
    Moving slot 16382 from afb78d482884444027f1aef4f54df2bf7da7ccf8
    Moving slot 16383 from afb78d482884444027f1aef4f54df2bf7da7ccf8
Moving slot 11007 from 10.10.10.52:6479 to 127.0.0.1:6479: 
Moving slot 11008 from 10.10.10.52:6479 to 127.0.0.1:6479: 
Moving slot 11009 from 10.10.10.52:6479 to 127.0.0.1:6479: 
Node 10.10.10.52:6479 replied with error:
IOERR error or timeout reading to target instance

host尝试使用局域网IP,添加超时时间(打开防火墙端口)

[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 0 keys | 86 slots | 0 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 52 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 48 keys | 5461 slots | 1 slaves.
10.10.10.45:6579 (a25a2ff5...) -> 56 keys | 5375 slots | 1 slaves.
[OK] 156 keys in 4 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-11008] (86 slots) master
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots: (0 slots) slave
   replicates a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
M: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots:[11009-16383] (5375 slots) master
   1 additional replica(s)
[ERR] Nodes don't agree about configuration!
>>> Check for open slots...
[WARNING] Node 10.10.10.70:6479 has slots in importing state 11009.
[WARNING] The following slots are open: 11009.

>>> Check slots coverage...
[OK] All 16384 slots covered.

1、修改集群fix(推荐)

2、>cluster setslot 11009 stable

5、修复集群
[root@test5 bin]# ./redis-cli --cluster fix 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 0 keys | 86 slots | 0 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 53 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 52 keys | 5461 slots | 1 slaves.
10.10.10.45:6579 (a25a2ff5...) -> 55 keys | 5375 slots | 1 slaves.
[OK] 160 keys in 4 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-11008] (86 slots) master
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots: (0 slots) slave
   replicates a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
M: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots:[11009-16383] (5375 slots) master
   1 additional replica(s)
[ERR] Nodes don't agree about configuration!
>>> Check for open slots...
[WARNING] Node 10.10.10.70:6479 has slots in importing state 11009.
[WARNING] The following slots are open: 11009.
>>> Fixing open slot 11009
Set as importing in: 10.10.10.70:6479
>>> Case 2: Moving all the 11009 slot keys to its owner 10.10.10.45:6579
Moving slot 11009 from 10.10.10.70:6479 to 10.10.10.45:6579: 
>>> Setting 11009 as STABLE in 10.10.10.70:6479
>>> Check slots coverage...
[OK] All 16384 slots covered.

6、迁移slot
[root@test5 bin]# ./redis-cli --cluster reshard 127.0.0.1:6479 --cluster-from a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 --cluster-to 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d --cluster-slots 5375 --cluster-yes --cluster-timeout 3600000 -a myPaasword
    Moving slot 16380 from a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
    Moving slot 16381 from a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
    Moving slot 16382 from a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
    Moving slot 16383 from a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
Moving slot 11009 from 10.10.10.45:6579 to 127.0.0.1:6479: 
Moving slot 11010 from 10.10.10.45:6579 to 127.0.0.1:6479: 
Moving slot 11011 from 10.10.10.45:6579 to 127.0.0.1:6479: 
Moving slot 11124 from 10.10.10.45:6579 to 127.0.0.1:6479: 
Moving slot 11125 from 10.10.10.45:6579 to 127.0.0.1:6479: 
Moving slot 11126 from 10.10.10.45:6579 to 127.0.0.1:6479: 
Node 10.10.10.45:6579 replied with error:
ERR Target instance replied with error: MOVED 11126 10.10.10.45:6579

检查集群check,修复集群fix

7、检查集群

[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 0 keys | 203 slots | 0 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 52 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 53 keys | 5461 slots | 1 slaves.
10.10.10.45:6579 (a25a2ff5...) -> 55 keys | 5258 slots | 1 slaves.
[OK] 160 keys in 4 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-11125] (203 slots) master
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots: (0 slots) slave
   replicates a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
M: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots:[11126-16383] (5258 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
[WARNING] Node 10.10.10.70:6479 has slots in importing state 11126.
[WARNING] Node 10.10.10.45:6579 has slots in migrating state 11126.
[WARNING] The following slots are open: 11126.

>>> Check slots coverage...
[OK] All 16384 slots covered.

修改集群fix

8、修复集群

[root@test5 bin]# ./redis-cli --cluster fix 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 0 keys | 203 slots | 0 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 53 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 53 keys | 5461 slots | 1 slaves.
10.10.10.45:6579 (a25a2ff5...) -> 55 keys | 5258 slots | 1 slaves.
[OK] 161 keys in 4 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-11125] (203 slots) master
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots: (0 slots) slave
   replicates a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
M: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots:[11126-16383] (5258 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
[WARNING] Node 10.10.10.70:6479 has slots in importing state 11126.
[WARNING] Node 10.10.10.45:6579 has slots in migrating state 11126.
[WARNING] The following slots are open: 11126.
>>> Fixing open slot 11126
Set as migrating in: 10.10.10.45:6579
Set as importing in: 10.10.10.70:6479
>>> Case 1: Moving slot 11126 from 10.10.10.45:6579 to 10.10.10.70:6479
Moving slot 11126 from 10.10.10.45:6579 to 10.10.10.70:6479: .
>>> Check slots coverage...
[OK] All 16384 slots covered.

9、检查集群
[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 1 keys | 204 slots | 0 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 53 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 53 keys | 5461 slots | 1 slaves.
10.10.10.45:6579 (a25a2ff5...) -> 54 keys | 5257 slots | 1 slaves.
[OK] 161 keys in 4 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-11126] (204 slots) master
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots: (0 slots) slave
   replicates a25a2ff556bc68b96ce55d997aa33ec1ef23ae30
M: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots:[11127-16383] (5257 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.

10、迁移slot
[root@test5 bin]# ./redis-cli --cluster reshard 10.10.10.70:6479 --cluster-from a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 --cluster-to 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d --cluster-slots 5257 --cluster-yes --cluster-timeout 3600000 -a myPaasword
Moving slot 16381 from 10.10.10.45:6579 to 10.10.10.70:6479: 
Moving slot 16382 from 10.10.10.45:6579 to 10.10.10.70:6479: 
Moving slot 16383 from 10.10.10.45:6579 to 10.10.10.70:6479: 
Node 10.10.10.45:6579 replied with error:
ERR Please use SETSLOT only with masters.

这个错误,可忽略,是因为迁移完slot后,节点从主降到从了。

11、检查集群

[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 55 keys | 5461 slots | 2 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 53 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 53 keys | 5461 slots | 1 slaves.
[OK] 161 keys in 3 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-16383] (5461 slots) master
   2 additional replica(s)
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: afb78d482884444027f1aef4f54df2bf7da7ccf8 10.10.10.52:6479
   slots: (0 slots) slave
   replicates 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

12、客户端连接测试
[root@test5 mysql-8.0.32]# /opt/redis6/bin/redis-cli -c -h 127.0.0.1 -p 6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6479> set k1 1
OK
127.0.0.1:6479> set k2 2
-> Redirected to slot [449] located at 10.10.10.45:6479
OK
10.10.10.45:6479> set k3 3
OK
10.10.10.45:6479> set k4 4
-> Redirected to slot [8455] located at 10.10.10.51:6479
OK
10.10.10.51:6479> del k1
-> Redirected to slot [12706] located at 10.10.10.70:6479
(integer) 1
10.10.10.70:6479> del k2
-> Redirected to slot [449] located at 10.10.10.45:6479
(integer) 1
10.10.10.45:6479> del k3
(integer) 1
10.10.10.45:6479> del k4
-> Redirected to slot [8455] located at 10.10.10.51:6479
(integer) 1
10.10.10.51:6479>

13、删除原来的主节点
[root@test5 bin]# ./redis-cli --cluster del-node 10.10.10.52:6479 afb78d482884444027f1aef4f54df2bf7da7ccf8 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node afb78d482884444027f1aef4f54df2bf7da7ccf8 from cluster 10.10.10.52:6479
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 55 keys | 5461 slots | 1 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 52 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 53 keys | 5461 slots | 1 slaves.
[OK] 160 keys in 3 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

14、添加新从节点
 [root@test5 bin]# ./redis-cli --cluster add-node 10.10.10.70:6579 10.10.10.51:6479 --cluster-slave --cluster-master-id fe29e4fdf577ee326bb7a66a7669042c718caff3 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 10.10.10.70:6579 to cluster 10.10.10.51:6479
>>> Performing Cluster Check (using node 10.10.10.51:6479)
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 10.10.10.70:6579 to make it join the cluster.
Waiting for the cluster to join

>>> Configure node as replica of 10.10.10.51:6479.
[OK] New node added correctly.

15、检查集群

[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 55 keys | 5461 slots | 1 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 52 keys | 5462 slots | 2 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 53 keys | 5461 slots | 1 slaves.
[OK] 160 keys in 3 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   2 additional replica(s)
S: 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e 10.10.10.52:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 60728de1eedbfed820eecd811b6924bd345c1d45 10.10.10.70:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

16、删除原来的从节点
[root@test5 bin]# ./redis-cli --cluster del-node 10.10.10.52:6579 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 99d21673e03a8b7ab47ad1be28fc2b6ee63f391e from cluster 10.10.10.52:6579
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.

17、检查集群

[root@test5 bin]# ./redis-cli --cluster check 10.10.10.70:6479 -a myPaasword
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.10.10.70:6479 (27e15b4d...) -> 55 keys | 5461 slots | 1 slaves.
10.10.10.51:6479 (fe29e4fd...) -> 52 keys | 5462 slots | 1 slaves.
10.10.10.45:6479 (a7eb9bf3...) -> 53 keys | 5461 slots | 1 slaves.
[OK] 160 keys in 3 masters.
0.01 keys per slot on average.
>>> Performing Cluster Check (using node 10.10.10.70:6479)
M: 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d 10.10.10.70:6479
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: fe29e4fdf577ee326bb7a66a7669042c718caff3 10.10.10.51:6479
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: a7eb9bf3ad3817659d3a3cb09543600e95b1b987 10.10.10.45:6479
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 60728de1eedbfed820eecd811b6924bd345c1d45 10.10.10.70:6579
   slots: (0 slots) slave
   replicates fe29e4fdf577ee326bb7a66a7669042c718caff3
S: 244635b346f6190072cd3d9311f52e83ba698f97 10.10.10.51:6579
   slots: (0 slots) slave
   replicates a7eb9bf3ad3817659d3a3cb09543600e95b1b987
S: a25a2ff556bc68b96ce55d997aa33ec1ef23ae30 10.10.10.45:6579
   slots: (0 slots) slave
   replicates 27e15b4d0be71f8b8ece05cc6b8d860e123ab54d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

参考

Redis集群迁移节点

Redis15-redis集群间的数据迁移

Redis 单机迁移 Redis 集群方案(包含数据迁移)

redis集群管理-5.0.14版本

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Ubuntu 20.04 Redis 6.2三主三从集群是一种分布式架构的Redis数据存储方案。在这种架构中,有三个主节点和三个从节点组成一个集群,实现了高可用性和负载均衡。 在Ubuntu 20.04上搭建Redis 6.2三主三从集群可以按照以下步骤进行: 1. 首先,确保在每个节点上安装了Redis 6.2,并将其配置为允许远程访问。 2. 在主节点上编辑Redis配置文件,设置节点的端口号、IP地址、密码等信息。将从节点配置为复制主节点。 3. 在每个节点的命令行终端上启动Redis服务。 4. 在每个从节点上执行`slaveof 主节点IP地址 主节点端口号`命令,将从节点连接到主节点。 5. 在主节点上执行`CLUSTER MEET 从节点IP地址 从节点端口号`命令,将从节点添加到主节点集群中。 6. 执行`CLUSTER REPLICATE 主节点ID`命令,将从节点设置为主节点的从节点。 7. 重复步骤4-6,将剩余的主节点和从节点添加集群中,确保集群的完整性。 8. 执行`CLUSTER INFO`命令,查看集群的状态和节点信息。 通过以上步骤,就可以在Ubuntu 20.04上搭建Redis 6.2三主三从集群。这种集群架构能够提供高可用性和负载均衡,当主节点出现故障时,从节点可以自动接替主节点的功能,保证系统的可用性。同时,通过将数据进行分布存储,集群能够提供更高的读写性能。 值得注意的是,在集群添加删除节点时,需要进行相应的配置更改和数据迁移,以确保集群的稳定和一致性。因此,在进行任何更改之前,务必备份重要的数据,并了解Redis集群的运维和管理知识。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值