redis 数据迁移(RDB文件-》集群)

461 阅读3分钟

暂且使用此集群:redis6.09 集群安装(docker-compose)

1. 迁移工具

github.com/tanruixing8…
另外自己做了一个包含此工具的镜像,可以下载使用

docker pull lyman1567/redis-migrate-tool

2 迁移数据配置

#rmt.conf
[source]
type: rdb file
servers:
 - /usr/local/etc/redis/dump.rdb
[target]
type: redis cluster
servers:
 - 10.0.0.10:6379
[common]
listen: 0.0.0.0:8888

3 准备好后,开始部署

$ docker ps
CONTAINER ID   IMAGE                                 COMMAND                 CREATED          STATUS                          PORTS                    NAMES
bea2824575f6   redis-cluster-node                    "/bin/bash /start.sh"   39 minutes ago   Up 39 minutes                   0.0.0.0:6379->6379/tcp   docker-redis-cluster-605_redis-1_1
a3d701b0ec4f   redis-cluster-node                    "/bin/bash /start.sh"   39 minutes ago   Up 39 minutes                   0.0.0.0:6382->6379/tcp   docker-redis-cluster-605_redis-4_1
075c167803af   redis-cluster-node                    "/bin/bash /start.sh"   39 minutes ago   Up 39 minutes                   0.0.0.0:6383->6379/tcp   docker-redis-cluster-605_redis-5_1
24e69de07e17   redis-cluster-node                    "/bin/bash /start.sh"   39 minutes ago   Up 39 minutes                   0.0.0.0:6380->6379/tcp   docker-redis-cluster-605_redis-2_1
7105bf04fcb7   redis-cluster-node                    "/bin/bash /start.sh"   39 minutes ago   Up 39 minutes                   0.0.0.0:6381->6379/tcp   docker-redis-cluster-605_redis-3_1
ca51ec501820   redis-cluster-node                    "/bin/bash /start.sh"   39 minutes ago   Up 39 minutes                   0.0.0.0:6384->6379/tcp   docker-redis-cluster-605_redis-6_1
$ docker images
lyman1567/redis-migrate-tool   latest    72c4a8146559   11 hours ago     473MB

$ docker run -it --network=container:bea2824575f6 --pid=container:bea2824575f6 -v C:/redis-migrate-tool/data:/usr/local/etc lyman1567/redis-migrate-tool bash

4 进入集群容器执行

[root@bea2824575f6 /]# cd /usr/local/etc
[root@bea2824575f6 etc]# ls
conf  redis
[root@bea2824575f6 etc]# cd conf
[root@bea2824575f6 etc]# vi rmt.conf
[source]
type: rdb file
servers:
 - /usr/local/etc/redis/dump.rdb
[target]
type: redis cluster
servers:
 - 10.0.0.10:6379
[common]
listen: 0.0.0.0:8888

5 确认好后,执行

[root@bea2824575f6 conf]# redis-migrate-tool -c rmt.conf -o output.log -d

6 查看log

[2021-01-30 14:01:58.742] rmt_core.c:525 Nodes count of source group : 1 [2021-01-30 14:01:58.742] rmt_core.c:526 Total threads count : 12 [2021-01-30 14:01:58.742] rmt_core.c:527 Read threads count assigned: 1 [2021-01-30 14:01:58.742] rmt_core.c:528 Write threads count assigned: 1 [2021-01-30 14:01:58.744] rmt_core.c:2443 Total threads count in fact: 1 [2021-01-30 14:01:58.745] rmt_core.c:2444 Read threads count in fact: 0 [2021-01-30 14:01:58.745] rmt_core.c:2445 Write threads count in fact: 1 [2021-01-30 14:01:58.745] rmt_core.c:2487 write thread(0): [2021-01-30 14:01:58.745] rmt_core.c:2493 /usr/local/etc/redis/dump.rdb [2021-01-30 14:01:58.745] rmt_connect.c:798 bind on p 8 to addr '0.0.0.0:8888' failed: Address already in use [2021-01-30 14:01:58.745] rmt_connect.c:1690 ERROR: get proxy connect failed. [2021-01-30 14:02:28.174] rmt_core.c:525 Nodes count of source group : 1 [2021-01-30 14:02:28.174] rmt_core.c:526 Total threads count : 12 [2021-01-30 14:02:28.174] rmt_core.c:527 Read threads count assigned: 1 [2021-01-30 14:02:28.175] rmt_core.c:528 Write threads count assigned: 1 [2021-01-30 14:02:28.175] rmt_core.c:2443 Total threads count in fact: 1 [2021-01-30 14:02:28.175] rmt_core.c:2444 Read threads count in fact: 0 [2021-01-30 14:02:28.175] rmt_core.c:2445 Write threads count in fact: 1 [2021-01-30 14:02:28.176] rmt_core.c:2487 write thread(0): [2021-01-30 14:02:28.176] rmt_core.c:2493 /usr/local/etc/redis/dump.rdb [2021-01-30 14:02:28.176] rmt_core.c:2550 migrate job is running... [2021-01-30 14:04:06.171] rmt_redis.c:6685 Rdb file for node[/usr/local/etc/redis/dump.rdb] parsed finished, use: 97 s.

可以看出来:rdb总用时97秒

7 查看集群数据

redis--port:6379

127.0.0.1:6379> info
....
# Keyspace
db0:keys=695608,expires=0,avg_ttl=0

如果想用两个不同的容器加入同一网络,进行数据迁移可以参考下面博文:
www.cnblogs.com/ejiyuan/p/1…