redis cluster 数据迁移

1,先停止java的后台和.net的后台,停止对redis cluster进行访问

2,然后 cd /usr/local/redis-cluster/7001 每个节点都要做如下操作7001-7006

bin/redis-cli -c -h 10.17.100.222 -p 7001 -a ‘redis!123456’

执行save

然后把 7001-7006目录下的dump.rdb文件备份到redis_backup20200925目录下的7001-7006

cp dump.rdb /root/redis_backup20200925/7001

3,然后把7001-7006的redis节点kill -9 停掉

把7001 -7006的密码取消

然后把7001-7006的redis节点重启

scl enable rh-ruby25 bash

检验并查看ruby版本:

ruby -v

cd /root/tools/redis-4.0.11/src

然后vim redis-trib.rb

把其中的2行的source.r.client.call改为source.r.call

begin
source.r.client.call([“migrate”,target.info[:host],target.info[:port],””,0,@timeout,:keys,keys])
rescue => e
if o[:fix] && e.to_s =~ /BUSYKEY/
xputs “
* Target key exists. Replacing it for FIX.”
source.r.client.call([“migrate”,target.info[:host],target.info[:port],””,0,@timeout,:replace,:keys,
keys])

然后保存这个文件

然后在222上把之前的221上的7007 7008 7009 都添加到集群,如下命令的第一个ip:port是需要添加的新节点 第二个ip:port是之前集群的任意一个节点

[root@localhost src]# /root/tools/redis-4.0.11/src/redis-trib.rb add-node 10.17.100.221:7007 10.17.100.222:7001

Adding node 10.17.100.221:7007 to cluster 10.17.100.222:7001
Performing Cluster Check (using node 10.17.100.222:7001)
S: c6eb5f1bb557b118c4cc391d613b3d63d1f44e30 10.17.100.222:7001
slots: (0 slots) slave
replicates 1b5cbd25391f4ff0e7997e276ad4ad780cb0556a
M: 88fb94a3f6216c3ffb1bfd1db5d194d94422a584 10.17.100.222:7005
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 22324a252ff2be093f59b250181c8c050e7fc180 10.17.100.222:7006
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 166607e8101ed75efd7ef939c32b5339004024d5 10.17.100.222:7003
slots: (0 slots) slave
replicates 22324a252ff2be093f59b250181c8c050e7fc180
M: 1b5cbd25391f4ff0e7997e276ad4ad780cb0556a 10.17.100.222:7004
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: cb8f5bf5a2999d496b41bed6a293a792a6e39dc3 10.17.100.222:7002
slots: (0 slots) slave
replicates 88fb94a3f6216c3ffb1bfd1db5d194d94422a584
[OK] All nodes agree about slots configuration.

Check for open slots…

Check slots coverage…

[OK] All 16384 slots covered.

Send CLUSTER MEET to node 10.17.100.221:7007 to make it join the cluster.

[OK] New node added correctly.

7007 7008 7009添加完后再查看一些当前redis cluster的情况:

[root@localhost src]# /root/tools/redis-4.0.11/src/redis-trib.rb info 10.17.100.222:7001
10.17.100.222:7005 (88fb94a3…) -> 32310 keys | 5462 slots | 1 slaves.

10.17.100.222:7006 (22324a25…) -> 32022 keys | 5461 slots | 1 slaves.

10.17.100.222:7004 (1b5cbd25…) -> 32035 keys | 5461 slots | 1 slaves.

10.17.100.221:7008 (1033b8a2…) -> 0 keys | 0 slots | 0 slaves.

10.17.100.221:7009 (36f4ebfc…) -> 0 keys | 0 slots | 0 slaves.

10.17.100.221:7007 (08bca5f8…) -> 0 keys | 0 slots | 0 slaves.

[OK] 96367 keys in 6 masters.

5.88 keys per slot on average.

6,开始把数据迁移到7007和7008

先看看当前Node的信息

