Redis Cluster在线迁移

2017-11-03 10:50:01来源:http://hsbxxl.blog.51cto.com/181620/1978491作者:人点击

分享

由于之前的redis cluster物理硬件性能不足。决定升级到更好的服务器上。考虑到redis是核心生产数据库,决定在线迁移,迁移过程,不中断服务。

下面是测试环境的完成迁移步骤:1. 原环境(测试环境,没有创建slave)

10.21.14.251:7000
10.21.14.251:7001
10.21.14.251:7002

2. 在新主机上,启动三个redis实例

10.21.10.120:7000
10.21.10.120:7001
10.21.10.120:7002

3. 将三个redis,都添加到集群中. 命令格式redis-trib.rb add-node <新增节点名> < 原集群节点名>

./redis-trib.rbadd-node10.21.10.120:700010.21.14.251:7000
./redis-trib.rbadd-node10.21.10.120:700110.21.14.251:7000
./redis-trib.rbadd-node10.21.10.120:700210.21.14.251:7000

4. 确认添加成功之后,开始reshard slot

./redis-trib.rbreshard10.21.10.120:7000

5. 遇到点问题,由于网络超时等原因,导致resharding中断。然后出现两边都有slot的情况,需要通过fix的方式来修复

[redis@ip-10-21-14-251redis]$./redis-trib.rbreshard10.21.10.120:7000
>>>PerformingClusterCheck(usingnode10.21.10.120:7000)
M:4422ab38377fa8828e0f7884570b3b482a66496b10.21.10.120:7000
slots:5026-5460(435slots)master
0additionalreplica(s)
M:5b38e63a1091baa3a871a52275489a2aa1d28bfb10.21.10.120:7002
slots:894-3397(2504slots)master
0additionalreplica(s)
M:bb1572074d41254e5b4d5aae5c52e54f5129d6d510.21.14.251:7001
slots:3398-4999,5461-15922(12064slots)master
0additionalreplica(s)
M:396a7fbd2ec61752f9e848a1d8cc7b405aef035610.21.14.251:7000
slots:(0slots)master
0additionalreplica(s)
M:9f215e7e4b511f3d2bbf5d734731899b71a62a3b10.21.10.120:7001
slots:0-893,5000-5025,15923-15948(946slots)master
0additionalreplica(s)
M:0c9b383f65ae4fefc5e02617fb76a845d7510a5310.21.14.251:7002
slots:15949-16383(435slots)master
0additionalreplica(s)
[OK]Allnodesagreeaboutslotsconfiguration.
>>>Checkforopenslots...
[WARNING]Node10.21.10.120:7002hasslotsinimportingstate(3398).
[WARNING]Node10.21.14.251:7001hasslotsinmigratingstate(3398).
[WARNING]Thefollowingslotsareopen:3398
>>>Checkslotscoverage...
[OK]All16384slotscovered.
***Pleasefixyourclusterproblemsbeforeresharding<<<<<<<<<<<<<<<<<<<<<

6. 可以使用下面命令进行集群检查

./redis-trib.rbcheck10.21.10.120:7000

7. 执行下面命令进行修复,然后就可以继续reshard slot了

./redis-trib.rbfix10.21.10.120:7000

8. 全部slot迁移完成

$./redis-trib.rbcheck10.21.10.120:7000
>>>PerformingClusterCheck(usingnode10.21.10.120:7000)
M:4422ab38377fa8828e0f7884570b3b482a66496b10.21.10.120:7000
slots:3399-4999,5026-7332(3908slots)master
0additionalreplica(s)
M:5b38e63a1091baa3a871a52275489a2aa1d28bfb10.21.10.120:7002
slots:894-3398,7333-15332,15949-16383(10940slots)master
0additionalreplica(s)
M:bb1572074d41254e5b4d5aae5c52e54f5129d6d510.21.14.251:7001
slots:(0slots)master
0additionalreplica(s)
M:396a7fbd2ec61752f9e848a1d8cc7b405aef035610.21.14.251:7000
slots:(0slots)master
0additionalreplica(s)
M:9f215e7e4b511f3d2bbf5d734731899b71a62a3b10.21.10.120:7001
slots:0-893,5000-5025,15333-15948(1536slots)master
0additionalreplica(s)
M:0c9b383f65ae4fefc5e02617fb76a845d7510a5310.21.14.251:7002
slots:(0slots)master
0additionalreplica(s)
[OK]Allnodesagreeaboutslotsconfiguration.
>>>Checkforopenslots...
>>>Checkslotscoverage...
[OK]All16384slotscovered.

