1. 遷移工具
另外自己做了一個(gè)包含此工具的鏡像,可以下載使用
docker pull lyman1567/redis-migrate-tool復(fù)制代碼
2 遷移數(shù)據(jù)配置
#rmt.conf[source]type: rdb fileservers: - /usr/local/etc/redis/dump.rdb[target]type: redis clusterservers: - 10.0.0.10:6379[common]listen: 0.0.0.0:8888復(fù)制代碼
3 準(zhǔn)備好后厘贼,開始部署
$ docker psCONTAINER ID? IMAGE? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? COMMAND? ? ? ? ? ? ? ? CREATED? ? ? ? ? STATUS? ? ? ? ? ? ? ? ? ? ? ? ? PORTS? ? ? ? ? ? ? ? ? ? NAMESbea2824575f6? 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_1a3d701b0ec4f? 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_1075c167803af? 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_124e69de07e17? 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_17105bf04fcb7? 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_1ca51ec501820? 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 imageslyman1567/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復(fù)制代碼
4 進(jìn)入集群容器執(zhí)行
[root@bea2824575f6 /]# cd /usr/local/etc[root@bea2824575f6 etc]# lsconf? redis[root@bea2824575f6 etc]# cd conf[root@bea2824575f6 etc]# vi rmt.conf[source]type: rdb fileservers: - /usr/local/etc/redis/dump.rdb[target]type: redis clusterservers: - 10.0.0.10:6379[common]listen: 0.0.0.0:8888復(fù)制代碼
5 確認(rèn)好后,執(zhí)行
[root@bea2824575f6 conf]# redis-migrate-tool -c rmt.conf -o output.log -d復(fù)制代碼
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總用時(shí)97秒
7 查看集群數(shù)據(jù)
redis--port:6379
127.0.0.1:6379> info....# Keyspacedb0:keys=695608,expires=0,avg_ttl=0復(fù)制代碼
如果想用兩個(gè)不同的容器加入同一網(wǎng)絡(luò)娄周,進(jìn)行數(shù)據(jù)遷移可以參考下面博文: