[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 样 ...
随机推荐
- JavaScript 冒号(:)详解
1.switch语句分支 2.?:三元表达式的false 3.声明对象直接量的成员 4.声明标签 1和2相信地球人都知道吧?如果有人不知道,那我改成地球上的程序员都知道,哈哈 3.对象直接量我们也经常 ...
- ncdu 查找linux下最占空间的文件(交互式查询)
安装 wget -c https://dev.yorhel.nl/download/ncdu-1.11.tar.gz tar xzvf ncdu-1.11.tar.gz cd ncdu-1.11 ./ ...
- 微信小程序,请求php后台返回json数据多出隐藏字符问题
这几天在做一个微信小程序注册登录页面的时候碰到一个问题,就是使用wx.request api的时候success中返回的JSON数据前面会多出空白字符,后面网上查了一下是说php bom头问题(详细介 ...
- unittest之跳过用例(skip) (含如何调用类里面函数相互调取变量的方法)
当测试用例写完后,有些模块有改动时候,会影响到部分用例的执行,这个时候我们希望暂时跳过这些用例. 或者前面某个功能运行失败了,后面的几个用例是依赖于这个功能的用例,如果第一步就失败了,后面的用例也就没 ...
- 【转】学习使用Jmeter做压力测试(二)--压力测试的实施
JMeter测试步骤: 1.建立测试计划 2.添加线程组 3.添加HTTP请求 4.增加监听器 5.执行测试计划 6.根据JMeter提供的报告分析结果 一.目标 测试访问目标服务器网站首页的每秒查询 ...
- 分布式锁之二:zookeeper分布式锁2
示例: package com.util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.zoo ...
- PHP判断文件是否被引入的方法get_included_files
<?php // 本文件是 abc.php include 'test1.php'; include_once 'test2.php'; require 'test3.php'; require ...
- thinkphp线上自动加载异常与修复
项目遇到一个奇怪的问题,本地代码正常,服务器上却不正常. 经过测试,应该是自动加载出了问题,尝试了各种方法, 1.手动加载,发现好麻烦,没完没了. 2.自己写自动加载,写不出来,尴尬. 3.修改配置, ...
- Centos 6.5 安装Oracle 11g R2 on vbox
由于上一篇的rac安装,截图较多,这一篇选择以txt的方式叙述,另外上一篇的时间比较久远,这里最近从新安装 --2018-10-29 1 os环境初始化 [root@rac1 yum.repos.d] ...
- Java学习之SpringBoot整合SSM Demo
背景:在Java Web中Spring家族有着很重要的地位,之前JAVA开发需要做很多的配置,一堆的配置文件和部署调试一直是JavaWeb开发中的一大诟病,但现在Spring推出了SpringBoot ...