Building on the success of Redis data migration (RDB file – cluster), migrate a single node to a cluster

Note the file formats involved: Make sure the newline encoding is -LF(UNIX)

1. Check network connectivity

First check the network segment used by the cluster:

$ docker network ls
NETWORK ID     NAME                            DRIVER    SCOPE
bfa40a6eb2ba   bridge                          bridge    local
b6055b32849c   docker-redis-cluster_redisnet   bridge    local
Copy the code

The cluster uses the network docker-Redis-cluster_redisnet

2 Single-node Redis

2.1 Configuration File

redis.conf

port 6379
cluster-enabled no
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly no
Copy the code

2.2 docker – compose. Yml

Docker-redis-cluster_redisnet — external:true

version: '3'
networks:
    docker-redis-cluster_redisnet:
      external: true
services:
  redis:
    image: Redis: 6.0.9
    container_name: redis
    hostname: redis
    restart: always
    ports:
      - 7000: 6379
    networks:
      docker-redis-cluster_redisnet:
        ipv4_address: 10.0. 09.
    volumes:
      - ./conf/redis.conf:/etc/redis/redis.conf
      - ./data/:/data/
    command:
      redis-server /etc/redis/redis.conf --appendonly no
Copy the code

2.3 Deploying a Single-node Redis

$ docker-compose up --build -d
Creating redis ... done
Copy the code

3. Single node: Migrate the cluster

3.1 Obtaining migration Mirrors

$ docker pull lyman1567/redis-migrate-tool
Using default tag: latest
latest: Pulling from lyman1567/redis-migrate-tool
2d473b07cdd5: Pull complete
db3f9a69e07b: Pull complete
Digest: sha256:c6d39642f42d1882058664a10920cdff97b1439d4c5a91593549d8c1b3e68529
Status: Downloaded newer image for lyman1567/redis-migrate-tool:latest
docker.io/lyman1567/redis-migrate-tool:latest
Copy the code

3.2 Migrating Data Configuration (rmt.conf)

C:/ redis-migrant-tool /data/conf/rmt.conf Note: cluster-redis — change type:single to type: redis cluster

# rrmt. conf [source] type: single Servers: -10.0.0.9:6379 [target] type: redis cluster servers: -10.0.0.10:6379 [common] Listen: 0.0.0.0:8888Copy the code

3.3 Starting to Embed a Single Node

$ docker ps
CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS          PORTS                    NAMES
8986142ff4d4   redis:6.0.9          "Docker - entrypoint. S..."11 minutes ago Up 11 minutes 0.0.0.0:7000->6379/ TCP redis 9775b194c25b redis-cluster-node"/bin/bash /start.sh"51 minutes ago Up 51 minutes 0.0.0.0:6380->6379/ TCP docker-redis-cluster_redis-2_1 419e4364c06f Redis-cluster-node"/bin/bash /start.sh"51 minutes ago Up 51 minutes 0.0.0.0:6384->6379/ TCP docker-cluster_redis-6_1 e3a6230f2a20 Redis-cluster-node"/bin/bash /start.sh"51 minutes ago Up 51 minutes 0.0.0.0:6382->6379/ TCP docker-cluster_cluster_redis-4_1 bf62da9c04d9 Redis-cluster-node"/bin/bash /start.sh"51 minutes ago Up 51 minutes 0.0.0.0:6381->6379/ TCP docker-redis-cluster_redis-3_1 a507843f88eb Redis-cluster-node"/bin/bash /start.sh"51 minutes ago Up 51 minutes 0.0.0.0:6379->6379/ TCP docker-redis-cluster_redis-1_1 843d7f746595 Redis-cluster-node"/bin/bash /start.sh"51 minutes ago Up 51 minutes 0.0.0.0:6383->6379/ TCP docker-cluster_redis-5_1Copy the code

Embed the tool in the single node of name:redis

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

Copy the code

4. Access the container to verify the migration configuration

[root@redis /]# cd /usr/local/etc
[root@redis etc]# ls
rmt.conf
[root@redis etc]# vi rmt.conf
[source]
type: Single Servers: -10.0.0.9:6379 [target]type: Redis cluster Servers: -10.0.0.10:6379 [common] listen: 0.0.0.0:8888Copy the code

5. Perform migration and view the output.log file

5.1 Performing Migration

[root@redis etc]# redis-migrate-tool -c rmt.conf -o output.log -d
[root@redis etc]#
Copy the code

5.2 Viewing the output.log file

Temporary files such as node10.0.0.9[email protected] are displayed in the same directory as output.log. If the temporary files disappear, the migration is complete

[2021-01-31 08:09:52.784] RMt_core. c:525 Nodes count of source group: 1 [2021-01-31 08:09:52.784] RMt_core. C :526 Total Threads count: 12 [2021-01-31 08:09:52.785] rmt_core. C :527 Read threads count Assigned: 1 [2021-01-31 08:09:52.785] RMt_core. C :528 Write Threads count Assigned: 1 [2021-01-31 08:09:52.785] rmt_core.c:836 instances_by_host: [2021-01-31 08:09:52.786] rmT_core.c :840 10.0.9:6379 [2021-01-31 08:09:52.786] RMt_core.c :842 [2021-01-31 08:09:52.786 08:09:52.786] rmT_core.c :2443 Total Threads Count in Fact: 2 [2021-01-31 08:09:52.786] rmt_core.c:2444 Read Threads count in fact: 1 [2021-01-31 08:09:52.786] rmt_core.c:2445 Write Threads Count in Fact: 1 [2021-01-31 08:09:52.787] rmt_core.c:2454 Read thread(0): [2021-01-31 08:09:52.787] rmt_core.c:2460 10.0.9:6379 [2021-01-31 08:09:52.787] RMt_core.c :2487 Write thread(0): [2021-01-31 08:09:52.787] RMt_core. C :2493 10.0.9:6379 [2021-01-31 08:09:52.788] RMt_core. C :2550 Migrate job is running... [2021-01-31 08:09:52.788] RMt_redis. C :1735 Start connecting line to MASTER[10.0.0.9:6379]. [2021-01-31 08:09:52.788] Rmt_redis. c:1769 Master[10.0.0.9:6379] to PING, Replication can continue... [2021-01-31 08:09:52.788] rmt_redis.c:1080 Partial resynchronization for MASTER[10.0.9:6379] Not possible (no cached) Master). [2021-01-31 08:09:52.798] rmt_redis. C :1139 Full resync from master [10.0.0.9:6379]: 59 f526849c29aa8b2dbb2d835fc85bc91d326739:0 [the 2021-01-31 08:10:59. 012] rmt_redis. C: 1546 MASTER < - > SLAVE sync: Receiving 1151163248 bytes from master[10.0.0.9:6379] [2021-01-31 08:11:44.377] rmt_redis. C :1652 master <-> SLAVE sync: RDB data for nodes [10.0.0.9:6379] is received, used: 111 s [2021-01-31 08:11:44.377] rmt_redis. C :1672 RDB file node10.0.0.9:6379-1612080592798302-63. RDB write complete [2021-01-31 08:13:31.756] rmt_redis.c:6685 Rdb file for node[10.0.0.9:6379] Parsed finished, use: 107 S. [2021-01-31 08:13:31.873] rmt_redis. C :6793 All Nodes' RDB file parsed finished for this write thread(0).Copy the code

6. Verify the cluster

127.0.0.1:6379 > info...# Keyspace
db0:keys=495601,expires=0,avg_ttl=0
Copy the code