确认一下状态

[redis@ip-10-21-14-251redis]$./redis-cli-p7000clusternodes
bb1572074d41254e5b4d5aae5c52e54f5129d6d510.21.14.251:7001master-015096118149196connected
9f215e7e4b511f3d2bbf5d734731899b71a62a3b10.21.10.120:7001master-0150961181191714connected0-8935000-502515333-15948
5b38e63a1091baa3a871a52275489a2aa1d28bfb10.21.10.120:7002master-0150961181592313connected894-33987333-1533215949-16383
396a7fbd2ec61752f9e848a1d8cc7b405aef035610.21.14.251:7000myself,master-001connected
4422ab38377fa8828e0f7884570b3b482a66496b10.21.10.120:7000master-0150961181391912connected3399-49995026-7332
0c9b383f65ae4fefc5e02617fb76a845d7510a5310.21.14.251:7002master-015096118129173connected

9. 确认状态OK的话,开始删除节点

./redis-trib.rbdel-node10.21.14.251:7000396a7fbd2ec61752f9e848a1d8cc7b405aef0356
./redis-trib.rbdel-node10.21.14.251:7001bb1572074d41254e5b4d5aae5c52e54f5129d6d5
./redis-trib.rbdel-node10.21.14.251:70020c9b383f65ae4fefc5e02617fb76a845d7510a53

10. 干掉10.21.14.251:7002成功,

[redis@ip-10-21-14-251redis]$./redis-trib.rbdel-node10.21.14.251:70020c9b383f65ae4fefc5e02617fb76a845d7510a53
>>>Removingnode0c9b383f65ae4fefc5e02617fb76a845d7510a53fromcluster10.21.14.251:7002
>>>SendingCLUSTERFORGETmessagestothecluster...
>>>SHUTDOWNthenode.
[envuser@ip-10-21-14-251redis]$./redis-trib.rbcheck10.21.10.120:7000
>>>PerformingClusterCheck(usingnode10.21.10.120:7000)
M:4422ab38377fa8828e0f7884570b3b482a66496b10.21.10.120:7000
slots:3399-4999,5026-7332(3908slots)master
0additionalreplica(s)
M:5b38e63a1091baa3a871a52275489a2aa1d28bfb10.21.10.120:7002
slots:894-3398,7333-15332,15949-16383(10940slots)master
0additionalreplica(s)
M:bb1572074d41254e5b4d5aae5c52e54f5129d6d510.21.14.251:7001
slots:(0slots)master
0additionalreplica(s)
M:396a7fbd2ec61752f9e848a1d8cc7b405aef035610.21.14.251:7000
slots:(0slots)master
0additionalreplica(s)
M:9f215e7e4b511f3d2bbf5d734731899b71a62a3b10.21.10.120:7001
slots:0-893,5000-5025,15333-15948(1536slots)master
0additionalreplica(s)
[OK]Allnodesagreeaboutslotsconfiguration.
>>>Checkforopenslots...
>>>Checkslotscoverage...
[OK]All16384slotscovered.

状态检查

[redis@ip-10-21-14-251redis]$./redis-cli-p7000clusternodes
bb1572074d41254e5b4d5aae5c52e54f5129d6d510.21.14.251:7001master-015096119000946connected
9f215e7e4b511f3d2bbf5d734731899b71a62a3b10.21.10.120:7001master-0150961190210014connected0-8935000-502515333-15948
5b38e63a1091baa3a871a52275489a2aa1d28bfb10.21.10.120:7002master-0150961190109813connected894-33987333-1533215949-16383
396a7fbd2ec61752f9e848a1d8cc7b405aef035610.21.14.251:7000myself,master-001connected
4422ab38377fa8828e0f7884570b3b482a66496b10.21.10.120:7000master-0150961189909312connected3399-49995026-7332

根据上面步骤,删除剩余节点即可。经过测试,应用在迁移过程中,没有受到任何影响。但是应用连接池的IP需要找机会增加10.21.10.120。更多链接,请参考:

Redis Cluster集群部署搭建Redis Cluster 添加/删除 完整折腾步骤

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台