1:环境说明,首先说一下要做的事情,我们要迁移redis集群槽位,现有redis集群环境如下
172,16.128.240:7003
172,16.128.240:7004
172,16.128.241:7003
172,16.128.241:7004
172,16.128.242:7003
172,16.128.242:7004

我们看一下集群的基本信息:

172,16.128.240:7003> cluster nodes
8ea64a0049e0b193296aeba868391e7b009ed562 172,16.128.241:7004@17004 slave 7a35e29ebffb7fd42a9533811b8fcf67955635f2 0 1528448456000 4 connected
1cbccbfa9a6ee62d2f744af14fddfe97cc491926 172,16.128.242:7003@17003 master - 0 1528448456095 2 connected 10923-16383
d4fac62706aa4def7611a495676ebc2151fc07ba 172,16.128.240:7003@17003 myself,master - 0 1528448456000 0 connected 0-5461
3801a25ac04c7e2c610c1df9588c107e0ed62fa1 172,16.128.242:7004@17004 slave 1cbccbfa9a6ee62d2f744af14fddfe97cc491926 0 1528448457096 5 connected
7a35e29ebffb7fd42a9533811b8fcf67955635f2 172,16.128.241:7003@17003 master - 0 1528448455000 1 connected 5462-10922
7f2dbd47e72c7b15b160e0f11d9f0ef86f225c27 172,16.128.240:7004@17004 slave d4fac62706aa4def7611a495676ebc2151fc07ba 0 1528448458098 3 connected
2:在172,16.128.242上创建7013和7014实例
[root@mxq-ss1 redis7014]# redis-server /home/redis/redis7013/redis7013.conf
[root@mxq-ss1 redis7014]# redis-server /home/redis/redis7014/redis7014.conf
[root@mxq-ss1 redis7004]# ps -ef|grep redis
root 41550 1 0 01:21 ? 00:00:09 redis-server 172,16.128.242:7003 [cluster]
root 41559 1 0 01:22 ? 00:00:09 redis-server 172,16.128.242:7004 [cluster]
root 45182 1 0 04:54 ? 00:00:00 redis-server 172,16.128.242:7013 [cluster]
root 45187 1 0 04:54 ? 00:00:00 redis-server 172,16.128.242:7014 [cluster]
root 45192 34163 0 04:54 pts/3 00:00:00 grep --color=auto redis

3:正式进行热拓展测试(以下脚本将要应用到生产机房,请审视)

(1)server172,16.128.240

