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的使用的更多相关文章

  1. Redis进阶实践之十一 Redis的Cluster集群搭建

    一.引言      本文档只对Redis的Cluster集群做简单的介绍,并没有对分布式系统的详细概念做深入的探讨.本文只是提供了有关如何设置集群.测试和操作集群的说明,而不涉及Redis集群规范中涵 ...

  2. Redis进阶实践之十二 Redis的Cluster集群动态扩容

    一.引言     上一篇文章我们一步一步的教大家搭建了Redis的Cluster集群环境,形成了3个主节点和3个从节点的Cluster的环境.当然,大家可以使用 Cluster info 命令查看Cl ...

  3. Redis的Cluster配置

    Redis的Cluster配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装Redis并启动 1>.修改Redis的配置文件(本实验只有三个节点) [root@no ...

  4. Azure Redis Cache (5) Redis Cache Cluster集群模式

    <Windows Azure Platform 系列文章目录> Redis Cluster 3.0之后的版本,已经支持Redis Cluster集群模式,Redis Cluster采用无中 ...

  5. Redis搭建(七):Redis的Cluster集群动态增删节点

    一.引言 上一篇文章我们一步一步的教大家搭建了Redis的Cluster集群环境,形成了3个主节点和3个从节点的Cluster的环境.当然,大家可以使用 Cluster info 命令查看Cluste ...

  6. redis之(十七)自己实现redis的cluster集群环境的搭建

    [一]创建不同节点的配置文件和目录.并将配置文件中的port,cluster-enable,daemonize项做修改. --->port:修改成redis实例对应的端口号 --->clu ...

  7. Prometheus监控 Redis & Redis Cluster 说明

    说明 在前面的Prometheus + Grafana 部署说明之「安装」文章里,大致介绍说明了Prometheus和Grafana的一些安装使用,现在开始如何始部署Prometheus+Grafan ...

  8. 在执行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 ...

  9. [redis] Redis 配置文件置参数详解

    ################################ 基础配置 ################################# #daemonize no 默认情况下, redis 不 ...

  10. ServiceStack.Redis——Redis于.net向上client解

    ServiceStack.Redis--Redis于.net向上client解 源代码和使用: https://github.com/ServiceStack/ServiceStack.Redis 样 ...

随机推荐

  1. gogs docker 安装

     1.  gogs 镜像      docker pull gogs/gogs    2.  mysql    docker mysql    3.  本地数据卷配置 mkdir gogs & ...

  2. ORA-12154,TNS错误解决办法

  3. Python学习系列(四)(列表及其函数)

    Python学习系列(四)(列表及其函数) Python学习系列(一)(基础入门) Python学习系列(二)(基础知识) Python学习系列(三)(字符串) 一.基本概念 1,列表是什么?     ...

  4. BZOJ4755:[JSOI2016]扭动的回文串

    浅谈\(Manacher\):https://www.cnblogs.com/AKMer/p/10431603.html 题目传送门:https://lydsy.com/JudgeOnline/pro ...

  5. iptables防火墙工作原理

    iptables防火墙工作原理 简介:iptables防火墙工作在网络层,针对TCP/IP数据包实施过滤和限制,iptables防火墙基于内核编码实现,具有非常稳定的性能和高效率: iptables属 ...

  6. LVS+Keepalived搭建

    LVS+Keepalived搭建 原理说明 (推荐): http://www.cnblogs.com/likehua/archive/2014/06/19/3796849.html http://ou ...

  7. 如何查看自己的laravel版本

    方法1: 使用php artisan --version ,只要能看懂这个命令的人一定已经具有初步的Laravel知识.再介绍一种不需要命令,直接去文件中去查看的方法. 方法2: 在项目文件中找ven ...

  8. 中间件——Oracle Fusion Middleware

    Oracle Fusion Middleware定义: 什么是Oracle Fusion Middleware Oracle Fusion Middleware is a comprehensive ...

  9. 1117 Eddington Number

    题意:给出了N个数字,确定一个尽可能大的数字E,要求这N个数字中大于E的数字有E个. 思路: 乍一看不知道题目在说啥.静下心来多读几遍题目,在草稿纸上比划比划,发现是个大水题.解释一下样例,原始序列为 ...

  10. ecshop移动端支付宝支付对接

    初始页,提交基本信息到api页面, <?php /* * * 功能:支付宝手机网站支付接口接口调试入口页面 * 版本:3.4 * 修改日期:2016-03-08 * 说明: * 以下代码只是为了 ...