侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

redis数据同步工具redis-shake之两服务器之间数据实时同步案例

Redis  /  管理员 发布于 2年前   2579

redis-shake是阿里开源的用于redis数据同步的工具,我这里主要用于两台redis服务器之间有些key数据要同步一下,所以在测试环境测试一下,写个教程以防下次使用的时候方便


安装redis这点就不用说了

介绍一下我的环境

centos7两台,redis一台4.0,一台5.0


安装redis-shake

下载列表:

https://github.com/alibaba/RedisShake

我这里下载的版本是release-v2.1.1-20210903

https://github.com/alibaba/RedisShake/releases/download/release-v2.1.1-20210903/release-v2.1.1-20210903.tar.gz

下载下来放入被同步的服务器上

我这里是root目录创建redis-shake文件夹 放进这里面,然后解压

[root@hyperf redis-shake]# tar -zxvf release-v2.1.1-20210903.tar.gz 
release-v2.1.1-20210903/
release-v2.1.1-20210903/redis-shake.linux
release-v2.1.1-20210903/redis-shake.conf
release-v2.1.1-20210903/redis-shake.windows
release-v2.1.1-20210903/redis-shake.darwin
[root@hyperf redis-shake]# ll
总用量 58236
-rw-r--r-- 1  502 games    12589 8月  24 2022 redis-shake.conf
-rwxr-xr-x 1  502 games 13176492 9月   3 2021 redis-shake.darwin
-rwxr-xr-x 1  502 games 13235485 9月   3 2021 redis-shake.linux
-rwxr-xr-x 1  502 games 13356032 9月   3 2021 redis-shake.windows
-rw-r--r-- 1 root root  19842840 8月  24 12:49 release-v2.1.1-20210903.tar.gz


配置文件修改,记得把原来的redis-shake.conf备份一下加个.bak后缀

如下修改:

[root@hyperf redis-shake]# cat redis-shake.conf
conf.version = 1
id = redis-shake
log.file = /root/redis-shake/redis-shake.log
log.level = info
pid_path =
system_profile = 9310
http_profile = 9320
parallel = 32
source.type = standalone
source.address = 172.18.1.24:63790
source.password_raw = 123456
source.auth_type = auth
source.tls_enable = false
source.rdb.input =
source.rdb.parallel = 0
source.rdb.special_cloud =
target.type = standalone
target.address = 127.0.0.1:6379
target.password_raw =
target.auth_type = auth
target.db = 0
key_exists = rewrite
filter.db.whitelist = 0
[root@hyperf redis-shake]# 

ps:

我的源redis服务器是172.18.1.24,端口:63790 密码:123456

同步至服务器192.168.1.98 ,端口:6379  密码:无

日志文件记录:/root/redis-shake/redis-shake.log


启动redis-shake服务

[root@hyperf redis-shake]# ./redis-shake.linux -conf=redis-shake.conf -type=sync &
[2] 19824

ps:

这样就启动了,pid:19824,如果修改配置或者要重启服务可以使用kill命令 比如:

kill -9 19824


启动完了,看一下日志文件,我这就截一部分,看看都同步完了

[root@hyperf redis-shake]# ll
总用量 58500
-rw-r--r-- 1  502 games      537 8月  24 13:58 redis-shake.conf
-rw-r--r-- 1 root root     12544 8月  24 13:52 redis-shake.conf.bak
-rwxr-xr-x 1  502 games 13176492 9月   3 2021 redis-shake.darwin
-rwxr-xr-x 1  502 games 13235485 9月   3 2021 redis-shake.linux
-rw-r--r-- 1 root root    136400 8月  24 14:15 redis-shake.log
-rw------- 1 root root         6 8月  24 13:55 redis-shake.pid
-rwxr-xr-x 1  502 games 13356032 9月   3 2021 redis-shake.windows
-rw-r--r-- 1 root root  19842840 8月  24 12:49 release-v2.1.1-20210903.tar.gz
[root@hyperf redis-shake]# cat redis-shake.log
2022/08/24 13:55:40 [WARN] source.auth_type[auth] != auth
2022/08/24 13:55:40 [WARN] target.auth_type[auth] != auth
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] source rdb[172.18.1.24:63790] checksum[yes]
2022/08/24 13:55:40 [WARN] 
______________________________
\                             \           _         ______ |
 \                             \        /   \___-=O'/|O'/__|
  \   RedisShake, here we go !! \_______\          / | /    )
  /                             /        '/-==__ _/__|/__=-|  -GM
 /        Alibaba Cloud        /         *             \ | |