[root@mxq-ss3 data]# redis-cli -h 172,16.128.240 -p 7003 -a Rmbe7q3btATOE2Xyvmv
172,16.128.240:7003> cluster nodes
8ea64a0049e0b193296aeba868391e7b009ed562 172,16.128.241:7004@17004 slave 7a35e29ebffb7fd42a9533811b8fcf67955635f2 0 1528449386696 4 connected
1cbccbfa9a6ee62d2f744af14fddfe97cc491926 172,16.128.242:7003@17003 master - 0 1528449385694 2 connected 10923-16383
d4fac62706aa4def7611a495676ebc2151fc07ba 172,16.128.240:7003@17003 myself,master - 0 1528449384000 0 connected 0-5461
3801a25ac04c7e2c610c1df9588c107e0ed62fa1 172,16.128.242:7004@17004 slave 1cbccbfa9a6ee62d2f744af14fddfe97cc491926 0 1528449384692 5 connected
7a35e29ebffb7fd42a9533811b8fcf67955635f2 172,16.128.241:7003@17003 master - 0 1528449384000 1 connected 5462-10922
7f2dbd47e72c7b15b160e0f11d9f0ef86f225c27 172,16.128.240:7004@17004 slave d4fac62706aa4def7611a495676ebc2151fc07ba 0 1528449384000 3 connected
172,16.128.240:7003> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:0
cluster_stats_messages_ping_sent:4212
cluster_stats_messages_pong_sent:4031
cluster_stats_messages_meet_sent:5
cluster_stats_messages_sent:8248
cluster_stats_messages_ping_received:4031
cluster_stats_messages_pong_received:4217
cluster_stats_messages_received:8248
172,16.128.240:7003> cluster meet 172,16.128.242 7013
OK
172,16.128.240:7003> cluster meet 172,16.128.242 7014
OK
172,16.128.240:7003> cluster nodes
8ea64a0049e0b193296aeba868391e7b009ed562 172,16.128.241:7004@17004 slave 7a35e29ebffb7fd42a9533811b8fcf67955635f2 0 1528449505892 4 connected
1cbccbfa9a6ee62d2f744af14fddfe97cc491926 172,16.128.242:7003@17003 master - 0 1528449506000 2 connected 10923-16383
c73b4e70468d091e40123122ce140422f027d0d2 172,16.128.242:7013@17013 master - 0 1528449506593 6 connected
d4fac62706aa4def7611a495676ebc2151fc07ba 172,16.128.240:7003@17003 myself,master - 0 1528449503000 0 connected 0-5461
3801a25ac04c7e2c610c1df9588c107e0ed62fa1 172,16.128.242:7004@17004 slave 1cbccbfa9a6ee62d2f744af14fddfe97cc491926 0 1528449504000 5 connected
7a35e29ebffb7fd42a9533811b8fcf67955635f2 172,16.128.241:7003@17003 master - 0 1528449504891 1 connected 5462-10922
7f2dbd47e72c7b15b160e0f11d9f0ef86f225c27 172,16.128.240:7004@17004 slave d4fac62706aa4def7611a495676ebc2151fc07ba 0 1528449505000 3 connected
bd40901964330046ff5752fe62c7e11abba7ab06 172,16.128.242:7014@17014 master - 0 1528449506892 7 connected
172,16.128.240:7003> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:3
cluster_current_epoch:7
cluster_my_epoch:0
cluster_stats_messages_ping_sent:4341
cluster_stats_messages_pong_sent:4147
cluster_stats_messages_meet_sent:7
cluster_stats_messages_sent:8495
cluster_stats_messages_ping_received:4147
cluster_stats_messages_pong_received:4348
cluster_stats_messages_received:8495

(2)执行过脚本如下:

[root@mxq-ss3 data]# redis-cli -h 172,16.128.240 -p 7003 -a Rmbe7q3btATOE2Xyvmv
172,16.128.240:7003> cluster nodes
172,16.128.240:7003> cluster info
172,16.128.240:7003> cluster meet 172,16.128.242 7013
OK
172,16.128.240:7003> cluster meet 172,16.128.242 7014
OK
172,16.128.240:7003> cluster nodes
172,16.128.240:7003> cluster info

我们从上面信息已经看出已经将新建节点加入到了集群当中。下面开始将新加入的节点作为主从 server172,16.128.242

[root@mxq-ss1 redis7014]# redis-cli -h 172,16.128.242 -p 7014 -a Rmbe7q3btATOE2Xyvmv
172,16.128.242:7014> cluster replicate c73b4e70468d091e40123122ce140422f027d0d2
OK
172,16.128.242:7014> CLUSTER NODES
8ea64a0049e0b193296aeba868391e7b009ed562 172,16.128.241:7004@17004 slave 7a35e29ebffb7fd42a9533811b8fcf67955635f2 0 1528449970993 1 connected
d4fac62706aa4def7611a495676ebc2151fc07ba 172,16.128.240:7003@17003 master - 0 1528449971994 0 connected 0-5461
7f2dbd47e72c7b15b160e0f11d9f0ef86f225c27 172,16.128.240:7004@17004 slave d4fac62706aa4def7611a495676ebc2151fc07ba 0 1528449968000 0 connected
3801a25ac04c7e2c610c1df9588c107e0ed62fa1 172,16.128.242:7004@17004 slave 1cbccbfa9a6ee62d2f744af14fddfe97cc491926 0 1528449972000 2 connected
7a35e29ebffb7fd42a9533811b8fcf67955635f2 172,16.128.241:7003@17003 master - 0 1528449972996 1 connected 5462-10922
c73b4e70468d091e40123122ce140422f027d0d2 172,16.128.242:7013@17013 master - 0 1528449970000 6 connected
bd40901964330046ff5752fe62c7e11abba7ab06 172,16.128.242:7014@17014 myself,slave c73b4e70468d091e40123122ce140422f027d0d2 0 1528449971000 7 connected
1cbccbfa9a6ee62d2f744af14fddfe97cc491926 172,16.128.242:7003@17003 master - 0 1528449969000 2 connected 10923-16383
4:执行完以后进行热拓展

