1)redis跨实例迁移——源实例db11迁移至目标实例db30

root@fe2e836e4470:/data# redis-cli -a pwd1 -n 11 keys \* |while read key
> do
> echo "Copying $key"
> redis-cli -a pwd1 -n 11 --raw dump $key |head -c -1 \
> |redis-cli -h <dst_ip> -p 6379 -a pwd2 -n 30 -x restore $key 0
> done ## 写成一行,如下:
root@fe2e836e4470:/data# redis-cli -a pwd1 -n 11 keys \* |while read key; do echo "Copying $key"; redis-cli -a pwd1 -n 11 --raw dump $key |head -c -1 |redis-cli -h <dst_ip> -p 6379 -a pwd2 -n 30 -x restore $key 0; done

2)redis上云——迁移至阿里云

参考文档

a. 点击参考文档中的 redis-shake ,下载 redis-shake.tar.gz 至本地

b. 将下载好的 redis-shake.tar.gz 上传至 redis所在的ECS,并拷贝至redis容器中

docker cp /tmp/redis-shake.tar.gz docker_redis_1:/data/

c. 解压redis-shake.tar.gz

leyao-slb02 docker # docker-compose exec redis bash
root@fe2e836e4470:/data# tar -xvf redis-shake.tar.gz
root@fe2e836e4470:/data# ls -ahl
drwxr-xr-x 3 redis root 4.0K Jun 21 07:37 .
drwxr-xr-x 1 root root 4.0K Jun 10 07:45 ..
-rw-r--r-- 1 redis users 2.4K Jun 13 15:48 ChangeLog
-rw-r--r-- 1 redis root 8.6K Jun 21 06:44 redis-shake.conf
-rwxr-xr-x 1 redis users 11M Jun 13 15:48 redis-shake.linux64
-rw-r--r-- 1 redis root 3.7M Jun 21 06:01 redis-shake.tar.gz

d. 修改redis-shake配置文件

leyao-slb02 docker # docker-compose exec redis bash
root@fe2e836e4470:/data# vim redis-shake.conf ...
source.address = localhost:6379
source.password_raw = localRedisPwd
target.address = r-uf65427cede42c14.redis.rds.aliyuncs.com:6379
target.password_raw = yourALIredisPwd
...
# 其余参数保持默认

e. 使用如下命令进行迁移

leyao-slb02 docker # docker-compose exec redis bash
root@fe2e836e4470:/data# ./redis-shake.linux64 -type=sync -conf=redis-shake.conf

f. 查看同步日志确认同步状态,当出现sync rdb done时,全量同步已经完成,同步进入增量阶段。

