1、准备两个redis集群
1、查看新旧集群的节点(redis实例)
//老集群 ]# redis-cli -h 10.1.1.13 -p 8001 -a admin 10.1.1.13:8001> cluster nodes 0d16af555f59c703e06faf1ed35228c6fd379ecd 10.1.1.13:8001@18001 myself,master - 0 1675152310000 1 connected 0-5460 deed95db95df42100d4736783af101483531b01e 10.1.1.13:8002@18002 master - 0 1675152309000 2 connected 5461-10922 fb8cfed07e8af1a3aaefd5967312d1c54a78e963 10.1.1.13:8003@18003 master - 0 1675152309899 3 connected 10923-16383 af0fbd9877e11e78572c7c01a54ef51459f37ed6 10.1.1.13:8004@18004 slave fb8cfed07e8af1a3aaefd5967312d1c54a78e963 0 1675152310916 4 connected 7c23a23e57d404c024a2dc3a633768cdf9766cdc 10.1.1.13:8005@18005 slave 0d16af555f59c703e06faf1ed35228c6fd379ecd 0 1675152309000 5 connected 7e7823a8948d421c1176a07ef09bf7b0384c417f 10.1.1.13:8006@18006 slave deed95db95df42100d4736783af101483531b01e 0 1675152308000 6 connected //新集群 ]# redis-cli -h 10.1.1.11 -p 7001 -a admin 10.1.1.11:7001> cluster nodes 471bfcf3bcdfc0a794eee25c547bec6e4dcb1fb7 10.1.1.11:7001@17001 myself,master - 0 1675152342000 1 connected 0-5460 7b91a5eaf084ad566c182dc91269ec37c16e7cb4 10.1.1.12:7001@17001 master - 0 1675152342374 3 connected 5461-10922 a5a7f7bc528d509af1b9df8a0926ec5999706552 10.1.1.13:7001@17001 master - 0 1675152343000 5 connected 10923-16383 d0a1f380a20add265f08cf2ba6ff0e0510df3ce0 10.1.1.11:7002@17002 slave a5a7f7bc528d509af1b9df8a0926ec5999706552 0 1675152343399 5 connected a36f84864e5ee8d947d911f88e796d085783b80f 10.1.1.12:7002@17002 slave 471bfcf3bcdfc0a794eee25c547bec6e4dcb1fb7 0 1675152344420 4 connected 1b62eb8bd0e71f4e03840cc522806bf4af98ca88 10.1.1.13:7002@17002 slave 7b91a5eaf084ad566c182dc91269ec37c16e7cb4 0 1675152344000 6 connected
2、向旧集群中写入模拟数据
]# redis-cli -h 10.1.1.13 -p 8001 -a admin -c 10.1.1.13:8001> set hh1 hh1 -> Redirected to slot [5691] located at 10.1.1.13:8002 OK 10.1.1.13:8002> set hh2 hh2 OK 10.1.1.13:8002> set hh3 hh3 -> Redirected to slot [13945] located at 10.1.1.13:8003 OK 10.1.1.13:8003> set hh4 hh4 -> Redirected to slot [1694] located at 10.1.1.13:8001 OK
2、使用dump.rdb文件实现数据迁移
1、关闭新集群的所有节点
//先停止所有的从节点 ]# systemctl stop redis-7002.service //再停止所有的主节点 ]# systemctl stop redis-7001.service
2、持久化数据
- 在旧集群上,依次持久化所有主节点的数据。
//持久化数据 ]# redis-cli -h 10.1.1.13 -p 8001 -a admin bgsave //查看bgsave命令是否已经执行完成(0是已经完成) ]# redis-cli -h 10.1.1.13 -p 8001 -a admin info Persistence | grep 'rdb_bgsave_in_progress' rdb_bgsave_in_progress:0
3、获取dump.rdb文件
- 在旧集群上,依次查看其所有主节点的持久化文件。
//查看dump.rdb文件的目录 redis-cli -h 10.1.1.13 -p 8001 -a admin config get dir 1) "dir" 2) "/data/redis-data-8001 //检测RDB文件 ]# redis-check-rdb /data/redis-data-8001/dump.rdb
4、迁移数据
- 将旧集群的持久化文件dump.rdb对应的迁移到新集群的主节点的数据目录中
]# scp /data/redis-data-8001/dump.rdb [email protected]:/data/redis-data-7001/ ]# scp /data/redis-data-8002/dump.rdb [email protected]:/data/redis-data-7001/ ]# scp /data/redis-data-8003/dump.rdb [email protected]:/data/redis-data-7001/
5、重新启动新集群的所有节点
- 在新集群上,启动主节点前,要关闭AOF数据持久化。
]# vim /usr/local/redis-7001/conf/redis-7001.conf appendonly no
- 在新集群上,启动主节点时,其的数据目录中不能有appendonly.aof文件。
]# rm -f /data/redis-data-7001/appendonly.aof
- 启动所有节点
//先启动所有的主节点 ]# systemctl start redis-7001.service //再启动所有的从节点 ]# systemctl start redis-7002.service
1
# #标签:10.1,1.13,redis,Redis15,集群,7001,connected,data From: https://www.cnblogs.com/maiblogs/p/17080216.html