Aws ElastiCache Redis数据迁移(一)
2023-10-29 本文已影响0人
青水山
1、EC 简介及性能表现
Aws ElastiCache(简称 EC),主要包含两种架构,主从架构和集群架构。
EC在性能上做了部分优化,在R6g 等arm机型上也做了部分优化。



可以看到,部分场景下,GET性能可以达到接近90万的QPS。
2、EC迁移工具
目前EC的迁移工具,主要包括两种:Riot,Redis-shake。
Aws 官方的ElastiCache 控制台、API 或 AWS CLI,本篇不做介绍。
本文,先介绍第一种Riot。
Riot 介绍
- Files (CSV, JSON, XML)
- Data generators (Redis data structures, Faker)
- Relational databases
-
Redis itself (snapshot and live replication)
image.png

3、部署方式
3.1 docker方式
docker run -d --name=riot fieldengineering/riot \
-h source-ip -p source-port -a source-pwd <-c> <--tls> \
replicate \
-h target-ip -p target-port -a target-pwd <-c> <--tls> \
--threads 3 \
--mode live
3.2 二进制方式
#x86_64
wget https://github.com/redis-developer/riot/releases/download/v3.1.5/riot-standalone-3.1.5-linux-x86_64.zip
#riot-standalone-3.1.5-*.zip 包含自己的 Java 运行时并且不需要安装 Java
#其他系统,参考 https://github.com/redis-developer/riot/releases
# 迁移命令
riot -h source-ip -p source-port -a source-pwd <-c> <--tls> \
replicate <--type ds> \
-h target-ip -p target-port -a target-pwd <-c> <--tls> \
--threads 3 \
--mode live
3.3 replicate 数据同步模式参数
TIPS:
source-ip 源端ip(dns)
source-port 源端port
source-pwd 源端密码
-c 集群模式,非集群模式不需要加-c
--tls redis实例启用了数据传输加密时,需要增加此参数
replicate 数据同步模式
--type ds 源端和目的端版本不一致时,对key 按照类型进行同步。cpu负载高
target-ip 目标端ip
target-port 目标端port
target-pwd 目标端密码
--threads 启用多线程
--mode live 启用数据增量同步
4、迁移类型
4.1 离线迁移
通过对文件进行import。该方案不包含在线业务的增量数据。
文件类型主要为CSV, TSV, PSV
4.2 在线全量迁移
对Redis 进行 dump & restoe 操作。该方案不包含在线业务的增量数据。
4.3 在线全量/增量迁移
对Redis 进行 dump & restoe 操作,并且监测在线业务的增量数据情况,进行实时同步。
增量迁移,需要设置源端redis参数 notify-keyspace-events
config set notify-keyspace-events KA
可以通过配置 "notify-keyspace-events" 选项来让 Redis 选择发送哪些事件:
K Keyspace 事件, 以 __keyspace@<db>__ 为前缀发布
E Keyevent 事件, 以 __keyevent@<db>__ 为前缀发布
g 通用命令 (不是针对特定类型的命令) 比如 DEL, EXPIRE, RENAME 等
$ String 命令
l List 命令
s Set 命令
h Hash 命令
z Sorted set 命令
x Expired 事件 (当一个 key 过期的时候生成)
e Evicted 事件 (当一个 key 由于 maxmemory 被回收生成)
A 表示 g$lshzxe 的别名,因此 "AKE" 表示所有事件
notify-keyspace-events 的值由上面的 0 到 N 个字符组成。空字符串表示禁止发送通知,
这是 notify-keyspace-events 的默认值。
迁移时,增加增量迁移参数
--mode live
5、迁移准备
5.1 准备EC2
在待迁移实例的同一个vpc中,准备一台EC2,4c8g+
5.2 修改参数
如果需要数据实时同步,需要提前修改EC(Redis)的参数。
开启方法:
5.2.1 物理自建实例,可在线动态修改
config set notify-keyspace-events KA
5.2.2 EC实例
Tips:EC实例限制了部分命令,如config,sync,psync等命令,所以需要修改配置文件.
查看当前集群的参数组名称,如default.redis6.x.cluster.on,default前缀表示使用的是系统默认参数组,默认参数组不可以修改

在Aws-ElastiCache 控制台页面左侧, —>配置—> 参数组,点击右上角【创建参数组】

输入一个参数组名称,建议名称包含实例类型(redis),实例版本,实例架构,选择默认参数组对应的版本,及描述信息

重新进入 配置—> 参数组,选择刚才创建的参数组,点击右侧【编辑参数值】

搜索notify,找到notify-keyspace-events参数,值修改为 KA

如果原EC为cluster 架构,还需要修改cluster-enabled值为yes,因为新创建的参数组,cluster-enabled默认为NO

5.3 测试网络
在EC2机器安装redis-cli工具
sudo apt-get install redis-tools
测试源端EC
redis-cli -h cluster1.1o85i0.clustercfg.apse1.cache.amazonaws.com -p 6379 -a xxx
如果开启了传输加密,需要加上--tls 参数
redis-cli -h cluster1.1o85i0.clustercfg.apse1.cache.amazonaws.com -p 6379 -a xxx --tls
测试目标端Redis
redis-cli -h target-ip -p 6379 -a xxx
6、迁移场景
6.1 ElastiCache Cluster To other Redis Cluster
6.1.1全量迁移
docker run -d --name=riot fieldengineering/riot \
-h source-ip -p source-port -a source-pwd -c --tls \
replicate \
-h target-ip -p target-port -a target-pwd -c --tls \
--threads 2 \
TIPS: 未开启传输加密,不需要--tls 参数
6.1.2 全量+增量迁移
docker run -d --name=riot fieldengineering/riot \
-h source-ip -p source-port -a source-pwd -c --tls \
replicate \
-h target-ip -p target-port -a target-pwd -c --tls \
--threads 2 \
--mode live
TIPS: 未开启传输加密,不需要--tls 参数
6.2 ElastiCache Single To other Redis Single
6.2.1全量迁移
docker run -d --name=riot fieldengineering/riot \
-h source-ip -p source-port -a source-pwd --tls \
replicate \
-h target-ip -p target-port -a target-pwd --tls \
--threads 2 \
TIPS: 未开启传输加密,不需要--tls 参数
6.2.2全量+增量迁移
docker run -d --name=riot fieldengineering/riot \
-h source-ip -p source-port -a source-pwd --tls \
replicate \
-h target-ip -p target-port -a target-pwd --tls \
--threads 2 \
--mode live
TIPS: 未开启传输加密,不需要--tls 参数