现有个需求是redis-cluster到redis-cluster的快速迁移,并且迁移过后两套redis-cluster都要独立使用无依赖
方法一:使用前面redis迁移中的在线迁移工具
redis-migration(劣势:不支持redis4.0) redis-migration-tools(劣势:不支持redis4.0) redis-sync-manage:redis-port封装版本((劣势:不支持密码模式)) 等工具
刚好线上是redis4.0,有的无的因为各种原因无法使用上面的各种工具
方法二:
参考:【Redis】redis迁移数据到redis-cluster 劣势:步骤相对麻烦,档redis rdb文件过大时,迁移时间过长
方法三:本文需要详细说的一种办法(假设集群是三个节点)
1.新的集群(75,74,72)当作slave加入原集群中,等待同步数据 2.等待数据同步完毕将其剔除集群 3.关闭同步完的三台节点 4.编辑nodes.conf文件 原nodes.conf应该是这样 4ce6e03ba48336569efcc7bbaab6edb538cb1a90 172.23.3.74:6379@16379 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536238939051 19 connected aa8cf0b64f91c77846862909f9cec0c20ea54c1e 172.23.3.72:6379@16379 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536238941056 18 connected 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 master - 0 1536238940000 17 connected 0-502 1753-5930 12175-12671 f2d9ac982c1d621850638a474ed4b8ffc5063d28 172.31.47.95:6379@16379 master - 0 1536238939000 18 connected 503-1752 5931-6380 10925-11274 12672-16383 4dd59a9480a669f308a6819a3538e3340ed855cf 172.23.3.75:6379@16379 myself,slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536238940000 0 connected c4c7df1e21399984d909761441be80b178ef62a5 172.31.47.95:6380@16380 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536238941000 19 connected 9a6307f16ea34354e701c4dbe04ecb5c77021938 172.31.37.24:6380@16380 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536238942381 18 connected a7f923aaee624acf672f8704ffb4b27b48a56352 172.31.37.24:6379@16379 master - 0 1536238942061 19 connected 6381-10924 11275-12174 5dcc47b5477628895ce98e4c06f8e228a9c4fe5f 172.31.36.20:6380@16380 slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536238941373 17 connected vars currentEpoch 19 lastVoteEpoch 0 修改nodes.conf为 4ce6e03ba48336569efcc7bbaab6edb538cb1a90 172.23.3.74:6379@16379 master - 0 1536238942061 19 connected 6381-10924 11275-12174 aa8cf0b64f91c77846862909f9cec0c20ea54c1e 172.23.3.72:6379@16379 master - 0 1536238939000 18 connected 503-1752 5931-6380 10925-11274 12672-16383 4dd59a9480a669f308a6819a3538e3340ed855cf 172.23.3.75:6379@16379 myself,master - 0 1536238940000 17 connected 0-502 1753-5930 12175-12671 vars currentEpoch 19 lastVoteEpoch 0 以74为例,修改思路: 找到74的主37.24,替换74的slot信息为37.24的slot信息master - 0 1536238942061 19 connected 6381-10924 11275-12174 每台机器的master前面分别加上myself信息 5.重启75,74,72三台的redis集群并校验 可将2-5步写成脚本自动化完成,分钟级就可以复制出一套集群!
补充:还有可能是机房迁移,那样只需要一套集群可用就好了,这个需求更简单!
直接关掉原机房的redis服务,新机房的redis提升为master,修改域名解析就好了,切换过程如下
6379 down机后,6380会被提升为master,6379重启后会变成slave 加入到6380下 cluster info变化流程如下: 正常情况下 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 127.0.0.1 -p 6379 -c cluster nodes f2d9ac982c1d621850638a474ed4b8ffc5063d28 172.31.47.95:6379@16379 master - 0 1536302125000 18 connected 804-1752 5931-6380 10925-11274 12672-16383 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536302126000 20 connected a7f923aaee624acf672f8704ffb4b27b48a56352 172.31.37.24:6379@16379 master - 0 1536302126573 21 connected 787-803 6381-10924 11275-12174 596012a79c3699692651fe47bc1a5a982762676a 172.31.47.95:6380@16380 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536302124569 21 connected dd4d8dbe8aee4ef0e31b8908297ca64092302bfd 172.31.37.24:6380@16380 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536302125000 21 connected 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 myself,master - 1536291530036 1536291530036 20 connected 0-786 1753-5930 12175-12671 down掉master 6379后 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 172.31.37.24 -p 6379 -c cluster nodes|grep -i 36 a7f923aaee624acf672f8704ffb4b27b48a56352 172.31.37.24:6379@16379 myself,master - 1536291532036 1536291532036 21 connected 787-803 6381-10924 11275-12174 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536302197019 20 connected f2d9ac982c1d621850638a474ed4b8ffc5063d28 172.31.47.95:6379@16379 master - 0 1536302196019 18 connected 804-1752 5931-6380 10925-11274 12672-16383 596012a79c3699692651fe47bc1a5a982762676a 172.31.47.95:6380@16380 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536302198019 18 connected dd4d8dbe8aee4ef0e31b8908297ca64092302bfd 172.31.37.24:6380@16380 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536302195000 21 connected 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 master,fail - 1536302172919 1536302169019 20 disconnected 0-786 1753-5930 12175-12671 几秒后选举成功,6380提升 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 172.31.37.24 -p 6379 -c cluster nodes|grep -i 36.20 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 master - 0 1536302200019 22 connected 0-786 1753-5930 12175-12671 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 master,fail - 1536302172919 1536302169019 20 disconnected 重启6379几秒后重新加入集群 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 172.31.37.24 -p 6379 -c cluster nodes|grep -i 36.20 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 master - 0 1536302275023 22 connected 0-786 1753-5930 12175-12671 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 slave 95c8168dab83f7156c1b0ba34686917972259517 0 1536302273023 22 connected
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。