[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 样 ...
随机推荐
- WPF简单模拟QQ登录背景动画(转)
介绍 之所以说是简单模拟,是因为我不知道QQ登录背景动画是怎么实现的.这里是通过一些办法把它简化了,做成了类似的效果 效果图 大体思路 首先把背景看成是一个4行8列的点的阵距,X轴Y轴都是距离70.把 ...
- Python reload() 函数
reload(module) 作用: 用于重新载入之前载入的模块. module -- 模块对象.返回模块对象. 实例: 重新载入 sys 模块,并设置默认编码为 utf8 >>> ...
- log框架集成
使用slf4j,slf4j相当于一个接口,我们面对接口编程,方便地集成其他的日志框架,我们按照slf4j的标准,日志就会相应地打入日志系统中(log4j 使用slf4j要有两个包1,他本身的api,2 ...
- 一键获取 所有连接过的WIFI密码
使用方法 一.运行CMD (以及 开启无线网卡.最好是笔记本) 二.输入命令: for /f "skip=9 tokens=1,2 delims=:" %i in ('netsh ...
- Linux环境下安装XAMPP的PHP的PDF扩展
安装pdf扩展1. wget http://pecl.php.net/get/pdflib-4.1.2.tgz2. tar zxvf pdflib-4.1.2.tgz3. cd pdflib-4.1. ...
- Office 2019 2016 安装破解教程
声明:工具由蓝点网提供支持,密钥为本人收集内容,非转载部分 GVLKs for Office 2019 Product GVLK Office Professional Plus 2019 ...
- dd命令的高级应用
dd是Linux上的一个常用的命令.例如:dd if=/1.txt of=/tmp/2.txt (其中, if代表input file:of代表output file, 命令的结果就是将根目录 ...
- Three.js加载gltf模型
效果图 demo import './index.css'; var stats; stats = new Stats(); document.body.appendChild( stats.dom ...
- windows右键打开方式里面添加新的应用程序
1.打开注册表编辑器.打开运行窗口,快捷键,开始+R.输入“regedit”,回车确定. 2.进入注册表编辑器的HKEY_CLASSES_ROOT文件夹下的*子文件夹下的shell文件夹. 3.右键s ...
- 将Maven项目打包成可执行 jar文件(引用第三方jar)
使用maven assembly插件完成打包 修改pom: <build> <pluginManagement> <plugins> <!--设置jdk版本, ...