[root@localhost 7001]# bin/redis-cli -c -h 10.17.100.222 -p 7001
10.17.100.222:7001> cluster nodes
88fb94a3f6216c3ffb1bfd1db5d194d94422a584 10.17.100.222:7005@17005 master – 0 1601027558210 10 connected 5461-10922
22324a252ff2be093f59b250181c8c050e7fc180 10.17.100.222:7006@17006 master – 0 1601027562218 11 connected 10923-16383
1b5cbd25391f4ff0e7997e276ad4ad780cb0556a 10.17.100.222:7004@17004 master – 0 1601027558000 7 connected 0-5460
1033b8a2893adcc7fee8464281f95116b9825383 10.17.100.221:7008@17008 master – 0 1601027559000 13 connected
36f4ebfc772287e848e4d9b85b974675c2b61bd4 10.17.100.221:7009@17009 master – 0 1601027561000 0 connected
08bca5f84d3b7cb1c9df84ac8c25536985c30981 10.17.100.221:7007@17007 master – 0 1601027559000 12 connected
166607e8101ed75efd7ef939c32b5339004024d5 10.17.100.222:7003@17003 slave 22324a252ff2be093f59b250181c8c050e7fc180 0 1601027560214 11 connected
cb8f5bf5a2999d496b41bed6a293a792a6e39dc3 10.17.100.222:7002@17002 slave 88fb94a3f6216c3ffb1bfd1db5d194d94422a584 0 1601027561217 10 connected
c6eb5f1bb557b118c4cc391d613b3d63d1f44e30 10.17.100.222:7001@17001 myself,slave 1b5cbd25391f4ff0e7997e276ad4ad780cb0556a 0 1601027558000 1 connected

[root@novacq1 7001]# /root/tools/redis-4.0.11/src/redis-trib.rb reshard 15.32.134.247:7007

