redis cluster集群升级数据同步
redis cluster集群升级数据同步
背景
项目上的redis-cluster集群版本为5.0.5,现在有爆出漏洞,甲方要求升级到6.2.20的redis
原本以为重新搭建一套就可以了,但是开发说他们有的数据是直接填充到redis里面的,不是从数据库读取自动生成的,没办法只能加上数据同步
用户是生产环境,尽量不停机同步服务同步数据,所以用到阿里的一个工具
下载地址:
wget https://github.com/tair-opensource/RedisShake/releases/download/v4.3.2/redis-shake-v4.3.2-linux-amd64.tar.gz
搭建redis-cluster集群
参考我之前写的一篇文章 https://www.cnblogs.com/liwenchao1995/p/16619556.html
三主三从搭建好后,可以开始进行数据同步了
数据同步
前面我们下载好了redis同步工具
tar zxvf redis-shake-v4.3.2-linux-amd64.tar.gz
# 解压后就2个文件,一个执行文件,一个配置文件
#编辑配置文件
vim shake.toml
//只需要改下源地址和目标地址就可以了
# 数据来源,因为是集群,写任意一个节点就可以了10.212.1.36:16380
[sync_reader]
cluster = true # Set to true if the source is a Redis cluster
address = "10.212.1.36:16380" # For clusters, specify the address of any cluster node; use the master or slave address in master-slave mode
username = "" # Keep empty if ACL is not in use
password = "adKxyeKYbXeMavsW4Vr1c" # Keep empty if no authentication is required
tls = false # Set to true to enable TLS if needed
sync_rdb = true # Set to false if RDB synchronization is not required
sync_aof = true # Set to false if AOF synchronization is not required
prefer_replica = false # Set to true to sync from a replica node
try_diskless = false # Set to true for diskless sync if the source has repl-diskless-sync=yes
#目标集群,往这个集群里同步写数据,10.212.1.35:8001是我新搭的集群,在同三台机器上,端口不同
[redis_writer]
cluster = true # set to true if target is a redis cluster
address = "10.212.1.35:8001" # when cluster is true, set address to one of the cluster node
username = "" # keep empty if not using ACL
password = "adKxyeKYbXeMavsW4Vr1c" # keep empty if no authentication is required
tls = false
off_reply = false # turn off the server reply
# 配置改完后,执行命令
nohup ./redis-shake shake.toml > shake.log 2>&1 &
# 查看同步日志,当出现以下类似信息就同步完成了
INF redisClusterWriter connected to redis cluster successful. addresses=[10.212.1.36:8002 10.212.1.36:8001 10.212.1.37:8001]
tail -f shake.log
# 分别连上两个redis集群,检查key的数量,如果只差几个,不用担心,多数情况下,这种少量差异是 “同步期间源 Key 过期 / 删除” 或 “隐性过滤” 导致的,通过对比缺失 Key 的特征,能快速定位原因。若缺失的是业务无关的 Key(如临时缓存、过期数据),无需处理
服务切换
关闭源redis服务(前5分钟)
关闭同步工具
ps -ef | grep redis-shake # kill掉
切换配置到新redis集群
本文来自博客园,作者:liwenchao1995,转载请注明原文链接:https://www.cnblogs.com/liwenchao1995/p/19161226

浙公网安备 33010602011771号