redis单实例数据迁移到cluster(redis5.0.5)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis单实例数据迁移到cluster(redis5.0.5)相关的知识,希望对你有一定的参考价值。

参考技术A 1、检查redis集群状态

/app/redis_6379/bin/redis-cli -p 6379 -a 123456 --cluster check 10.1.1.90:6379

2、将所有master上的slots重新分配到一个master上

/app/redis_6379/bin/redis-cli -p 6379 -a 123456 --cluster reshard --cluster-from f2e8c51ea2ab2a0a976f2c0eec89262f060b623f --cluster-to 79d21bd1d8c2f5d8af5b96687115ad4a290cc305 --cluster-slots 5462 --cluster-yes 10.1.1.90:6379

/app/redis_6379/bin/redis-cli -p 6379 -a 123456 --cluster reshard --cluster-from 9ba4348d48656eaab300a49e7dfb08f6d2ddb61e --cluster-to 79d21bd1d8c2f5d8af5b96687115ad4a290cc305 --cluster-slots 5462 --cluster-yes 10.1.1.90:6379

3、停止除唯一持有slots的master的其他节点

4、停止唯一持有slots的master节点

5、将单实例的持久化文件rdb/aof文件拷贝到唯一持有slots的master节点的数据目录下

6、启动唯一持有slots的master节点

7、启动除唯一持有slots的master的其他节点

8、在集群masters间重新分配slots

/app/redis_6379/bin/redis-cli -p 6379 -a 123456 --cluster reshard --cluster-from 79d21bd1d8c2f5d8af5b96687115ad4a290cc305 --cluster-to f2e8c51ea2ab2a0a976f2c0eec89262f060b623f  --cluster-slots 5462 --cluster-yes 10.1.1.90:6379

/app/redis_6379/bin/redis-cli -p 6379 -a 123456 --cluster reshard --cluster-from 79d21bd1d8c2f5d8af5b96687115ad4a290cc305 --cluster-to 9ba4348d48656eaab300a49e7dfb08f6d2ddb61e --cluster-slots 5462 --cluster-yes 10.1.1.90:6379

9、检查redis集群状态

/app/redis_6379/bin/redis-cli -p 6379 -a 123456 --cluster check 10.1.1.90:6379

Redis单实例数据迁移到集群

环境说明

单机redis

192.168.41.101:6379

redis集群

192.168.41.101:7000 master
192.168.41.101:7001 master
192.168.41.101:7002

192.168.41.102:7000 master
192.168.41.102:7001
192.168.41.102:7002

迁移步骤

查看集群状态及节点槽分布

[[email protected] bin]# ./redis-cli -c -p 7000
127.0.0.1:7000> cluster nodes
ab6d9f956de325cb4cf001abc31df365a5db5234 192.168.41.102:7001 slave 923c9ea13ec8fc19bed309dfbfad094320e1ca41 0 1560304528263 7 connected
48629733acbb8a580a39403dfac92845d63c97b3 192.168.41.101:7001 master - 0 1560304529768 2 connected 5461-10921
2cec8ac00f760c45d86f7903cefad85ec36704e7 192.168.41.102:7002 slave 923c9ea13ec8fc19bed309dfbfad094320e1ca41 0 1560304531271 7 connected
923c9ea13ec8fc19bed309dfbfad094320e1ca41 192.168.41.101:7000 myself,master - 0 0 7 connected 0-5460
e65b319e83997ed6f5323a26aaccba3f35522cbd 192.168.41.101:7002 slave 923c9ea13ec8fc19bed309dfbfad094320e1ca41 0 1560304532274 7 connected
5c0888d5bcceda2904311cbd5405596217c48105 192.168.41.102:7000 master - 0 1560304530268 4 connected 10922-16383
[[email protected] src]# ./redis-trib.rb check 192.168.41.101:7000
>>> Performing Cluster Check (using node 192.168.41.101:7000)
M: 923c9ea13ec8fc19bed309dfbfad094320e1ca41 192.168.41.101:7000
   slots:0-5460 (5461 slots) master
   3 additional replica(s)