Performing Cluster Check (using node 15.32.134.247:7007)
M: 8dbea4fac4dc3fb133fa4e946c44584cf895cd02 15.32.134.247:7007
slots: (0 slots) master
0 additional replica(s)
S: b7c383c0663afd90a2e66b830b648180de8ce882 15.99.72.154:7004
slots: (0 slots) slave
replicates ccd2166eb56df50ece8988f790977f61289b0084
M: 963bb18d24abff0543811b293551efe74a59db45 15.32.134.247:7009
slots: (0 slots) master
0 additional replica(s)
S: c0dd3cddd8b2a5f842c46848830701b7fdc0a27c 15.99.72.162:7005
slots: (0 slots) slave
replicates ff5aa484136e7504d9ae4a8e6d795cf1ed4c3a0c
M: ff5aa484136e7504d9ae4a8e6d795cf1ed4c3a0c 15.99.72.153:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 388bd7613d5eb7334fb2734dd2cb842f01cdae58 15.99.72.162:7006
slots: (0 slots) slave
replicates 9cdb8de1ca0b97694e845d344f1e4327cca48561
M: 5c1d9192e2da819af92d4df8546967be54d1c5b1 15.32.134.247:7008
slots: (0 slots) master
0 additional replica(s)
M: ccd2166eb56df50ece8988f790977f61289b0084 15.99.72.153:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 9cdb8de1ca0b97694e845d344f1e4327cca48561 15.99.72.154:7003
slots:5461-10922 (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.

Check for open slots…

Check slots coverage…

[OK] All 16384 slots covered.

How many slots do you want to move (from 1 to 16384)? 5461
What is the receiving node ID? 8dbea4fac4dc3fb133fa4e946c44584cf895cd02
Please enter all the source node IDs.

Type ‘all’ to use all the nodes as source nodes for the hash slots.

Type ‘done’ once you entered all the source nodes IDs.

Source node #1:ccd2166eb56df50ece8988f790977f61289b0084

Source node #2:done

……

Moving slot 5454 from ccd2166eb56df50ece8988f790977f61289b0084
Moving slot 5455 from ccd2166eb56df50ece8988f790977f61289b0084
Moving slot 5456 from ccd2166eb56df50ece8988f790977f61289b0084
Moving slot 5457 from ccd2166eb56df50ece8988f790977f61289b0084
Moving slot 5458 from ccd2166eb56df50ece8988f790977f61289b0084
Moving slot 5459 from ccd2166eb56df50ece8988f790977f61289b0084
Moving slot 5460 from ccd2166eb56df50ece8988f790977f61289b0084
Do you want to proceed with the proposed reshard plan (yes/no)? yes

[root@localhost 7001]# /root/tools/redis-4.0.11/src/redis-trib.rb reshard 10.17.100.221:7008

Performing Cluster Check (using node 10.17.100.221:7008)
M: 1033b8a2893adcc7fee8464281f95116b9825383 10.17.100.221:7008
slots: (0 slots) master
0 additional replica(s)
M: 08bca5f84d3b7cb1c9df84ac8c25536985c30981 10.17.100.221:7007
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: c6eb5f1bb557b118c4cc391d613b3d63d1f44e30 10.17.100.222:7001
slots: (0 slots) slave
replicates 08bca5f84d3b7cb1c9df84ac8c25536985c30981
M: 1b5cbd25391f4ff0e7997e276ad4ad780cb0556a 10.17.100.222:7004
slots: (0 slots) master
0 additional replica(s)
S: cb8f5bf5a2999d496b41bed6a293a792a6e39dc3 10.17.100.222:7002
slots: (0 slots) slave
replicates 88fb94a3f6216c3ffb1bfd1db5d194d94422a584
S: 166607e8101ed75efd7ef939c32b5339004024d5 10.17.100.222:7003
slots: (0 slots) slave
replicates 22324a252ff2be093f59b250181c8c050e7fc180
M: 88fb94a3f6216c3ffb1bfd1db5d194d94422a584 10.17.100.222:7005
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 36f4ebfc772287e848e4d9b85b974675c2b61bd4 10.17.100.221:7009
slots: (0 slots) master
0 additional replica(s)
M: 22324a252ff2be093f59b250181c8c050e7fc180 10.17.100.222:7006
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.

Check for open slots…

Check slots coverage…

[OK] All 16384 slots covered.

How many slots do you want to move (from 1 to 16384)? 5462
What is the receiving node ID? 1033b8a2893adcc7fee8464281f95116b9825383
Please enter all the source node IDs.

Type ‘all’ to use all the nodes as source nodes for the hash slots.

Type ‘done’ once you entered all the source nodes IDs.

Source node #1:88fb94a3f6216c3ffb1bfd1db5d194d94422a584
Source node #2:done

7,然后数据迁移到7007和7008后,查看下当前cluster 和 nodes的信息

[root@localhost 7001]# bin/redis-cli -c -h 10.17.100.222 -p 7001
10.17.100.222:7001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:9
cluster_size:3
cluster_current_epoch:15
cluster_my_epoch:14
cluster_stats_messages_ping_sent:2016
cluster_stats_messages_pong_sent:2054
cluster_stats_messages_update_sent:36
cluster_stats_messages_sent:4106
cluster_stats_messages_ping_received:2051
cluster_stats_messages_pong_received:2016
cluster_stats_messages_meet_received:3
cluster_stats_messages_fail_received:2
cluster_stats_messages_update_received:446
cluster_stats_messages_received:4518
10.17.100.222:7001> cluster nodes
88fb94a3f6216c3ffb1bfd1db5d194d94422a584 10.17.100.222:7005@17005 master – 0 1601028728532 10 connected
22324a252ff2be093f59b250181c8c050e7fc180 10.17.100.222:7006@17006 master – 0 1601028732000 11 connected 10923-16383
1b5cbd25391f4ff0e7997e276ad4ad780cb0556a 10.17.100.222:7004@17004 master – 0 1601028729534 7 connected
1033b8a2893adcc7fee8464281f95116b9825383 10.17.100.221:7008@17008 master – 0 1601028729000 15 connected 5461-10922
36f4ebfc772287e848e4d9b85b974675c2b61bd4 10.17.100.221:7009@17009 master – 0 1601028729000 0 connected
08bca5f84d3b7cb1c9df84ac8c25536985c30981 10.17.100.221:7007@17007 master – 0 1601028732558 14 connected 0-5460
166607e8101ed75efd7ef939c32b5339004024d5 10.17.100.222:7003@17003 slave 22324a252ff2be093f59b250181c8c050e7fc180 0 1601028730537 11 connected
cb8f5bf5a2999d496b41bed6a293a792a6e39dc3 10.17.100.222:7002@17002 slave 1033b8a2893adcc7fee8464281f95116b9825383 0 1601028729000 15 connected
c6eb5f1bb557b118c4cc391d613b3d63d1f44e30 10.17.100.222:7001@17001 myself,slave 08bca5f84d3b7cb1c9df84ac8c25536985c30981 0 1601028731000 1 connected
10.17.100.222:7001>

8,然后把7001-7009都加上密码然后重启redis

9,然后把java和.net的后端的redis的地址加上7007 7008 7009

重启后台

2021-04-02发现redis迁移过程中老是报错

Calling MIGRATE: IOERR error or timeout reading to target instance

BUSYKEY Target key name already exists

有可能是重庆和上海的网络问题或者是

后来做了如下修改 vim /root/tools/redis-4.0.11/src/redis-trib.rb 这个文件

搜索60

把MigrateDefaultTimeout 改成了6000000

还有另外一个本来是60的也改成了6000000

每次报错先执行

/root/tools/redis-4.0.11/src/redis-trib.rb fix 10.17.100.221:7008

然后再继续

/root/tools/redis-4.0.11/src/redis-trib.rb reshard 10.17.100.221:7008

比较麻烦,但是暂时没找到原因为什么会报Calling MIGRATE: IOERR error or timeout reading to target instance

不知道是不是有些key里的内容太大了

上面修改了redis-trib.rb里的6000000 也没用

Original: https://www.cnblogs.com/xiaohanlin/p/13731452.html
Author: kuroniko
Title: redis cluster 数据迁移

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/529452/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 05-ElasticSearch高级搜索

    * package com.coolman.hotel.test; import com.coolman.hotel.pojo.HotelDoc; import com.faste…

    Linux 2023年6月7日
    086
  • git删除push到远程服务器的commit

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年8月30日
    0283
  • Redis Cluster集群

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年9月14日
    0259
  • Linux配置和管理设备映射多路径multipath

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年8月13日
    0259
  • JavaWeb-Git使用教程

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年8月30日
    0232
  • 【VSCode】vscode中配置默认终端为git-bash

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年8月30日
    0285
  • PyTorch 介绍 | 快速开始

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年11月12日
    0236
  • 【PHP】浅谈php实现订阅发布模式及redis的实现

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年9月14日
    0209
  • JCL 日志门面

    JCL( Jakarta Commons Logging ),是 Apache 提供的一个 通用日志 API 。用户可以自由选择第三方的日志组件作为具体实现,像 Log4j 或 J…

    Linux 2023年6月8日
    063
  • Linux Buffers和Cached的区别(转)

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年8月24日
    0222
  • 【Java8新特性】- 接口中默认方法修饰为普通方法

    Java8新特性 – 接口中默认方法修饰为普通方法 😄生命不息,写作不止🔥 继续踏上学习之路,学之分享笔记👊 总有一天我也能像各位大佬一样🏆 一个有梦有戏的人 @怒放吧…

    Linux 2023年6月6日
    091
  • [云原生]Kubernetes-Pod详解(第5章)

    一、Pod介绍 1.1 Pod结构 1.2 Pod定义 二、Pod配置 2.1 基本配置 2.2 镜像拉取 2.3 启动命令 2.4 环境变量 2.5 端口设置 2.6 资源配额 …

    Linux 2023年6月13日
    082
  • git常用命令

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年8月30日
    0268
  • Linux常用文件权限命令详解

    注入产生的原理: 数据库设置为GBK编码: 宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而…

    Linux 2022年9月10日
    0266
  • C语言怎么给函数添加形参的默认值

    如果不是机缘巧合,当年转到C++之后,恐怕很难再有机会还写C的代码。面向对象在现代coding中,就像圣经一样,在码农的口中自带光环,code起来左一个语法糖,右一个范式编程,各种…

    Linux 2023年6月6日
    089
  • scp 远程安全复制文件

    scp是 secure copy 的缩写,相当于 cp命令 + SSH。它的底层是 SSH 协议,默认端口是22,相当于先使用 ssh命令登录远程主机,然后再执行拷贝操作。 scp…

    Linux 2023年6月7日
    080
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球