一、查看集群状态

1.查看集群状态

/opt/redis/src/redis-cli -h 本机IP -p redsi实例端口 -c      #连接redis实例
/opt/redis/src/redis-cli -h 10.105.199.48 -p -c 10.105.199.48:7000> cluster info  #查看集群状态
cluster_state:ok            #ok表示集群正常
cluster_slots_assigned:16384    #已分配的槽
cluster_slots_ok:16384        #槽的状态是ok的数目
cluster_slots_pfail:0        #可能失效的槽的数目
cluster_slots_fail:0         #已经失效的槽的数目
cluster_known_nodes:6        #集群中节点个数
cluster_size:3            #集群中设置的分片个数
cluster_current_epoch:7       #集群中的currentEpoch总是一致的,currentEpoch越高,代表节点的配置或者操作越新,集群中最大的那个node epoch
cluster_my_epoch:2          #当前节点的config epoch,每个主节点都不同,一直递增, 其表示某节点最后一次变成主节点或获取新slot所有权的逻辑时间.
cluster_stats_messages_sent:337616    #
cluster_stats_messages_received:334496

2.查看节点信息

10.105.199.48:> cluster nodes  #查看集群节点
88370db287d1a30e262167008e9ff60009c33628 10.105.199.48: myself,slave 9b865041519484766bfa4b0d72f179f767c18091 connected
e93cbc4a0f50b41b2384f582b73b33bb4e598bda 10.105.199.48: slave 216694a6a93fdc2bb3231771d0fde5133e19c513 connected
216694a6a93fdc2bb3231771d0fde5133e19c513 10.105.199.48: master - connected -
9b865041519484766bfa4b0d72f179f767c18091 10.105.199.48: master - connected -
7618157e849b73aeff856f05d4f9a9e860d30da2 10.105.199.48: master - connected -
0ff033100f41af1f19f2faba600ae60affc47da8 10.105.199.48: slave 7618157e849b73aeff856f05d4f9a9e860d30da2 connected
#说明
节点ID:例如88370db287d1a30e262167008e9ff60009c33628
ip:port:节点的ip地址和端口号,例如10.105.199.:
flags:节点的角色(master,slave,myself)以及状态(pfail,fail)
如果节点是一个从节点的话,那么跟在flags之后的将是主节点的节点ID,例如10.105.199.:7000主节点的ID就是9b865041519484766bfa4b0d72f179f767c18091
集群最近一次向节点发送ping命令之后,过了多长时间还没接到回复
节点最近一次返回pong回复的时间
节点的配置纪元(config epoch)
本节点的网络连接情况
节点目前包含的槽,例如10.105.199.:7002目前包含的槽为10923-

二、Redis集群操作

1.删除从节点

(1)删除从节点
/opt/redis/src/redis-trib.rb del-node 10.105.199.48: e93cbc4a0f50b41b2384f582b73b33bb4e598bda  #删除节点,使用“redis-trib.rb del-node IP:端口实例ID”
>>> Removing node e93cbc4a0f50b41b2384f582b73b33bb4e598bda from cluster 10.105.199.48:7005
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
(2)查看集群状态
# /opt/redis/src/redis-cli -h 10.105.199.48 -p 7000 -c                                             
10.105.199.48:7000> cluster nodes
88370db287d1a30e262167008e9ff60009c33628 10.105.199.48:7000 myself,slave 9b865041519484766bfa4b0d72f179f767c18091 0 0 1 connected
216694a6a93fdc2bb3231771d0fde5133e19c513 10.105.199.48:7002 master - 0 1522676241162 3 connected 10923-16383
9b865041519484766bfa4b0d72f179f767c18091 10.105.199.48:7003 master - 0 1522676240661 7 connected 0-5460
7618157e849b73aeff856f05d4f9a9e860d30da2 10.105.199.48:7001 master - 0 1522676242165 2 connected 5461-10922
0ff033100f41af1f19f2faba600ae60affc47da8 10.105.199.48:7004 slave 7618157e849b73aeff856f05d4f9a9e860d30da2 0 1522676241664 5 connected
(3)查看节点状态
10.105.199.48:7000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:5      #发现少了一个节点
cluster_size:3
cluster_current_epoch:7
cluster_my_epoch:7
cluster_stats_messages_sent:5281
cluster_stats_messages_received:4448