先说明一下现在有三台主从,做热拓展的话,每个槽位都要迁移出1365个槽位到172,16.128.242:7013的redis实例上。以下是迁移步骤 执行机器:172,16.128.240

执行以前,我们要确定以下配置文件
vi /usr/local/rvm/gems/ruby-2.4.1/gems/redis-4.0.1/lib/redis/client.rb
里面配置和redis的配置要一致,不然连不上redis报错。这个要确认。下面执行迁移过程
[root@mxq-ss3 ~]# redis-trib.rb reshard 172,16.128.240:7003
How many slots do you want to move (from 1 to 16384)? 1364
What is the receiving node ID? 363ecec54c92c2548dcab016146bdb4c104e5e84
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:c73b4e70468d091e40123122ce140422f027d0d2
Source node #2:done

查看节点信息:

172,16.128.240:7003> cluster nodes
8ea64a0049e0b193296aeba868391e7b009ed562 172,16.128.241:7004@17004 slave 7a35e29ebffb7fd42a9533811b8fcf67955635f2 0 1528535455177 4 connected
1cbccbfa9a6ee62d2f744af14fddfe97cc491926 172,16.128.242:7003@17003 master - 0 1528535457181 2 connected 10923-16383
c73b4e70468d091e40123122ce140422f027d0d2 172,16.128.242:7013@17013 master - 0 1528535456180 6 connected
d4fac62706aa4def7611a495676ebc2151fc07ba 172,16.128.240:7003@17003 myself,master - 0 1528535455000 0 connected 0-5461
3801a25ac04c7e2c610c1df9588c107e0ed62fa1 172,16.128.242:7004@17004 slave 1cbccbfa9a6ee62d2f744af14fddfe97cc491926 0 1528535455000 5 connected
7a35e29ebffb7fd42a9533811b8fcf67955635f2 172,16.128.241:7003@17003 master - 0 1528535453172 1 connected 5462-10922
7f2dbd47e72c7b15b160e0f11d9f0ef86f225c27 172,16.128.240:7004@17004 slave d4fac62706aa4def7611a495676ebc2151fc07ba 0 1528535453000 3 connected
bd40901964330046ff5752fe62c7e11abba7ab06 172,16.128.242:7014@17014 slave c73b4e70468d091e40123122ce140422f027d0d2 0 1528535453000 7 connected
172,16.128.240:7003> cluster nodes
8ea64a0049e0b193296aeba868391e7b009ed562 172,16.128.241:7004@17004 slave 7a35e29ebffb7fd42a9533811b8fcf67955635f2 0 1528535856000 4 connected
1cbccbfa9a6ee62d2f744af14fddfe97cc491926 172,16.128.242:7003@17003 master - 0 1528535852000 2 connected 10923-16383
c73b4e70468d091e40123122ce140422f027d0d2 172,16.128.242:7013@17013 master - 0 1528535856884 8 connected 0-1364
d4fac62706aa4def7611a495676ebc2151fc07ba 172,16.128.240:7003@17003 myself,master - 0 1528535854000 0 connected 1365-5461
3801a25ac04c7e2c610c1df9588c107e0ed62fa1 172,16.128.242:7004@17004 slave 1cbccbfa9a6ee62d2f744af14fddfe97cc491926 0 1528535855883 5 connected
7a35e29ebffb7fd42a9533811b8fcf67955635f2 172,16.128.241:7003@17003 master - 0 1528535856000 1 connected 5462-10922
7f2dbd47e72c7b15b160e0f11d9f0ef86f225c27 172,16.128.240:7004@17004 slave d4fac62706aa4def7611a495676ebc2151fc07ba 0 1528535855000 3 connected
bd40901964330046ff5752fe62c7e11abba7ab06 172,16.128.242:7014@17014 slave c73b4e70468d091e40123122ce140422f027d0d2 0 1528535854000 8 connected

