当前位置: 代码网 > it编程>数据库>Redis > Redis中redis-shake实现数据迁移同步

Redis中redis-shake实现数据迁移同步

2025年11月18日 Redis 我要评论
0 项目介绍在当今快速发展的业务环境中,企业经常面临跨区域数据迁移和同步的挑战,以确保业务连续性和数据一致性。特别是在使用redis作为关键数据存储解决方案时,如何高效、安全地进行数据迁移和同步成为了

0 项目介绍

在当今快速发展的业务环境中,企业经常面临跨区域数据迁移和同步的挑战,以确保业务连续性和数据一致性。特别是在使用redis作为关键数据存储解决方案时,如何高效、安全地进行数据迁移和同步成为了一个重要的问题。

1 初始化 redis-shake 服务器

# ===================== 内核参数 ============================
连接数
cat >> /etc/security/limits.conf << eof
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535 
eof

cat >>  /etc/sysctl.conf  << eof
vm.overcommit_memory = 1
net.ipv4.tcp_max_tw_buckets = 150000
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 9000 65500
eof

# ====================== 基础配置 ===================================
setenforce 0 && sed -i 's/^selinux=enforcing/selinux=disabled/g' /etc/selinux/config && getenforce

systemctl disable firewalld && systemctl stop firewalld

useradd -s /sbin/nologin redis

2 安装 redis-shake

# 下载 redis-shake
wget https://github.com/tair-opensource/redisshake/releases/download/v4.2.0/redis-shake-linux-amd64.tar.gz

# 解压 redis-shake
tar xf redis-shake-linux-amd64.tar.gz

# 创建目录
mkdir -pv /usr/local/redis-shake/config

3 配置 redis-shake

vim /usr/local/redis-shake/config/shake.toml

主要调整参数:

  • sync_reader.cluster:设置同步模式是否为 cluster 模式
  • sync_reader.address:源端 redis cluster ip (任意ip)
  • sync_reader.password: 源端 redist cluster 访问密码
  • sync_reader.sync_rdb: 同步方式,rdb 为 全量同步
  • sync_reader.aof: 同步方式, aof 为增量同步 (即使cluster没有开启aof,也可以使用)
  • redis_writer.cluster: 设置目标端同步模式,此处应与源端模式一样
  • redis_writer.address :设置目标端同步 ip
  • redis_writer.password: 设置目标端同步密码
[sync_reader]
cluster = true            # set to true if source is a redis cluster
address = 192.168.1.1:6379" # when cluster is true, set address to one of the cluster node
username = ""              # keep empty if not using acl
password = "xxxxx"              # keep empty if no authentication is required
tls = false                #
sync_rdb = true            # set to false if you don't want to sync rdb
sync_aof = true          # set to false if you don't want to sync aof
prefer_replica = false     # set to true if you want to sync from replica node
try_diskless = false       # set to true if you want to sync by socket and source repl-diskless-sync=yes

#[scan_reader]
#cluster = false            # set to true if source is a redis cluster
#address = "127.0.0.1:6379" # when cluster is true, set address to one of the cluster node
#username = ""              # keep empty if not using acl
#password = ""              # keep empty if no authentication is required
#tls = false
#dbs = []                   # set you want to scan dbs such as [1,5,7], if you don't want to scan all
#scan = true                # set to false if you don't want to scan keys
#ksn = false                # set to true to enabled redis keyspace notifications (ksn) subscription
#count = 1                  # number of keys to scan per iteration

# [rdb_reader]
# filepath = "/tmp/dump.rdb"

# [aof_reader]
# filepath = "/tmp/.aof"
# timestamp = 0            # subsecond

[redis_writer]
cluster = true            # set to true if target is a redis cluster
sentinel = false           # set to true if target is a redis sentinel
master = ""                # set to master name if target is a redis sentinel
address = "192.168.1.2:6379" # when cluster is true, set address to one of the cluster node
username = ""              # keep empty if not using acl
password = "xxxxx"              # keep empty if no authentication is required
tls = false
off_reply = false          # turn off the server reply

