redis集群热扩展(基于4.0.9)
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)的更多相关文章
- Dubbo入门到精通学习笔记(十五):Redis集群的安装(Redis3+CentOS)、Redis集群的高可用测试(含Jedis客户端的使用)、Redis集群的扩展测试
文章目录 Redis集群的安装(Redis3+CentOS) 参考文档 Redis 集群介绍.特性.规范等(可看提供的参考文档+视频解说) Redis 集群的安装(Redis3.0.3 + CentO ...
- Redis 集群搭建(基于Linux)
一.基础环境 1.虚拟机 VMware 15.x 2.Linux系统,用的是Centos7的Linux系统 3.Redis数据库版本 5.0.3 二.Redis集群简介 1.背景 Redis在3.0版 ...
- redis 集群热备自动切换sentinel配置实战
---恢复内容开始--- Redis SentinelSentinel(哨兵)是用于监控redis集群中Master状态的工具,其已经被集成在redis2.4+的版本中一.Sentinel作用:1): ...
- Redis 集群_主从复制_哨兵模型
1 redis集群简介 1.1 集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 1.1.1 使用redis集群的必要性 问题:我们已经部署好了 ...
- Windows搭建Redis集群-详细教程
一.集群知识 1.集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 2.使用redis集群的必要性 问题:我们已经部署好了redis,并且能启动 ...
- redis集群简介
1.1 集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 1.1.1 使用redis集群的必要性 问题:我们已经部署好 ...
- Redis学习之路(二)Redis集群搭建
一.Redis集群搭建说明 基于三台虚拟机部署9个节点,一台虚拟机三个节点,创建出4个master.4个slave的Redis集群. Redis 集群搭建规划,由于集群至少需要6个节点(3主3从模式) ...
- Redis集群教程(Redis cluster tutorial)
本博文翻译自Redis官网:http://redis.io/topics/cluster-tutorial 本文档以温和的方式介绍Redis集群,不使用复杂的方式来理解分布式系统的概念. ...
- Redis 集群的安装
Redis 集群介绍.特性.规范等Redis 集群的安装(Redis3.0.3 + CentOS6.6_x64)要让 Redis3.0 集群正常工作至少需要 3 个 Master 节点,要想实现高可用 ...
随机推荐
- 按照Right-BICEP要求对实验二进行测试
我的代码实现的功能很简单,在最基本的功能上,包括有无括号(0/1),有无负数(0/1),有无乘除法(0/1)验证程序的正确性,测试用例为8个,2^3个,也就覆盖了所有的代码路径. 测试计划: 基本功能 ...
- tomcat安装以及常用配置
目录 一 什么是tomcat 二 tomcat 的版本: 三 tomcat的下载 3.1 tomcat9版本下载链接 3.2 tomcat8.5版本下载链接 四 tomcat的安装 4.1 java环 ...
- 入坑python 自己写的小工具,纪念一下
这个程序的功能是可以从表格中读取某一列数据,传到IDs 这一个参数里,然后在url中获取相应的请求值,并打印 import urllib.request import json import xlrd ...
- SharePoint 2013 EventHanlder工具
之前在07的时候使用SharePoint Event Receiver Manager (2007 & 2010)来管理SharePoint的Event Handler,但是2013后作者没有 ...
- Java 和 JSP 实现网站访问量统计 (刷新过滤)
java 和 JSP 实现的统计网站访问量,不需要数据库,将数据存储在 指定位置的 txt 文件中,代码块分为两部分 首先, java 部分: import java.io.File; import ...
- C#字符串中的中文逗号转英文逗号
public static string ToDBC(string input) { char[] c = input.ToCharArray(); for (int i = 0; i < c. ...
- 用bind方法保持this上下文
什么是this对象 先来说说什么是this对象吧.每一个函数在调用的时候都会自己主动获取两个特殊变量:this和arguments对象. this值详细是指哪个对象是和该函数的运行环境相关的.假设是作 ...
- spring jpa和mybatis整合
spring jpa和mybatis整合 前一阵子接手了一个使用SpringBoot 和spring-data-jpa开发的项目 后期新加入一个小伙伴,表示jpa相比mybatis太难用,多表联合的查 ...
- php 多次导入文件导致 Cannot redeclare class
定义了类A b.php中导入了A c.php中导入了b.php c.php中导入A会报错:
- Invoke 和 BeginInvoke 的区别
在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是dot ...