一、查看集群状态

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. ES6---new Promise()讲解(尤其注意里面的参数resolve、reject)

    直接打印出来看看吧,console.dir(Promise). 这么一看就明白了,Promise是一个构造函数,自己身上有all.reject.resolve这几个眼熟的方法,原型上有then.cat ...

  2. 故障检测、性能调优与Java类加载机制

    故障检测.性能调优与Java类加载机制 故障检测.性能调优 用什么工具可以查出内存泄露 (1)MerroyAnalyzer:一个功能丰富的java堆转储文件分析工具,可以帮助你发现内存漏洞和减少内存消 ...

  3. Nginx之概念和简介

    Nginx是什么? 代理服务器,处于客户端和服务器端之间的一台服务器,不负责处理请求. 主要作用是什么? 1.负载均衡: 高并发场景下,Nginx代理服务器按一定规则将请求分发,从而使服务器能有条不紊 ...

  4. 015:URLs分层模块化

    URLs分层模块化: 经过上面的14节课程,大伙有没有发现一个问题:那就是随着的项目功能模块越来越多,所有url匹配都写在一个urls.py文件中,其结果是:文件长,看着心累——需要分门别类:因此能不 ...

  5. linux 系统下 tar 的压缩与解压缩命令

    1.压缩 [small@sun shine]# tar -zcvf java.tar.gz java java/ java/default/ java/default/THIRDPARTYLICENS ...

  6. SDRAM学习笔记

    摘自“开源骚客视频教程” 1.仲裁模块就是用来控制什么时候读.写.刷新 2.模块中的状态机 3.初始化时序图说明,来自“IS42S116160.pdf”文件 4.SDRAM写时序图,来自“IS42S1 ...

  7. react样式

    https://www.jianshu.com/p/711c596571d6(copy)

  8. 在Sublime Text 3中配置Python3的开发环境/Build System

    本文来源:https://www.cnblogs.com/zhangqinwei/p/6886600.html Sublime Text作为一款支持多种编程语言的文本编辑神器,深受广大开发者的喜爱.通 ...

  9. 洛谷P2482 [SDOI2010]猪国杀——题解

    猪国杀,模拟题的一颗耀眼的明珠,成长大牛.锻炼码力必写题! 模拟题没什么思维难度.只要按部就班地去做就是.模拟简单在这,难也在这.因为题面巨长,条件巨多,忽疏一点都有可能全盘皆输.故推荐考试时碰见了, ...

  10. Spring Boot教程(二十)开发Web应用(1)

    静态资源访问 在我们开发Web应用的时候,需要引用大量的js.css.图片等静态资源. 默认配置 Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则: /s ...