三、redis6 集群 在线迁移

环境:

1.基于【redis6 集群部署

原集群 新集群
192.168.109.137:7000 192.168.109.139:7000
192.168.109.137:7001 192.168.109.139:7001
192.168.109.137:7002 192.168.109.139:7002
192.168.109.138:7000 192.168.109.140:7000
192.168.109.138:7001 192.168.109.140:7001
192.168.109.138:7002 192.168.109.140:7002

2.在线迁移就得保障业务的可用性;这就必须要求新旧集群主机间网络连通性,业务连接redis集群接口配置文件无论从哪一个节点都能操作集群

1).模拟线上环境,后台运行上一章节redis6 集群 扩缩容中提到的脚本set_key.sh(注意增加配置,相当于修改业务接口配置文件操作)模拟线上实时写入key

 

操作:

1.查看老集群状态、key等信息

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster info 192.168.109.137:7000 -a 'wang!321' 2>/dev/null

 

 

 [apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster check 192.168.109.137:7000 -a 'wang!321' 2>/dev/null

2.参考【redis6 集群部署】将新集群节点都安装上redis,并把各节点加入老集群先

加入规划:

3主:192.168.109.139:7000、7001、7002

3从:192.168.109.140:7000、7001、7002

3从分别指向3主

[apprun@localhost ~]$ /apprun/redis/bin/redis-cli --cluster add-node 192.168.109.139:7000 192.168.109.137:7000 -a 'wang!321'

[apprun@localhost ~]$ /apprun/redis/bin/redis-cli --cluster add-node 192.168.109.139:7001 192.168.109.137:7000 -a 'wang!321'

[apprun@localhost ~]$ /apprun/redis/bin/redis-cli --cluster add-node 192.168.109.139:7002 192.168.109.137:7000 -a 'wang!321'

 

 

 [apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster check 192.168.109.137:7000 -a 'wang!321' 2>/dev/null

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster add-node 192.168.109.140:7000 192.168.109.137:7000 -a 'wang!321' --cluster-slave --cluster-master-id c7a05ce237bd8177af154af3ce48fd89d7c86453

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster add-node 192.168.109.140:7001 192.168.109.137:7000 -a 'wang!321' --cluster-slave --cluster-master-id 8f2ed53955dfe9fc22de255e91ba2a9e696055b2

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster add-node 192.168.109.140:7002 192.168.109.137:7000 -a 'wang!321' --cluster-slave --cluster-master-id e30842d360247cad83e2b2e4d7369e65607fcb85

 

 

 

开始迁移:

1.先查看当前集群状态

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster check 192.168.109.137:7000 -a 'wang!321' 2>/dev/null

M: 5ff72f7e629f8dd290a66e06d73e85378e4e1349 192.168.109.138:7000
slots:[5516-10922] (5407 slots) master

1 additional replica(s)

M: fe0d43871950c7b2a9b7082bfe9b52f56aa4c65f 192.168.109.138:7002
slots:[0-5515],[10923-10976] (5570 slots) master

1 additional replica(s)

M: 776134007b961293086f6248b0ad05a094a5f19a 192.168.109.138:7001
slots:[10977-16383] (5407 slots) master

1 additional replica(s)

老集群的3主分别如上,并各有一个从,接下来我们一个一个主的迁移,先迁移192.168.109.138:7000

如下;

1).先删除192.168.109.138:7000的从节点

S: 98ec10ff7e5b788130dd5283422ae52358599084 192.168.109.137:7002
slots: (0 slots) slave
replicates 5ff72f7e629f8dd290a66e06d73e85378e4e1349

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster del-node 192.168.109.137:7002 98ec10ff7e5b788130dd5283422ae52358599084 -a 'wang!321'

 

 

 

 

 

 2).分片迁移,即迁移槽;192.168.109.138:7000 迁移到 192.168.109.139:7000

查看192.168.109.138:7000 老节点的槽数量,并全部迁移到192.168.109.139:7000

192.168.109.138:7000 (5ff72f7e...) -> 449 keys | 5407 slots | 0 slaves.

M: 5ff72f7e629f8dd290a66e06d73e85378e4e1349 192.168.109.138:7000
slots:[5516-10922] (5407 slots) master

M: c7a05ce237bd8177af154af3ce48fd89d7c86453 192.168.109.139:7000
slots: (0 slots) master
1 additional replica(s)

命令:

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster reshard 192.168.109.137:7000 -a 'wang!321' --cluster-from 5ff72f7e629f8dd290a66e06d73e85378e4e1349 --cluster-to c7a05ce237bd8177af154af3ce48fd89d7c86453 --cluster-slots 5407 --cluster-yes

 

 

 [apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster check 192.168.109.137:7000 -a 'wang!321' 2>/dev/null

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster info 192.168.109.137:7000 -a 'wang!321' 2>/dev/null

 

 

 3).192.168.109.138:7000老节点删除~

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster del-node 192.168.109.138:7000 5ff72f7e629f8dd290a66e06d73e85378e4e1349 -a 'wang!321'

 

 

 

 

 

 至此,老集群的一个主节点就迁移完成了~......其他老集群主节点参照上面步骤操作!!!

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster del-node 192.168.109.137:7001 5f9f852f5ebf0d6ccc357e1eadfad7a2a4cade47 -a 'wang!321'

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster reshard 192.168.109.137:7000 -a 'wang!321' --cluster-from 776134007b961293086f6248b0ad05a094a5f19a --cluster-to 8f2ed53955dfe9fc22de255e91ba2a9e696055b2 --cluster-slots 5407 --cluster-yes

[apprun@localhost ~]$ /apprun/redis/bin/redis-cli --cluster del-node 192.168.109.138:7001 776134007b961293086f6248b0ad05a094a5f19a -a 'wang!321'

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

[apprun@localhost ~]$ /apprun/redis/bin/redis-cli --cluster del-node 192.168.109.137:7000 79d3d38b893eb9e301481d04fe39fc1ff54d2155 -a 'wang!321'

[apprun@localhost ~]$ /apprun/redis/bin/redis-cli --cluster reshard 192.168.109.139:7000 -a 'wang!321' --cluster-from fe0d43871950c7b2a9b7082bfe9b52f56aa4c65f --cluster-to e30842d360247cad83e2b2e4d7369e65607fcb85 --cluster-slots 5570 --cluster-yes

[apprun@localhost ~]$ /apprun/redis/bin/redis-cli --cluster del-node 192.168.109.138:7002 fe0d43871950c7b2a9b7082bfe9b52f56aa4c65f -a 'wang!321'

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

迁移完成:

 

 

 在线迁移期间通过模拟在线环境,利用脚本set_key.sh每秒向集群写入key共写入3037个,我们接下来核对这些:

 

 

查询:

 

 

 

 

 

 由此可验证在线集群迁移成功~!!!

 

posted on 2022-03-03 22:59  NG-承  阅读(345)  评论(0编辑  收藏  举报

导航