root@fe2e836e4470:/data# ./redis-shake.linux64 -type=sync -conf=redis-shake.conf
2019/06/27 06:53:56 [WARN]
______________________________
\ \ _ ______ |
\ \ / \___-=O'/|O'/__|
\ redis-shake, here we go !! \_______\ / | / )
/ / '/-==__ _/__|/__=-| -GM
/ / * \ | |
/ / (o)
------------------------------
if you have any problem, please visit https://github.com/alibaba/RedisShake/wiki/FAQ 2019/06/27 06:53:56 [INFO] redis-shake configuration: {"Id":"redis-shake","LogFile":"","LogLevel":"info","SystemProfile":9310,"HttpProfile":9320,"NCpu":0,"Parallel":32,"SourceType":"standalone","SourceAddress":"localhost:6379","SourcePasswordRaw":"bckBuqb5hDhCQfSr9eTVEYufn7gBxJ5k","SourcePasswordEncoding":"","SourceVersion":0,"SourceAuthType":"auth","SourceParallel":1,"SourceTLSEnable":false,"TargetAddress":"r-uf65427cede42c14.redis.rds.aliyuncs.com:6379","TargetPasswordRaw":"Karl@612500","TargetPasswordEncoding":"","TargetVersion":0,"TargetDBString":"-1","TargetAuthType":"auth","TargetType":"standalone","TargetTLSEnable":false,"RdbInput":["local"],"RdbOutput":"local_dump","RdbParallel":1,"RdbSpecialCloud":"","FakeTime":"","Rewrite":true,"FilterDB":"","FilterKey":[],"FilterSlot":[],"BigKeyThreshold":524288000,"Psync":false,"Metric":true,"MetricPrintLog":false,"HeartbeatUrl":"","HeartbeatInterval":3,"HeartbeatExternal":"test external","HeartbeatNetworkInterface":"","SenderSize":104857600,"SenderCount":5000,"SenderDelayChannelSize":65535,"KeepAlive":0,"PidPath":"","ScanKeyNumber":50,"ScanSpecialCloud":"","ScanKeyFile":"","Qps":200000,"ReplaceHashTag":false,"ExtraInfo":false,"SockFileName":"","SockFileSize":0,"SourceAddressList":["localhost:6379"],"TargetAddressList":["r-uf65427cede42c14.redis.rds.aliyuncs.com:6379"],"HeartbeatIp":"127.0.0.1","ShiftTime":0,"TargetRedisVersion":"4.0.11","TargetReplace":true,"TargetDB":-1,"Version":"improve-1.6.7,678f43481a4826764ed71fedd744a7ee23736536,go1.10.3,2019-06-13_23:48:39"}
2019/06/27 06:53:56 [INFO] routine[0] starts syncing data from localhost:6379 to [r-uf65427cede42c14.redis.rds.aliyuncs.com:6379] with http[9321]
2019/06/27 06:53:57 [INFO] dbSyncer[0] rdb file size = 3429472
2019/06/27 06:53:57 [INFO] Aux information key:redis-ver value:5.0.5
2019/06/27 06:53:57 [INFO] Aux information key:redis-bits value:64
2019/06/27 06:53:57 [INFO] Aux information key:ctime value:1561618436
2019/06/27 06:53:57 [INFO] Aux information key:used-mem value:27379792
2019/06/27 06:53:57 [INFO] Aux information key:repl-stream-db value:0
2019/06/27 06:53:57 [INFO] Aux information key:repl-id value:6641200d52e448927a79ce3e0a3cec641302da7f
2019/06/27 06:53:57 [INFO] Aux information key:repl-offset value:0
2019/06/27 06:53:57 [INFO] Aux information key:aof-preamble value:0
2019/06/27 06:53:57 [INFO] db_size:1 expire_size:1
2019/06/27 06:53:57 [INFO] db_size:3 expire_size:1
2019/06/27 06:53:57 [INFO] db_size:9 expire_size:9
2019/06/27 06:53:57 [INFO] db_size:7 expire_size:4
2019/06/27 06:53:57 [INFO] db_size:6 expire_size:0
2019/06/27 06:53:57 [INFO] db_size:6 expire_size:0
2019/06/27 06:53:57 [INFO] Aux information key:lua value:-- Pop the first job off of the queue...
local job = redis.call('lpop', KEYS[1])
local reserved = false if(job ~= false) then
-- Increment the attempt count and place job on the reserved queue...
reserved = cjson.decode(job)
reserved['attempts'] = reserved['attempts'] + 1
reserved = cjson.encode(reserved)
redis.call('zadd', KEYS[2], ARGV[1], reserved)
end return {job, reserved}
2019/06/27 06:53:57 [INFO] Aux information key:lua value:-- Get all of the jobs with an expired "score"...
local val = redis.call('zrangebyscore', KEYS[1], '-inf', ARGV[1]) -- If we have values in the array, we will remove them from the first queue
-- and add them onto the destination queue in chunks of 100, which moves
-- all of the appropriate jobs onto the destination queue very safely.
if(next(val) ~= nil) then
redis.call('zremrangebyrank', KEYS[1], 0, #val - 1) for i = 1, #val, 100 do
redis.call('rpush', KEYS[2], unpack(val, i, math.min(i+99, #val)))
end
end return val
2019/06/27 06:53:57 [INFO] Aux information key:lua value:return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])
2019/06/27 06:53:57 [INFO] dbSyncer[0] total=3429472 - 3429472 [100%] entry=35
2019/06/27 06:53:57 [INFO] dbSyncer[0] sync rdb done
2019/06/27 06:53:57 [WARN] dbSyncer[0] GetFakeSlaveOffset not enable when psync == false
2019/06/27 06:53:57 [INFO] dbSyncer[0] Event:IncrSyncStart Id:redis-shake
2019/06/27 06:53:58 [INFO] dbSyncer[0] sync: +forwardCommands=0 +filterCommands=0 +writeBytes=0
2019/06/27 06:53:59 [INFO] dbSyncer[0] sync: +forwardCommands=7 +filterCommands=0 +writeBytes=34
2019/06/27 06:54:00 [INFO] dbSyncer[0] sync: +forwardCommands=6 +filterCommands=0 +writeBytes=27

g. 登录阿里云Redis查看数据同步情况

最新文章

  1. Linux下安装Git
  2. [UCSD白板题] Maximize the Value of an Arithmetic Expression
  3. Mysql对用户操作加审计功能——高级版
  4. Struts2复习笔记
  5. Java Hour 42 fastjson
  6. SRM 393(1-250pt)
  7. java中关于SSL/TSL的介绍和如何实现SSL Socket双向认证
  8. cygwin 运行窗口程序
  9. 关于在git添加远程地址的过程中遇到的问题
  10. ef core自动映射
  11. worknote
  12. Docker:企业级私有仓库harbor[十六]
  13. 接口测试工具-Jmeter使用笔记(八:模拟OAuth2.0协议简化模式的请求)
  14. ArrayList的扩容机制
  15. LeetCode(78):子集
  16. reorder-list 单链表
  17. 在HTML中导入外部的css
  18. windows如何查看某个端口被谁占用
  19. Kafka生产者APi
  20. IIS中利用ARR实现反向代理

热门文章

  1. SQL Server截取字符串(经纬度)
  2. noip模拟测试31
  3. 小白学vue第四天,从入门到放弃(vue指令的使用加高阶函数)
  4. Java流程控制01——用户交互Scanner
  5. Git点赞82K!字节跳动保姆级Android学习指南,干货满满
  6. MySQL:获取元数据
  7. git的实用命令(撤回,合并)
  8. 软件或jar包版本的小知识---Beta版、Final版、Free版等
  9. JAVA 调用第三方短信平台接口发送短信
  10. Elasticsearch IK分词器