2.删除主节点

()重新分配槽,将想删除的主节点槽重新分配为0
# /opt/redis/src/redis-trib.rb reshard 10.105.199.48: >>> Performing Cluster Check (using node 10.105.199.48:)
M: b1b5a9fa3ff177094cea730c2a63e2c185174af7 10.105.199.48:
slots:-,-,-,- ( slots) master
additional replica(s)
M: ca016bd0b77820183a593658b2f7f15af5f9a30c 10.105.199.48:
slots:- ( slots) master
additional replica(s)
M: bb8455d0387419acbb500bcb73b93036d5776c5b 10.105.199.48:
slots:- ( slots) master
additional replica(s)
M: 596bf938bb2e02a233e7f8c112b143434aa6ddc1 10.105.199.48:
slots:- ( slots) master
additional replica(s)
M: dc241e88be395bdc224bcfb11a111b9d9b0a9cfc 10.105.199.48:
slots:- ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
How many slots do you want to move (from to )?       #这个个数就是这个实例分配的槽数
What is the receiving node ID? bb8455d0387419acbb500bcb73b93036d5776c5b    #输入接收内存槽的实例ID
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 #:all  #输入all
Do you want to proceed with the proposed reshard plan (yes/no)? yes  #输入yes (2)删除节点
# /opt/redis/src/redis-trib.rb del-node 10.105.199.48:7000 b1b5a9fa3ff177094cea730c2a63e2c185174af7
>>> Removing node b1b5a9fa3ff177094cea730c2a63e2c185174af7 from cluster 10.105.199.48:7000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

3.添加主节点

(1)添加节点
# /opt/redis/src/redis-trib.rb add-node 10.105.199.48: 10.105.199.48:7001  #redis-trib.rb add-node 新节点IP:端口 已有节点IP:端口
>>> Adding node 10.105.199.48: to cluster 10.105.199.48:
>>> Performing Cluster Check (using node 10.105.199.48:)
M: 596bf938bb2e02a233e7f8c112b143434aa6ddc1 10.105.199.48:
slots: ( slots) master
additional replica(s)
M: ca016bd0b77820183a593658b2f7f15af5f9a30c 10.105.199.48:
slots: ( slots) master
additional replica(s)
M: dc241e88be395bdc224bcfb11a111b9d9b0a9cfc 10.105.199.48:
slots:- ( slots) master
additional replica(s)
M: bb8455d0387419acbb500bcb73b93036d5776c5b 10.105.199.48:
slots: ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Send CLUSTER MEET to node 10.105.199.48: to make it join the cluster.
[OK] New node added correctly. (2)重新分配内存槽
# /opt/redis/src/redis-trib.rb reshard 10.105.199.48:7005
>>> Performing Cluster Check (using node 10.105.199.48:7005)
M: 77f2256c607d67705ad456fb0460ffef116409b4 10.105.199.48:7005
   slots: (0 slots) master
   0 additional replica(s)
M: bb8455d0387419acbb500bcb73b93036d5776c5b 10.105.199.48:7002
   slots: (0 slots) master
   0 additional replica(s)
M: ca016bd0b77820183a593658b2f7f15af5f9a30c 10.105.199.48:7004
   slots: (0 slots) master
   0 additional replica(s)
M: b1b5a9fa3ff177094cea730c2a63e2c185174af7 10.105.199.48:7000
   slots: (0 slots) master
   0 additional replica(s)
M: dc241e88be395bdc224bcfb11a111b9d9b0a9cfc 10.105.199.48:7003
   slots:0-16383 (16384 slots) master
   0 additional replica(s)
M: 596bf938bb2e02a233e7f8c112b143434aa6ddc1 10.105.199.48:7001
   slots: (0 slots) master
   0 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)? 3276      #分配的槽数
What is the receiving node ID? 77f2256c607d67705ad456fb0460ffef116409b4  #新节点ID
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:all    #all      #输入all
Do you want to proceed with the proposed reshard plan (yes/no)?yes  #输入yes