发现执行完毕,已经迁移了。接下来同样方式迁移其他两台master相同槽位到新节点上。 执行完查看节点信息,发现已经完全迁移上去了。

[root@mxq-ss3 ~]# redis-cli -h 172,16.128.240 -p 7003 -a ***********cluster nodes
8ea64a0049e0b193296aeba868391e7b009ed562 172,16.128.241:7004@17004 slave 7a35e29ebffb7fd42a9533811b8fcf67955635f2 0 1528536351000 4 connected
1cbccbfa9a6ee62d2f744af14fddfe97cc491926 172,16.128.242:7003@17003 master - 0 1528536352764 2 connected 12287-16383
c73b4e70468d091e40123122ce140422f027d0d2 172,16.128.242:7013@17013 master - 0 1528536349759 8 connected 0-1364 5462-6825 10923-12286
d4fac62706aa4def7611a495676ebc2151fc07ba 172,16.128.240:7003@17003 myself,master - 0 1528536351000 0 connected 1365-5461
3801a25ac04c7e2c610c1df9588c107e0ed62fa1 172,16.128.242:7004@17004 slave 1cbccbfa9a6ee62d2f744af14fddfe97cc491926 0 1528536349000 5 connected
7a35e29ebffb7fd42a9533811b8fcf67955635f2 172,16.128.241:7003@17003 master - 0 1528536350759 1 connected 6826-10922
7f2dbd47e72c7b15b160e0f11d9f0ef86f225c27 172,16.128.240:7004@17004 slave d4fac62706aa4def7611a495676ebc2151fc07ba 0 1528536351761 3 connected
bd40901964330046ff5752fe62c7e11abba7ab06 172,16.128.242:7014@17014 slave c73b4e70468d091e40123122ce140422f027d0d2 0 1528536350000 8 connected

整体迁移脚本如下:

脚本步骤:
脚本步骤: 11:server10:server172,16.128.240上执行
[root@mxq-ss3 data]# redis-cli -h 172,16.128.240 -p 7003 -a Rmbe7q3btATOE2Xyvmv
172,16.128.240:7003> cluster nodes
172,16.128.240:7003> cluster info
172,16.128.240:7003> cluster meet 172,16.128.242 7013
OK
172,16.128.240:7003> cluster meet 172,16.128.242 7014
OK
172,16.128.240:7003> cluster nodes
172,16.128.240:7003> cluster info
新加入节点做主从:
[root@mxq-ss1 redis7014]# redis-cli -h 172,16.128.242 -p 7014 -a Rmbe7q3btATOE2Xyvmv
172,16.128.242:7014> cluster replicate c73b4e70468d091e40123122ce140422f027d0d2
OK
172,16.128.242:7014> CLUSTER NODES
下面进行迁移(注意我们要执行三次,手动从240,241,242上7003实例迁移1364个slot到新实例上,并且每次迁移完成都要查看一下节点状态):
[root@mxq-ss3 ~]# redis-trib.rb reshard 172,16.128.240:7003
How many slots do you want to move (from 1 to 16384)? 1364
What is the receiving node ID? 363ecec54c92c2548dcab016146bdb4c104e5e84
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:c73b4e70468d091e40123122ce140422f027d0d2
Source node #2:done
[root@mxq-ss3 ~]# redis-cli -h 172,16.128.240 -p 7003 -a ***********cluster nodes
[root@mxq-ss3 ~]# redis-cli -h 172,16.128.240 -p 7003 -a ***********cluster info