/                             /                        (o)
------------------------------
if you have any problem, please visit https://github.com/alibaba/RedisShake/wiki/FAQ
2022/08/24 13:55:40 [INFO] redis-shake configuration: {"ConfVersion":1,"Id":"redis-shake","LogFile":"/root/redis-shake/redis-shake.log","LogLevel":"info","SystemProfile":9310,"HttpProfile":9320,"Parallel":32,"SourceType":"standalone","SourceAddress":"172.18.1.24:63790","SourcePasswordRaw":"***","SourcePasswordEncoding":"***","SourceAuthType":"auth","SourceTLSEnable":false,"SourceRdbInput":[],"SourceRdbParallel":1,"SourceRdbSpecialCloud":"","TargetAddress":"127.0.0.1:6379","TargetPasswordRaw":"***","TargetPasswordEncoding":"***","TargetDBString":"0","TargetDBMapString":"","TargetAuthType":"auth","TargetType":"standalone","TargetTLSEnable":false,"TargetRdbOutput":"","TargetVersion":"5.0.9","FakeTime":"","KeyExists":"rewrite","FilterDBWhitelist":["0"],"FilterDBBlacklist":null,"FilterKeyWhitelist":null,"FilterKeyBlacklist":null,"FilterSlot":null,"FilterLua":false,"BigKeyThreshold":52428800,"Metric":false,"MetricPrintLog":false,"SenderSize":65535,"SenderCount":1024,"SenderDelayChannelSize":32,"KeepAlive":0,"PidPath":"","ScanKeyNumber":0,"ScanSpecialCloud":"","ScanKeyFile":"","Qps":500000,"ResumeFromBreakPoint":false,"Psync":true,"NCpu":0,"HeartbeatUrl":"","HeartbeatInterval":10,"HeartbeatExternal":"","HeartbeatNetworkInterface":"","ReplaceHashTag":false,"ExtraInfo":false,"SockFileName":"","SockFileSize":0,"FilterKey":null,"FilterDB":"","Rewrite":false,"SourceAddressList":["172.18.1.24:63790"],"TargetAddressList":["127.0.0.1:6379"],"SourceVersion":"4.0.6","HeartbeatIp":"127.0.0.1","ShiftTime":0,"TargetReplace":true,"TargetDB":0,"Version":"develop,cc226f841e2e244c48246ebfcfd5a50396b59710,go1.15.7,2021-09-03_10:06:55","Type":"sync","TargetDBMap":null}
2022/08/24 13:55:40 [INFO] DbSyncer[0] starts syncing data from 172.18.1.24:63790 to [127.0.0.1:6379] with http[9321], enableResumeFromBreakPoint[false], slot boundary[-1, -1]
2022/08/24 13:55:40 [INFO] DbSyncer[0] psync connect '172.18.1.24:63790' with auth type[auth] OK!
2022/08/24 13:55:40 [INFO] DbSyncer[0] psync send listening port[9320] OK!
2022/08/24 13:55:40 [INFO] DbSyncer[0] try to send 'psync' command: run-id[?], offset[-1]
2022/08/24 13:55:40 [INFO] Event:FullSyncStartId:redis-shake
2022/08/24 13:55:40 [INFO] DbSyncer[0] psync runid = a347eaedbfa83634774b5584ed0efe9d152c6d0f, offset = 0, fullsync
2022/08/24 13:55:40 [INFO] DbSyncer[0] rdb file size = 104942
2022/08/24 13:55:40 [INFO] Aux information key:redis-ver value:4.0.6
2022/08/24 13:55:40 [INFO] Aux information key:redis-bits value:64
2022/08/24 13:55:40 [INFO] Aux information key:ctime value:1661320637
2022/08/24 13:55:40 [INFO] Aux information key:used-mem value:2231719
2022/08/24 13:55:40 [INFO] Aux information key:repl-stream-db value:0
2022/08/24 13:55:40 [INFO] Aux information key:repl-id value:a347eaedbfa83634774b5584ed0efe9d152c6d0f
2022/08/24 13:55:40 [INFO] Aux information key:repl-offset value:0
2022/08/24 13:55:40 [INFO] Aux information key:aof-preamble value:0
2022/08/24 13:55:40 [INFO] db_size:20 expire_size:14
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] db_size:2 expire_size:0
2022/08/24 13:55:40 [INFO] Aux information key:lua value:return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] input password is empty, skip auth address[127.0.0.1:6379] with type[auth].
2022/08/24 13:55:40 [INFO] warning, rewrite key: name
2022/08/24 13:55:40 [INFO] DbSyncer[0] total = 102.48KB -     102.48KB [100%]  entry=20            filter=3           
2022/08/24 13:55:40 [INFO] DbSyncer[0] sync rdb done
...


上面就同步过来了,如果日志没报错的话就ok了;

用redis客户端软件打开检查测试一下

然后在源redis上修改一下数据,在同步redis服务器上看看,同步过来就ok了

测试我就不截图了,比较简单,有兴趣有需要的可以自行测试一下


  • 上一条:
    在phpunit中mock支付宝回调测试用例样式代码分享
    下一条:
    如何简单粗暴地屏蔽百度联盟广告及启用cname的反屏蔽模式代码
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Redis中能实现的功能、常见应用介绍(0个评论)
    • 2024年Redis面试题之一(0个评论)
    • 在redis缓存常见出错及解决方案(0个评论)
    • 在redis中三种特殊数据类型:地理位置、基数(cardinality)估计、位图(Bitmap)使用场景介绍浅析(2个评论)
    • Redis 删除 key用 del 和 unlink 有啥区别?(1个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2017-12
    • 2020-03
    • 2020-05
    • 2021-04
    • 2022-03
    • 2022-05
    • 2022-08
    • 2023-02
    • 2023-04
    • 2023-07
    • 2024-01
    • 2024-02
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客