简介: redis-shake是阿里云Redis&MongoDB团队开源的用于redis数据同步的工具。
下载地址:这里。
基本功能
redis-shake是我们基于redis-port基础上进行改进的一款产品。它支持解析、恢复、备份、同步四个功能。以下主要介绍同步sync。
恢复restore:将RDB文件恢复到目的redis数据库。
备份dump:将源redis的全量数据通过RDB文件备份起来。
解析decode:对RDB文件进行读取,并以json格式解析存储。
同步sync:支持源redis和目的redis的数据同步,支持全量和增量数据的迁移,支持从云下到阿里云云上的同步,也支持云下到云下不同环境的同步,支持单节点、主从版、集群版之间的互相同步。需要注意的是,如果源端是集群版,可以启动一个RedisShake,从不同的db结点进行拉取,同时源端不能开启move slot功能;对于目的端,如果是集群版,写入可以是1个或者多个db结点。
同步rump:支持源redis和目的redis的数据同步,仅支持全量的迁移。采用scan和restore命令进行迁移,支持不同云厂商不同redis版本的迁移。
基本原理
edis-shake的基本原理就是模拟一个从节点加入源redis集群,首先进行全量拉取并回放,然后进行增量的拉取(通过psync命令)。如下图所示:
如果源端是集群模式,只需要启动一个redis-shake进行拉取,同时不能开启源端的move slot操作。如果目的端是集群模式,可以写入到一个结点,然后再进行slot的迁移,当然也可以多对多写入。
目前,redis-shake到目的端采用单链路实现,对于正常情况下,这不会成为瓶颈,但对于极端情况,qps比较大的时候,此部分性能可能成为瓶颈,后续我们可能会计划对此进行优化。另外,redis-shake到目的端的数据同步采用异步的方式,读写分离在2个线程操作,降低因为网络时延带来的同步性能下降。
高效性
全量同步阶段并发执行,增量同步阶段异步执行,能够达到毫秒级别延迟(取决于网络延迟)。同时,我们还对大key同步进行分批拉取,优化同步性能。
监控
用户可以通过我们提供的restful拉取metric来对redis-shake进行实时监控:
curl 127.0.0.1:9320/metric
校验
如何校验同步的正确性?可以采用我们开源的redis-full-check,具体原理可以参考这篇文章。
下载(2.0.3版本为例)
wget https://github.com/alibaba/RedisShake/releases/download/release-v2.0.3-20200724/redis-shake-v2.0.3.tar.gz
解压
tar -zxvf redis-shake-v2.0.3.tar.gz
配置文件修改
# source redis configuration.
# used in `dump`, `sync` and `rump`.
# source redis type, e.g. "standalone" (default), "sentinel" or "cluster".
# 1. "standalone": standalone db mode.
# 2. "sentinel": the redis address is read from sentinel.
# 3. "cluster": the source redis has several db.
# 4. "proxy": the proxy address, currently, only used in "rump" mode.
# 源端redis的类型,支持standalone,sentinel,cluster和proxy四种模式,注意:目前proxy只用于rump模式。
source.type = standalone #【单机模式下直接使用standalone 即可】
# 源redis地址
source.address = 127.0.0.1:6379 #【本例从本机同步到远程的redis上】
# password.
source.password_raw = 123456 #【如果没有设置密码,可以不用填】
# auth type, don't modify it
source.auth_type = auth
# target redis configuration. used in `restore`, `sync` and `rump`.
# the type of target redis can be "standalone", "proxy" or "cluster".
# 1. "standalone": standalone db mode.
# 2. "sentinel": the redis address is read from sentinel.
# 3. "cluster": open source cluster (not supported currently).
# 4. "proxy": proxy layer ahead redis. Data will be inserted in a round-robin way if more than 1 proxy given.
# 目的redis的类型,支持standalone,sentinel,cluster和proxy四种模式。
target.type = standalone #【单机模式下直接使用standalone 即可】
# 目的redis地址
target.address = 目的地IP:6379
# password.
target.password_raw = 123456 #【如果没有设置密码,可以不用填】
# auth type, don't modify it
target.auth_type = auth
# version number, default is 6 (6 for Redis Version <= 3.0.7, 7 for >=3.2.0)
target.version =
# all the data will come into this db. < 0 means disable.
# used in `restore` and `sync`.
target.db = -1
# 当源目的有重复key,是否进行覆写
rewrite = true
启动命令
./redis-shake.linux -conf=redis-shake.conf -type=sync
打印
同步成功