[filter]
# allow keys with specific prefixes or suffixes
# examples:
#   allow_key_prefix = ["user:", "product:"]
#   allow_key_suffix = [":active", ":valid"]
# leave empty to allow all keys
allow_key_prefix = []
allow_key_suffix = []

# block keys with specific prefixes or suffixes
# examples:
#   block_key_prefix = ["temp:", "cache:"]
#   block_key_suffix = [":tmp", ":old"]
# leave empty to block nothing
block_key_prefix = []
block_key_suffix = []

# specify allowed and blocked database numbers (e.g., allow_db = [0, 1, 2], block_db = [3, 4, 5])
# leave empty to allow all databases
allow_db = []
block_command = []

# allow or block specific command groups
# available groups:
#   server, string, cluster, connection, bitmap, list, sorted_set,
#   generic, transactions, scripting, tairhash, tairstring, tairzset,
#   geo, hash, hyperloglog, pubsub, set, sentinel, stream
# examples:
#   allow_command_group = ["string", "hash"]  # only allow string and hash commands
#   block_command_group = ["scripting", "pubsub"]  # block scripting and pubsub commands
# leave empty to allow all command groups
allow_command_group = []
block_command_group = []

# function for custom data processing
# for best practices and examples, visit:
# https://tair-opensource.github.io/redisshake/zh/function/best_practices.html
function = ""

[advanced]
dir = "/usr/local/redis-shake/data"
ncpu = 0        # runtime.gomaxprocs, 0 means use runtime.numcpu() cpu cores
pprof_port = 0  # pprof port, 0 means disable
status_port = 0 # status port, 0 means disable

# log
log_file = "shake.log"
log_level = "info"     # debug, info or warn
log_interval = 5       # in seconds

# redis-shake gets key and value from rdb file, and uses restore command to
# create the key in target redis. redis restore will return a "target key name
# is busy" error when key already exists. you can use this configuration item
# to change the default behavior of restore:
# panic:   redis-shake will stop when meet "target key name is busy" error.
# rewrite: redis-shake will replace the key with new value.
# skip:  redis-shake will skip restore the key when meet "target key name is busy" error.
rdb_restore_command_behavior = "panic" # panic, rewrite or skip

# redis-shake uses pipeline to improve sending performance.
# adjust this value based on the destination redis performance:
# - higher values may improve performance for capable destinations.
# - lower values are recommended for destinations with poor performance.
# 1024 is a good default value for most cases.
pipeline_count_limit = 1024

# this setting corresponds to the 'client-query-buffer-limit' in redis configuration.
# the default value is typically 1gb.
# it's recommended not to modify this value unless absolutely necessary.
target_redis_client_max_querybuf_len = 1073741824  # 1gb in bytes

# this setting corresponds to the 'proto-max-bulk-len' in redis configuration.
# it defines the maximum size of a single string element in the redis protocol.
# the value must be 1mb or greater. default is 512mb.
# it's recommended not to modify this value unless absolutely necessary.
target_redis_proto_max_bulk_len = 512_000_000

# if the source is elasticache, you can set this item. aws elasticache has custom
# psync command, which can be obtained through a ticket.
aws_psync = "" # example: aws_psync = "10.0.0.1:6379@nmfu2sl5osync,10.0.0.1:6379@xhma21xfkssync"

# destination will delete itself entire database before fetching files
# from source during full synchronization.
# this option is similar redis replicas rdb diskless load option:
#   repl-diskless-load on-empty-db
empty_db_before_sync = true

[module]
# the data format for bf.loadchunk is not compatible in different versions. v2.6.3 <=> 20603
target_mbbloom_version = 20603

3 配置 redis-shake service

vim /usr/lib/systemd/system/redis-shake.service
[unit]
description=redis-shake
after=data.mount

[service]
type=simple
execstart=/usr/local/redis-shake/redis-shake  /usr/local/redis-shake/config/shake.toml
execstop=/bin/kill -sigterm $mainpid
privatetmp=true
user=redis
group=redis

[install]
wantedby=multi-user.target

4 启动 & 开机自启

systemctl start redis-shake
systemctl enable redis-shake

到此这篇关于redis中redis-shake实现数据迁移同步的文章就介绍到这了,更多相关redis 数据迁移同步内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com