redis集群热扩展(基于4.0.9)的更多相关文章

  1. Dubbo入门到精通学习笔记(十五):Redis集群的安装(Redis3+CentOS)、Redis集群的高可用测试(含Jedis客户端的使用)、Redis集群的扩展测试

    文章目录 Redis集群的安装(Redis3+CentOS) 参考文档 Redis 集群介绍.特性.规范等(可看提供的参考文档+视频解说) Redis 集群的安装(Redis3.0.3 + CentO ...

  2. Redis 集群搭建(基于Linux)

    一.基础环境 1.虚拟机 VMware 15.x 2.Linux系统,用的是Centos7的Linux系统 3.Redis数据库版本 5.0.3 二.Redis集群简介 1.背景 Redis在3.0版 ...

  3. redis 集群热备自动切换sentinel配置实战

    ---恢复内容开始--- Redis SentinelSentinel(哨兵)是用于监控redis集群中Master状态的工具,其已经被集成在redis2.4+的版本中一.Sentinel作用:1): ...

  4. Redis 集群_主从复制_哨兵模型

    1 redis集群简介 1.1 集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 1.1.1 使用redis集群的必要性 问题:我们已经部署好了 ...

  5. Windows搭建Redis集群-详细教程

    一.集群知识 1.集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 2.使用redis集群的必要性 问题:我们已经部署好了redis,并且能启动 ...

  6. redis集群简介

    1.1        集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 1.1.1       使用redis集群的必要性 问题:我们已经部署好 ...

  7. Redis学习之路(二)Redis集群搭建

    一.Redis集群搭建说明 基于三台虚拟机部署9个节点,一台虚拟机三个节点,创建出4个master.4个slave的Redis集群. Redis 集群搭建规划,由于集群至少需要6个节点(3主3从模式) ...

  8. Redis集群教程(Redis cluster tutorial)

    本博文翻译自Redis官网:http://redis.io/topics/cluster-tutorial        本文档以温和的方式介绍Redis集群,不使用复杂的方式来理解分布式系统的概念. ...

  9. Redis 集群的安装

    Redis 集群介绍.特性.规范等Redis 集群的安装(Redis3.0.3 + CentOS6.6_x64)要让 Redis3.0 集群正常工作至少需要 3 个 Master 节点,要想实现高可用 ...

随机推荐

  1. SearchView去掉下划线

    SearchView calSearchView = (SearchView) findViewById(R.id.sv_search_text); if (calSearchView != null ...

  2. HTML&&css面试题

    HTML&css相关问题 1.XHTML和HTML有什么区别 HTML是一种基本的WEB网页设计语言,XHTML是一个基于XMl的置标语言 最主要的不同 XHTML元素必须被正确地嵌套. XH ...

  3. [Codeforces 925C]Big Secret

    Description 题库链接 给出 \(n\) 个数,让你生成这 \(n\) 个数的一个排列 \(A\) .定义 \(B_i = \bigoplus\limits_{j=1}^i A_j\) , ...

  4. oracle 比较日期相等

    where to_char(date1, 'yyyymmdd')=to_char(date2,'yyyymmdd'); or where to_date(char1, 'yyyymmdd')=to_d ...

  5. Vue双向绑定的关键:Object.defineProperty()

    这个方法了不起啊.vue.js和avalon.js 都是通过它实现双向绑定的.而且Object.observe也被草案发起人撤回了.所以defineProperty更有必要了解一下了. 先上几行代码看 ...

  6. Red Hat Linux 无法使用yum命令

    一:首先提供部分Red Hat 镜像下载地址 1.rhel-server-6.8-i386-dvd.iso 链接: https://pan.baidu.com/s/18VqxRgBMuAJE7Ty0H ...

  7. ABP学习入门系列(一)(第一个ABP项目)

    ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称.ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应用程序的新起点,它 ...

  8. AngleSharp一些示例

    看到了AngleSharp,感觉这个非常好用,比HtmlAgilityPack感觉好用点 AngleSharp 地址:https://github.com/AngleSharp/AngleSharp ...

  9. Servlet的数据库访问

    创建数据库:   import java.sql.*; public class SqlUtil { static { try { Class.forName("com.mysql.jdbc ...

  10. oracle序列的创建和使用

    oracle 序列的创建与使用 (2012-03-15 16:14:09) -------------------------------------------------------------- ...