Redis-集群操作
一、查看集群状态
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-集群操作的更多相关文章
- golang redis集群操作:redis-go-cluster
背景 感觉redis-cli desktop及其难用,最近用golang做了个redis查询工具,支持单例和集群操作,终于不再卡顿!!! 用到的包 "github.com/garyburd/ ...
- Java连接redis集群操作存储、删除以及获取值
pom文件添加: <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> &l ...
- Redis集群操作手册
一.原始集群(6节点 3主3从): (1)启动集群: [root@bhz004 ~]# /usr/local/redis/bin/redis-server /usr/local/redis-clust ...
- 【Redis学习之十一】Java客户端实现redis集群操作
客户端:jedis-2.7.2.jar 配置文件两种方式: properties: redis.cluster.nodes1=192.168.1.117 redis.cluster.port1=700 ...
- Redis集群的使用测试(Jedis客户端的使用)
Redis集群的使用测试(Jedis客户端的使用)1.Jedis客户端建议升级到最新版(当前为2.7.3),这样对3.0.x集群有比较好的支持.https://github.com/xetorthio ...
- Dubbo入门到精通学习笔记(十五):Redis集群的安装(Redis3+CentOS)、Redis集群的高可用测试(含Jedis客户端的使用)、Redis集群的扩展测试
文章目录 Redis集群的安装(Redis3+CentOS) 参考文档 Redis 集群介绍.特性.规范等(可看提供的参考文档+视频解说) Redis 集群的安装(Redis3.0.3 + CentO ...
- Java Spring mvc 操作 Redis 及 Redis 集群
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5941953.html 关于 Redis 集群搭建可以参考我的另一篇文章 Redis集群搭建与简单使用 R ...
- 分布式缓存技术redis学习系列(四)——redis高级应用(集群搭建、集群分区原理、集群操作)
本文是redis学习系列的第四篇,前面我们学习了redis的数据结构和一些高级特性,点击下面链接可回看 <详细讲解redis数据结构(内存模型)以及常用命令> <redis高级应用( ...
- 分布式缓存技术redis学习(四)——redis高级应用(集群搭建、集群分区原理、集群操作)
本文是redis学习系列的第四篇,前面我们学习了redis的数据结构和一些高级特性,点击下面链接可回看 <详细讲解redis数据结构(内存模型)以及常用命令> <redis高级应用( ...
- java操作redis集群配置[可配置密码]和工具类(比较好用)
转: java操作redis集群配置[可配置密码]和工具类 java操作redis集群配置[可配置密码]和工具类 <dependency> <groupId>red ...
随机推荐
- 在vue下引入jquery bootstrap
在vue 项目中引入jquery bootstrap 引入jquery npm install jquery --save-dev 在项目根目录下的build/webpack.base.conf.js ...
- Python之网路编程之死锁,递归锁,信号量,Event事件,线程Queue
一.死锁现象与递归锁 进程也是有死锁的 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用, 它们都将无法推进下去.此时称系统处于死锁状态或系统 ...
- 【SpringBoot】spring-session-data-redis 解决集群环境下session共享
为什么会产生Session共享问题 集群情况下,session保存在各自的服务器的tomcat中,当分发地址至不同服务时,导致sesson取不到,就会产生session共享问题. 解决方案 负载均 ...
- 【leetcode】Path Sum IV
If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...
- PHP入门(四)
1.数组 1. array() 函数用于创建数组 在 PHP 中,有三种类型的数组:数值数组 - 带有数字 ID 键的数组 关联数组 - 带有指定的键的数组,每个键关联一个值 多维数组 - 包含一个或 ...
- MySQL教程-MyISAM和InnoDB的区别
MySQL的表类型MyISAM和InnoDB之间的最大区别是,InnoDB的支持事务.兄弟连教育( )来给大家做个对比: InnoDB支持一些新的功能:交易,行级锁,外键 InnoDB是高容量,高性能 ...
- 随机数:rand()
首先我们要对rand&srand有个总体的看法:srand初始化随机种子,rand产生随机数,下面将详细说明. rand(产生随机数) 表头文件: #include<stdlib ...
- Debian Buster升级后找不到声卡
昨天将Debian从Stretch升级到了新版巴斯光年(Buster).仍旧是先将source.list中的stretch替换为buster,再执行apt-get的update.upgrade.dis ...
- Kubernetes Deployment故障排除图解指南
个人K8s还在学习中,相关博客还没有写,准备学第二遍再开始学,发现这篇文章挺好,先转载一下. 原创: 白明的赞赏账户 下面是一个示意图,可帮助你调试Kubernetes Deployment(你可以 ...
- 洛谷P4208 [JSOI2008]最小生成树计数——题解
题目传送 前置知识:对于同一个图的所有最小生成树,权值相等的边的数量相同. 可以简单证明一下: 我们可以从kruskal的过程考虑.这个算法把所有边按权值大小从小到大排序,然后按顺序看每条边,只要加上 ...