首页 > 技术文章 > REDIS数据备份集群部署和双集群同步工具redis-migrate-tool

cp-miao 2018-11-06 09:59 原文

REDIS 版本 < 4.0 笔者用的是 v=3.0.7

REDIS集群创建镜像:registry.cn-shenzhen.aliyuncs.com/cp_m/redis-trib:0.1.3

REDIS节点镜像:registry.cn-shenzhen.aliyuncs.com/cp_m/redis:3.0.7

REDIS数据同步工具:https://github.com/vipshop/redis-migrate-tool   alessandrob/redis-migrate-tool

redis

version: '2'
services:
  redis1:
    image: registry.cn-shenzhen.aliyuncs.com/cp_m/redis:3.0.7
    ports:
      - "7001:7001"
    volumes:
      - ./redis7001.conf:/usr/local/conf/redis.conf
    network_mode: "host"
  redis2:
    image: registry.cn-shenzhen.aliyuncs.com/cp_m/redis:3.0.7
    ports:
      - "7002:7002"
    volumes:
      - ./redis7002.conf:/usr/local/conf/redis.conf
    network_mode: "host"
  redis3:
    image: registry.cn-shenzhen.aliyuncs.com/cp_m/redis:3.0.7
    ports:
      - "7003:7003"
    volumes:
      - ./redis7003.conf:/usr/local/conf/redis.conf
    network_mode: "host"
  redis4:
    image: registry.cn-shenzhen.aliyuncs.com/cp_m/redis:3.0.7
    ports:
      - "7004:7004"
    volumes:
      - ./redis7004.conf:/usr/local/conf/redis.conf
    network_mode: "host"
  redis5:
    image: registry.cn-shenzhen.aliyuncs.com/cp_m/redis:3.0.7
    ports:
      - "7005:7005"
    volumes:
      - ./redis7005.conf:/usr/local/conf/redis.conf
    network_mode: "host"
  redis6:
    image: registry.cn-shenzhen.aliyuncs.com/cp_m/redis:3.0.7
    ports:
      - "7000:7000"
    volumes:
      - ./redis7000.conf:/usr/local/conf/redis.conf
    network_mode: "host"

redis.conf

daemonize no
pidfile /var/run/redis.pid
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 16
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

redis-trib

version: '2'
services:
  redistrib:
    image: treg.yun.wps.cn/kingsoft/redis-trib:0.1.3
    environment:
      - "NODES=127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7000"
    network_mode: "host"

redis-migrate-tool

src/redis-migrate-tool -c rmt.conf

src/redis-migrate-tool -c rmt.conf -C redis_check

[source]
type: redis cluster
servers:
 - 127.0.0.1:7003

[target]
type: redis cluster
servers:
 - 127.0.0.1:8002

[common]
listen: 0.0.0.0:8888

OR

docker run --net=host --rm -v /opt/redis-cluster/redis-migrate-tool/rmt.conf:/rmt.conf alessandrob/redis-migrate-tool  /app/src/redis-migrate-tool -c rmt.conf

docker run --net=host --rm -v /opt/redis-cluster/redis-migrate-tool/rmt.conf:/rmt.conf alessandrob/redis-migrate-tool  /app/src/redis-migrate-tool -c rmt.conf -C redis_check

docker run --net=host --rm -v ./rmt.conf:/migrate/rmt.conf alessandrob/redis-migrate-tool 

推荐阅读