[redis]redis-cluster的使用
1、为集群添加一个主节点
首先准备一个全新的redis文件夹,这里我们叫做为7007
[root@CentOS7 redis-cluster]# ls
[root@CentOS7 redis-cluster]# tree ├── redis-benchmark
├── redis-check-aof
├── redis-check-dump
├── redis-cli
├── redis.conf
├── redis-sentinel
└── redis-server
启动7007的redis,然后添加7007的节点
[root@CentOS7 ~]# cd /usr/local/redis-cluster/7007
[root@CentOS7 7007]# ./redis-server redis.conf
[root@CentOS7 redis-cluster]# ./redis-trib.rb add-node 192.168.133.159: 192.168.133.159:
这个时候在集群里其实已经可以但看7007的节点了
[root@CentOS7 ]# ./redis-cli -h 192.168.133.159 -p
192.168.133.159:> CLUSTER nodes
50e36c10b731d536fcf35d0478b20c6671ed3116 192.168.133.159: slave ee1d1cfbd7385893ababb0342329a55644734f4c connected
b40a94dee3200f716e8f628060348296b37952d1 192.168.133.159: master - connected -
93d1ef27a47b5e830e2f1fdce9bdaeac6ce7689d 192.168.133.159: slave b40a94dee3200f716e8f628060348296b37952d1 connected
ee1d1cfbd7385893ababb0342329a55644734f4c 192.168.133.159: myself,master - connected -
8ca1250d01509febbedc14748069ea130fdf2b76 192.168.133.159: master - connected
4e1ca9e4d966776c0ec1c37ab12e90315baef857 192.168.133.159: slave dd05edc6f7544f502c666d9b416a4063987bdbe9 connected
dd05edc6f7544f502c666d9b416a4063987bdbe9 192.168.133.159: master - connected -
但它还没有生效,因为redis的集群是对“槽“的操作,所以对于新加的节点,需要进行”槽“的再分配
[root@CentOS7 redis-cluster]# ./redis-trib.rb reshard 192.168.133.159:
比如我们这里先分配1000个槽
How many slots do you want to move (from to )?
然后输入接收点的ID
What is the receiving node ID? 8ca1250d01509febbedc14748069ea130fdf2b76
这个ID其实是通过cluster nodes的redis命令进行但看到的
最后输入源结点id
输入源结点id
,槽将从源结点中拿,分配后的槽在源结点中就不存在了。
输入all
表示从所有源结点中获取槽。
输入done
取消分配。
Source node #:all
以下就日志信息
Ready to move slots.
Source nodes:
M: ee1d1cfbd7385893ababb0342329a55644734f4c 192.168.133.159:
slots:- ( slots) master
additional replica(s)
M: b40a94dee3200f716e8f628060348296b37952d1 192.168.133.159:
slots:- ( slots) master
additional replica(s)
M: dd05edc6f7544f502c666d9b416a4063987bdbe9 192.168.133.159:
slots:- ( slots) master
additional replica(s)
Destination node:
M: 8ca1250d01509febbedc14748069ea130fdf2b76 192.168.133.159:
slots: ( slots) master
additional replica(s)
Resharding plan:
Moving slot from dd05edc6f7544f502c666d9b416a4063987bdbe9
。。。
2、为集群添加一个从节点,用它来做为7007的从节点
创建一个7008的目录,然后启动7008的进程,然后添加从节点
[root@CentOS7 ]# cd ../redis-trib.rb add-node --slave --master-id 8ca1250d01509febbedc14748069ea130fdf2b76 192.168.133.159:7008 192.168.133.159:7001
这样就完成了从节点的添加
192.168.133.159:> CLUSTER nodes
912b8dd1c7f35866ac15b263248ee729af7171e3 192.168.133.159: slave 8ca1250d01509febbedc14748069ea130fdf2b76 connected
50e36c10b731d536fcf35d0478b20c6671ed3116 192.168.133.159: slave ee1d1cfbd7385893ababb0342329a55644734f4c connected
b40a94dee3200f716e8f628060348296b37952d1 192.168.133.159: master - connected -
93d1ef27a47b5e830e2f1fdce9bdaeac6ce7689d 192.168.133.159: slave b40a94dee3200f716e8f628060348296b37952d1 connected
ee1d1cfbd7385893ababb0342329a55644734f4c 192.168.133.159: myself,master - connected -
8ca1250d01509febbedc14748069ea130fdf2b76 192.168.133.159: master - connected - - -
4e1ca9e4d966776c0ec1c37ab12e90315baef857 192.168.133.159: slave dd05edc6f7544f502c666d9b416a4063987bdbe9 connected
dd05edc6f7544f502c666d9b416a4063987bdbe9 192.168.133.159: master - connected -
3、删除一个主节点
[root@CentOS7 redis-cluster]# ./redis-trib.rb del-node 192.168.133.159: 8ca1250d01509febbedc14748069ea130fdf2b76
>>> Removing node 8ca1250d01509febbedc14748069ea130fdf2b76 from cluster 192.168.133.159:
[ERR] Node 192.168.133.159: is not empty! Reshard data away and try again.
已经占有hash槽的节点会删除失败,需要先将hash槽分配出去
首先、使用客户端连接集群后移动哈希槽,执行命令:
[root@CentOS7 redis-cluster]# ./redis-trib.rb reshard 192.168.133.159:
系统会提示我们移动多少个哈希槽,这里输入1000,因为当时我们就给7007设置了1000个哈希槽
How many slots do you want to move (from to )?
系统会提示我们接收者的ID,我们这里将这些哈希槽还给7001
What is the receiving node ID? ee1d1cfbd7385893ababb0342329a55644734f4c
系统会提示我们输入转出者的ID,最后输入done即可
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 #:8ca1250d01509febbedc14748069ea130fdf2b76
Source node #:done
系统日志:
Ready to move slots.
Source nodes:
M: 8ca1250d01509febbedc14748069ea130fdf2b76 192.168.133.159:
slots:-,-,- ( slots) master
additional replica(s)
Destination node:
M: ee1d1cfbd7385893ababb0342329a55644734f4c 192.168.133.159:
slots:- ( slots) master
additional replica(s)
Resharding plan:
Moving slot from 8ca1250d01509febbedc14748069ea130fdf2b76
日志省略了一大片,最后执行删除的步骤,删除7007的ID
[root@CentOS7 redis-cluster]# ./redis-trib.rb del-node 192.168.133.159: 8ca1250d01509febbedc14748069ea130fdf2b76
看到日志:
>>> Removing node 8ca1250d01509febbedc14748069ea130fdf2b76 from cluster 192.168.133.159:
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
4、删除一个从节点
[root@CentOS7 redis-cluster]# ./redis-trib.rb del-node 192.168.133.159: 912b8dd1c7f35866ac15b263248ee729af7171e3
>>> Removing node 912b8dd1c7f35866ac15b263248ee729af7171e3 from cluster 192.168.133.159:
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
5、使用客户端连接redis,一定要加-c参数,这样节点之前就可以互相跳转
[root@CentOS7 bin]# ./redis-cli -p -c
127.0.0.1:> KEYS *
(empty list or set)
127.0.0.1:> set a
-> Redirected to slot [] located at 192.168.133.159:
OK
192.168.133.159:> set b
-> Redirected to slot [] located at 192.168.133.159:
OK
192.168.133.159:> seb c
(error) ERR unknown command 'seb'
192.168.133.159:> set c
-> Redirected to slot [] located at 192.168.133.159:
OK
192.168.133.159:> get a
-> Redirected to slot [] located at 192.168.133.159:
""
192.168.133.159:> get b
-> Redirected to slot [] located at 192.168.133.159:
""
192.168.133.159:> get c
-> Redirected to slot [] located at 192.168.133.159:
""
[redis]redis-cluster的使用的更多相关文章
- Redis进阶实践之十一 Redis的Cluster集群搭建
一.引言 本文档只对Redis的Cluster集群做简单的介绍,并没有对分布式系统的详细概念做深入的探讨.本文只是提供了有关如何设置集群.测试和操作集群的说明,而不涉及Redis集群规范中涵 ...
- Redis进阶实践之十二 Redis的Cluster集群动态扩容
一.引言 上一篇文章我们一步一步的教大家搭建了Redis的Cluster集群环境,形成了3个主节点和3个从节点的Cluster的环境.当然,大家可以使用 Cluster info 命令查看Cl ...
- Redis的Cluster配置
Redis的Cluster配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装Redis并启动 1>.修改Redis的配置文件(本实验只有三个节点) [root@no ...
- Azure Redis Cache (5) Redis Cache Cluster集群模式
<Windows Azure Platform 系列文章目录> Redis Cluster 3.0之后的版本,已经支持Redis Cluster集群模式,Redis Cluster采用无中 ...
- Redis搭建(七):Redis的Cluster集群动态增删节点
一.引言 上一篇文章我们一步一步的教大家搭建了Redis的Cluster集群环境,形成了3个主节点和3个从节点的Cluster的环境.当然,大家可以使用 Cluster info 命令查看Cluste ...
- redis之(十七)自己实现redis的cluster集群环境的搭建
[一]创建不同节点的配置文件和目录.并将配置文件中的port,cluster-enable,daemonize项做修改. --->port:修改成redis实例对应的端口号 --->clu ...
- Prometheus监控 Redis & Redis Cluster 说明
说明 在前面的Prometheus + Grafana 部署说明之「安装」文章里,大致介绍说明了Prometheus和Grafana的一些安装使用,现在开始如何始部署Prometheus+Grafan ...
- 在执行gem install redis时 : ERROR: Error installing redis: redis requires Ruby version >= 2.2.2
在执行gem install redis时 提示: gem install redis ERROR: Error installing redis: redis requires Ruby versi ...
- [redis] Redis 配置文件置参数详解
################################ 基础配置 ################################# #daemonize no 默认情况下, redis 不 ...
- ServiceStack.Redis——Redis于.net向上client解
ServiceStack.Redis--Redis于.net向上client解 源代码和使用: https://github.com/ServiceStack/ServiceStack.Redis 样 ...
随机推荐
- 一分钟理解js闭包
什么是闭包?先看一段代码: ? 1 2 3 4 5 6 7 8 9 10 function a(){ var n = 0; function inc() { n++; cons ...
- 为什么新生代内存需要有两个Survivor区?
对于常见的GC算法,我们都应该知道,例如:标记清除算法.复制算法.标记整理算法等.标记清除算法由于回收之后存在大量的内存碎片,存在效率和空间问题!为了解决效率问题,引出了复制算法!熟悉GC算法的小伙伴 ...
- 管理11gRAC基本命令 (转载) 很详细
在 Oracle Clusterware 11g 第 2 版 (11.2) 中,有许多子程序和命令已不再使用: crs_stat crs_register crs_unregiste ...
- 【Python学习笔记】在OSX下搭建opencv+python环境
https://jjyap.wordpress.com/2014/05/24/installing-opencv-2-4-9-on-mac-osx-with-python-support/ 参照以上b ...
- delphi2010多线程编程教程
多线程编程(1) - 先入门再说. 多线程应该是编程工作者的基础技能, 但这个基础对我来讲的确有点难(起码昨天以前是这样). 开始本应该是一篇洋洋洒洒的文字, 不过我还是提倡先做起来, 在尝试中去理解 ...
- 苹果手机 iTunes 资料备份到另一手机
百度教程 https://jingyan.baidu.com/article/d621e8da332e602865913f8e.html 直接使用iTunes将老手机的资料备份, (可能需要关闭手机定 ...
- About CoffeeScript
本篇文章是对CoffeeScript做一个初步的了解.入门的学习笔记. 什么是CoffeeScript 一种新编程语言,是一套JavaScript的转译语言,可编译成高效的JavaScript.还可以 ...
- PL/SQL 训练06--字符串处理
现在需要做一个任务调度,请大家设计,满足以下需求(1)任务可配置,比如可以配置PKG方法TEST_PROCEDURE(:1,:2...),可以是任意多个入参的方法,也可以没有入参(2)每个方法的实际参 ...
- 子域名扫描器 - aquatone
项目地址:https://github.com/michenriksen/aquatone git clone,然后打开 ┌─[root@sch01ar]─[/sch01ar] └──╼ #git c ...
- 用python40行代码编写的计算器
效果图 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...