S: ab6d9f956de325cb4cf001abc31df365a5db5234 192.168.41.102:7001
   slots: (0 slots) slave
   replicates 923c9ea13ec8fc19bed309dfbfad094320e1ca41
M: 48629733acbb8a580a39403dfac92845d63c97b3 192.168.41.101:7001
   slots:5461-10921 (5461 slots) master
   0 additional replica(s)
S: 2cec8ac00f760c45d86f7903cefad85ec36704e7 192.168.41.102:7002
   slots: (0 slots) slave
   replicates 923c9ea13ec8fc19bed309dfbfad094320e1ca41
S: e65b319e83997ed6f5323a26aaccba3f35522cbd 192.168.41.101:7002
   slots: (0 slots) slave
   replicates 923c9ea13ec8fc19bed309dfbfad094320e1ca41
M: 5c0888d5bcceda2904311cbd5405596217c48105 192.168.41.102:7000
   slots:10922-16383 (5462 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

把101:7001和102:7000两个master的slots转移到101:7000上

./redis-trib.rb reshard --from 5c0888d5bcceda2904311cbd5405596217c48105 --to 923c9ea13ec8fc19bed309dfbfad094320e1ca41  --slots 5462 --yes 192.168.41.101:7000

./redis-trib.rb reshard --from 48629733acbb8a580a39403dfac92845d63c97b3 --to 923c9ea13ec8fc19bed309dfbfad094320e1ca41  --slots 5461 --yes 192.168.41.101:7000

 

查看转以后槽点分配

>>> Performing Cluster Check (using node 192.168.41.101:7000)
M: 923c9ea13ec8fc19bed309dfbfad094320e1ca41 192.168.41.101:7000
   slots:0-16383 (16384 slots) master
   3 additional replica(s)
S: ab6d9f956de325cb4cf001abc31df365a5db5234 192.168.41.102:7001
   slots: (0 slots) slave
   replicates 923c9ea13ec8fc19bed309dfbfad094320e1ca41
M: 48629733acbb8a580a39403dfac92845d63c97b3 192.168.41.101:7001
   slots: (0 slots) master
   0 additional replica(s)
S: 2cec8ac00f760c45d86f7903cefad85ec36704e7 192.168.41.102:7002
   slots: (0 slots) slave
   replicates 923c9ea13ec8fc19bed309dfbfad094320e1ca41
S: e65b319e83997ed6f5323a26aaccba3f35522cbd 192.168.41.101:7002
   slots: (0 slots) slave
   replicates 923c9ea13ec8fc19bed309dfbfad094320e1ca41
M: 5c0888d5bcceda2904311cbd5405596217c48105 192.168.41.102:7000
   slots: (0 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

把192.168.41.101:6379的appendonly.aof 文件复制到101:7000的aof文件目录下

cp 6379目录/appendonly.aof   7000目录

重启101:7000节点加载aof文件

[[email protected] bin]# ./redis-cli -c -p 7000 shutdown

[[email protected] bin]# ./redis-server ../redis.conf 

查看数据是否正确

dbsize

 

将101:7000的槽 均匀分配给其他两个master节点

./redis-trib.rb reshard --from 923c9ea13ec8fc19bed309dfbfad094320e1ca41  --to 5c0888d5bcceda2904311cbd5405596217c48105  --slots 5462 --yes 192.168.41.101:7000

./redis-trib.rb reshard --from 923c9ea13ec8fc19bed309dfbfad094320e1ca41  --to 48629733acbb8a580a39403dfac92845d63c97b3  --slots 5461 --yes 192.168.41.101:7000

再次查看集群状态和槽分配。

 

以上是关于redis单实例数据迁移到cluster(redis5.0.5)的主要内容,如果未能解决你的问题,请参考以下文章

Redis单实例数据迁移到集群

redis 版本升级数据迁移使用Redis-Shake

【Redis】Redis Cluster-集群数据迁移

浅谈集群版Redis和Gossip协议

问题追查记海外aws上redis-cluster单实例抖动问题追查

redis-cluster 迁移过程错误记录