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实例
[[email protected] redis7014]# redis-server /home/redis/redis7013/redis7013.conf
[[email protected] redis7014]# redis-server /home/redis/redis7014/redis7014.conf
[[email protected] 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

[[email protected] 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)执行过脚本如下:

[[email protected] 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

[[email protected] 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报错。这个要确认。下面执行迁移过程
[[email protected] ~]# 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相同槽位到新节点上。 执行完查看节点信息,发现已经完全迁移上去了。

[[email protected] ~]# 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上执行
[[email protected] 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
新加入节点做主从:
[[email protected] 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到新实例上,并且每次迁移完成都要查看一下节点状态):
[[email protected] ~]# 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
[[email protected] ~]# redis-cli -h 172,16.128.240 -p 7003 -a ***********cluster nodes
[[email protected] ~]# redis-cli -h 172,16.128.240 -p 7003 -a ***********cluster info

原文地址:https://www.cnblogs.com/shengdimaya/p/9160373.html

时间: 2024-10-16 22:28:22

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

Redis 集群搭建(基于Linux)

一.基础环境 1.虚拟机 VMware 15.x 2.Linux系统,用的是Centos7的Linux系统 3.Redis数据库版本 5.0.3 二.Redis集群简介 1.背景 Redis在3.0版本前只支持单实例模式,虽然支持主从模式部署来解决单点的故障,但是现在互联网企业的数据,都是几百G的数据,完全无法满足业务的需求,所以,在3.0版本以后就退出了集群模式. 2.概念 将多台Redis的服务器组成集群,分担负载.相对于主从架构,是进一步的扩展和升级.集群中的多台主服务器,同时对外提供读写

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

Redis SentinelSentinel(哨兵)是用于监控redis集群中Master状态的工具,其已经被集成在redis2.4+的版本中 一.Sentinel作用:1):Master状态检测 2):如果Master异常,则会进行Master-Slave切换,将其中一个Slave作为Master,将之前的Master作为Slave3):Master-Slave切换后,master_redis.conf.slave_redis.conf和sentinel.conf的内容都会发生改变,即mast

分布式锁--redis(集群)

原文链接:https://blog.csdn.net/weixin_38003389/article/details/89434629 redis 集群做分布式锁,我们使用 Redisson. 框架 版本 Spring Boot 2.0.3.RELEASE Spring Cloud Finchley.RELEASE redis redis-4.0.11 JDK 1.8.x maven配置 <parent> <groupId>org.springframework.boot</

python 操作redis集群

redis集群 cd /usr/local/redis3.0/src ./redis-trib.rb  create --replicas 1 ip1:7000 ip1:7001 cluster info/nodes redis-cli -c -h yourhost -p yourpost https://github.com/andymccurdy/redis-py pip install redis-py-cluster pip升级pip-9.0.1.tar.gz # !/usr/bin/e

redis集群环境搭建的错误

安装redis集群需要版本号在3.0以上 redis-cluster安装前需要安装ruby环境 搭建集群需要使用到官方提供的ruby脚本. 需要安装ruby的环境. yum -y install ruby yum -y install rubygems redis集群管理工具redis-trib.rb [[email protected] ~]# cd redis-3.0.0 [[email protected] redis-3.0.0]# cd src [[email protected] s

Redis 3.0正式版发布,正式支持Redis集群

Redis是一个开源.基于C语言.基于内存亦可持久化的高性能NoSQL数据库,同时,它还提供了多种语言的API.近日,Redis 3.0在经过6个RC版本后,其正式版终于发布了.Redis 3.0的最重要特征是对Redis集群的支持,此外,该版本相对于2.8版本在性能.稳定性等方面都有了重大提高. Redis 3.0正式版相对于RC6版本的改进内容包括: 修复了无磁盘情况下的的复制问题: 在角色变化后对BLPOP复制进行了测试: 改进了prepareClientToWrite()错误处理: 移除

Redis 3.0 新特性,支持redis 集群

Redis是一个开源.基于C语言.基于内存亦可持久化的高性能NoSQL数据库,同时,它还提供了多种语言的API. 近日,Redis 3.0在经过6个RC版本后,其正式版终于发布了. Redis 3.0的最重要特征是对Redis集群的支持,此外,该版本相对于2.8版本在性能.稳定性等方面都有了重大提高. 一.Redis 3.0正式版相对于RC6版本的改进内容包括: 1.修复了无磁盘情况下的的复制问题: 2.在角色变化后对BLPOP复制进行了测试: 3.改进了prepareClientToWrite

基于Twemproxy的Redis集群方案

概述 由于单台redis服务器的内存管理能力有限,使用过大内存redis服务器的性能急剧下降,且服务器发生故障将直接影响大面积业务.为了获取更好的缓存性能及扩展型,我们将需要搭建redis集群来满足需求.因redis 3.0 beta支持的集群功能不适合生产环境的使用,所以我们采用twitter正在使用的twemproxy来搭建redis缓存服务器集群,目前用户包括Pinterest.Tumblr.Twitter.Vine.Kiip.Wuaki.tv.Wanelo.Kontera.Wikimed

基于Redis Sentinel的Redis集群(主从&Sharding)高可用方案

基于Redis Sentinel的Redis集群(主从&Sharding)高可用方案 http://www.tuicool.com/articles/naeEJbv 基于Redis Sentinel的Redis集群(主从&Sharding)高可用方案 时间 2014-02-21 15:15:17  IT社区推荐资讯 原文  http://itindex.net/detail/48192-redis-sentinel-redis Redis Sentinel是一个分布式系统,可以部署多个Se