使用 redis-shake 迁移 redis-cluster
背景:
IDC上云, 有2套redis-cluster需要迁移到云上。 这里我们使用 redis-shake 来做迁移操作。
模拟机房集群(图是我后截的,图上已经有key了):
迁移前, redis-cluster 我们先造点数据进去到机房集群去。脚本如下:
for i in {1..10000}; do echo "set age$i $i" | redis-cli -c -h 172.31.1.133 -p 6391 done
然后,先找出老的redis cluster的master节点信息, redis-shake迁移要用到。如下:
echo 'cluster nodes' | redis-cli -c -h 172.31.1.133 -p 6391 | egrep master
1154ebeb83a53ad7ac09d14b49f4ec28af91e1e5 172.31.1.133:6392@16392 master - 0 1571397581506 13 connected 4097-8193 248a9d4e2ab4da9875c2ff2fb9c222be0b07deb7 172.31.1.134:6393@16393 master - 0 1571397583018 2 connected 8194-12290 94d42bffd85e4c8acf49c64b182023e9381805aa 172.31.1.134:6352@16352 master - 0 1571397582508 11 connected 12291-16383 1dd160e9fbfe4bb5d8c251053c9d7b752b23d317 172.31.1.134:6353@16353 master - 0 1571397582608 10 connected 0-4096
我这里的是如下4个节点为master:
172.31.1.133:6392;172.31.1.134:6393;172.31.1.134:6352;172.31.1.134:6353
然后,找出 新的redis cluster 的master节点信息,redis-shake迁移要用到。如下:
echo 'cluster nodes' | redis-cli -h 172.31.1.133 -p 6394 | egrep master
9a81aecf9ad5d2bb6104134107215b528476eec6 172.31.1.134:6397@16397 master - 0 1571398028000 1 connected 8194-12290 2b1bf7f11258ac363962c6216d19687e2d9e6bbe 172.31.1.133:6397@16397 master - 0 1571398027348 4 connected 12291-16383 3aec1bed303b228290886eb21af0a9907f4c22c9 172.31.1.134:6396@16396 master - 0 1571398025000 5 connected 4097-8193 d8173ea22c504639e3102991876edd401ec4f3d9 172.31.1.133:6394@16394 myself,master - 0 1571398027000 0 connected 0-4096
我这里的是如下4个节点为master:
172.31.1.134:6397;172.31.1.133:6397;172.31.1.134:6396;172.31.1.133:6394
然后,编辑 redis-shake 的配置
vim redis-shake.conf 修改source部分和target部分的内容如下:
source.type = cluster source.address = 172.31.1.133:6392;172.31.1.134:6393;172.31.1.134:6352;172.31.1.134:6353 source.password_raw = source.auth_type = auth target.type = cluster target.address = 172.31.1.134:6397;172.31.1.133:6397;172.31.1.134:6396;172.31.1.133:6394 target.password_raw = target.auth_type = auth target.db = -1
启动迁移进程:
./redis-shake.linux -type sync -conf redis-shake.conf
下图是迁移过程中,redis-shake的日志(最后一行就是写入到目标redis cluster的数据量瞬时值)