Redis-集群操作的更多相关文章

  1. golang redis集群操作:redis-go-cluster

    背景 感觉redis-cli desktop及其难用,最近用golang做了个redis查询工具,支持单例和集群操作,终于不再卡顿!!! 用到的包 "github.com/garyburd/ ...

  2. Java连接redis集群操作存储、删除以及获取值

    pom文件添加: <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> &l ...

  3. Redis集群操作手册

    一.原始集群(6节点 3主3从): (1)启动集群: [root@bhz004 ~]# /usr/local/redis/bin/redis-server /usr/local/redis-clust ...

  4. 【Redis学习之十一】Java客户端实现redis集群操作

    客户端:jedis-2.7.2.jar 配置文件两种方式: properties: redis.cluster.nodes1=192.168.1.117 redis.cluster.port1=700 ...

  5. Redis集群的使用测试(Jedis客户端的使用)

    Redis集群的使用测试(Jedis客户端的使用)1.Jedis客户端建议升级到最新版(当前为2.7.3),这样对3.0.x集群有比较好的支持.https://github.com/xetorthio ...

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

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

  7. Java Spring mvc 操作 Redis 及 Redis 集群

    本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5941953.html 关于 Redis 集群搭建可以参考我的另一篇文章 Redis集群搭建与简单使用 R ...

  8. 分布式缓存技术redis学习系列(四)——redis高级应用(集群搭建、集群分区原理、集群操作)

    本文是redis学习系列的第四篇,前面我们学习了redis的数据结构和一些高级特性,点击下面链接可回看 <详细讲解redis数据结构(内存模型)以及常用命令> <redis高级应用( ...

  9. 分布式缓存技术redis学习(四)——redis高级应用(集群搭建、集群分区原理、集群操作)

    本文是redis学习系列的第四篇,前面我们学习了redis的数据结构和一些高级特性,点击下面链接可回看 <详细讲解redis数据结构(内存模型)以及常用命令> <redis高级应用( ...

  10. java操作redis集群配置[可配置密码]和工具类(比较好用)

    转: java操作redis集群配置[可配置密码]和工具类 java操作redis集群配置[可配置密码]和工具类     <dependency>   <groupId>red ...

随机推荐

  1. bootstrap-table.min.js不同版本返回分页参数不同的问题

    1.使用公司用的bootstrap-table.min.js ,刚开始bootstrap-table分页参数是这么写的 分页查询参数: 后端代码为: Result返回类的参数为list,以及total ...

  2. SpringMVC 中的注解@RequestParam与@PathVariable的区别

    @PathVariable绑定URI模板变量值 @PathVariable是用来获得请求url中的动态参数的 @PathVariable用于将请求URL中的模板变量映射到功能处理方法的参数上.//配置 ...

  3. 界面开发工具集Telerik UI for ASP.NET AJAX发布R2 2019

    Telerik UI for ASP.NET AJAX拥有构建ASP.NET AJAX和SharePoint应用程序的80+控件,将为任何浏览器和设备构建Web Forms应用程序的时间缩短一半.Te ...

  4. 【转】原生js实现移动端h5长按事件

    $("#target").on({ touchstart: function(e) { // 长按事件触发 timeOutEvent = setTimeout(function() ...

  5. springboot 配置quart多数据源

    Springboot版本为2.1.6 多数据源配置使用druid进行配置,数据库使用的为Oracle11g,如果使用的是MySQL,直接将数据库的地址和驱动改一下即可 <parent> & ...

  6. LOJ-6280-数列分块入门4

    链接: https://loj.ac/problem/6280 题意: 给出一个长为n 的数列,以及 n个操作,操作涉及区间加法,区间求和. 思路: sum维护区间和, tag维护每个区间多加的,不是 ...

  7. Vue结合webpack实现路由懒加载和分类打包

    https://blog.csdn.net/weixin_39205240/article/details/80742723

  8. Python 3标准库第三章

    时间过得很快,又是一周过去了,今天感觉迷迷糊糊的,不在状态,然后,下面开始我们的讲解,还是跟大家分享一下我自己的一些想法,第一.怎么讲了,就是各位如果有怀才不遇的想法,我感觉最好不要有这种想法;第二. ...

  9. 对TypeScript进行研究

    1.npm install -g typescript 在编辑器,将下面的代码输入到greeter.ts文件里: function greeter(person) { return "Hel ...

  10. js-展开评论与隐藏评论

    //控制展开评论和隐藏评论 controldiscuss(){ $(".opendiss").click(function(){ if($(this).context.innerH ...