本文共 4852 字,大约阅读时间需要 16 分钟。
redis-shake是阿里云Redis&MongoDB团队开源的用于redis数据同步的工具。
redis-shake是我们基于基础上进行改进的一款产品。它支持解析、恢复、备份、同步四个功能。以下主要介绍同步sync。
redis-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
。
如何校验同步的正确性?可以采用我们开源的,具体原理可以参考。
启动示例(以sync
举例):
vinllen@ ~/redis-shake/bin$ ./redis-shake -type=sync -conf=../conf/redis-shake.conf
conf路径下的redis-shake.conf存放的是配置文件,其内容及部分中文注释如下 # this is the configuration of redis-shake.# idid = redis-shake# log file,日志文件,不配置将打印到stdoutlog_file =# pprof portsystem_profile = 9310# restful port,查看metric端口http_profile = 9320# runtime.GOMAXPROCS, 0 means use cpu core number: runtime.NumCPU()ncpu = 0# parallel routines number used in RDB file syncing.parallel = 4# input RDB file. read from stdin, default is stdin ('/dev/stdin').# used in `decode` and `restore`.# 如果是decode或者restore,这个参数表示读取的rdb文件input_rdb = local_dump# output RDB file. default is stdout ('/dev/stdout').# used in `decode` and `dump`.# 如果是decode或者dump,这个参数表示输出的rdboutput_rdb = local_dump# source redis configuration.# used in `dump` and `sync`.# ip:port# 源redis地址source.address = 127.0.0.1:20441# password.source.password_raw = kLNIl691OZctWST# auth type, don't modify itsource.auth_type = auth# version number, default is 6 (6 for Redis Version <= 3.0.7, 7 for >=3.2.0)source.version = 6# target redis configuration. used in `restore` and `sync`.# used in `restore` and `sync`.# ip:port# 目的redis地址target.address = 10.101.72.137:20551# password.target.password_raw = kLNIl691OZctWST# auth type, don't modify ittarget.auth_type = auth# version number, default is 6 (6 for Redis Version <= 3.0.7, 7 for >=3.2.0)target.version = 6# all the data will come into this db. < 0 means disable.# used in `restore` and `sync`.target.db = -1# use for expire key, set the time gap when source and target timestamp are not the same.# 用于处理过期的键值,当迁移两端不一致的时候,目的端需要加上这个值fake_time =# force rewrite when destination restore has the key# used in `restore` and `sync`.# 当源目的有重复key,是否进行覆写rewrite = true# filter db or key or slot# choose these db, e.g., 5, only choose db5. defalut is all.# used in `restore` and `sync`.# 支持过滤db,只让指定的db通过filter.db =# filter key with prefix string. multiple keys are separated by ';'.# e.g., a;b;c# default is all.# used in `restore` and `sync`.# 支持过滤key,只让指定的key通过,分号分隔filter.key =# filter given slot, multiple slots are separated by ';'.# e.g., 1;2;3# used in `sync`.# 指定过滤slot,只让指定的slot通过filter.slot =# big key threshold, the default is 500 * 1024 * 1024. The field of the big key will be split in processing.# 我们对大key有特殊的处理,此处需要指定大key的阈值big_key_threshold = 524288000# use psync command.# used in `sync`.# 默认使用sync命令,启用将会使用psync命令psync = false# enable metric# used in `sync`.# 是否启用metricmetric = true# print in log# 是否将metric打印到log中metric.print_log = true# heartbeat# send heartbeat to this url# used in `sync`.# 心跳的url地址,redis-shake将会发送到这个地址heartbeat.url = http://127.0.0.1:8000# interval by seconds# 心跳保活周期heartbeat.interval = 3# external info which will be included in heartbeat data.# 在心跳报文中添加额外的信息heartbeat.external = test external# local network card to get ip address, e.g., "lo", "eth0", "en0"# 获取ip的网卡heartbeat.network_interface =# sender information.# sender flush buffer size of byte.# used in `sync`.# 发送缓存的字节长度,超过这个阈值将会强行刷缓存发送sender.size = 104857600# sender flush buffer size of oplog number.# used in `sync`.# 发送缓存的报文个数,超过这个阈值将会强行刷缓存发送sender.count = 5000# delay channel size. once one oplog is sent to target redis, the oplog id and timestamp will also stored in this delay queue. this timestamp will be used to calculate the time delay when receiving ack from target redis.# used in `sync`.# 用于metric统计时延的队列sender.delay_channel_size = 65535# ----------------splitter----------------# below variables are useless for current opensource version so don't set.# replace hash tag.# used in `sync`.replace_hash_tag = false# used in `restore` and `dump`.extra = false
:
转载地址:http://swmol.baihongyu.com/