redis节点管理-新增主节点
原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg11.html
集群节点添加
节点新增包括新增主节点、从节点两种情况。以下分别做一下测试:
1、新增主节点
新增一个节点7007作为主节点修改配置文件
- [root@localhost redis-cluster]# cp -r redis01 redis07
- [root@localhost redis-cluster]# cd redis07/
- [root@localhost redis07]# sed -i "s/7001/7007/g" ./redis.conf
启动7007redis服务
- [root@localhost redis07]# ./redis-server redis.conf
- [root@localhost redis07]# netstat -anp | grep 7007
- tcp 0 0 127.0.0.1:17007 0.0.0.0:* LISTEN 13441/./redis-serve
- tcp 0 0 127.0.0.1:7007 0.0.0.0:* LISTEN 13441/./redis-serve
- [root@localhost redis07]#
上面可以看到,7007已经启动,现在加入集群中。添加使用redis-trib.rb的add-node命令
- ./redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7002
add-node是加入集群节点,127.0.0.1:7007为要加入的节点,127.0.0.1:7002 表示加入的集群的一个节点,用来辨识是哪个集群,理论上那个集群的节点都可以。
执行以下add-node
- [root@localhost redis-cluster]# ./redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7002
- >>> Adding node 127.0.0.1:7007 to cluster 127.0.0.1:7002
- >>> Performing Cluster Check (using node 127.0.0.1:7002)
- S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
- slots: (0 slots) slave
- replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
- M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
- slots:10923-16383 (5461 slots) master
- 1 additional replica(s)
- M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
- slots:5461-10922 (5462 slots) master
- 1 additional replica(s)
- S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004
- slots: (0 slots) slave
- replicates dd19221c404fb2fc4da37229de56bab755c76f2b
- S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
- slots: (0 slots) slave
- replicates f9886c71e98a53270f7fda961e1c5f730382d48f
- M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001
- slots:0-5460 (5461 slots) master
- 1 additional replica(s)
- [OK] All nodes agree about slots configuration.
- >>> Check for open slots...
- >>> Check slots coverage...
- [OK] All 16384 slots covered.
- >>> Send CLUSTER MEET to node 127.0.0.1:7007 to make it join the cluster.
- [OK] New node added correctly.
- [root@localhost redis-cluster]#
可以看到7007加入这个Cluster,并成为一个新的节点。
可以check以下7007节点状态
- [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7007
- >>> Performing Cluster Check (using node 127.0.0.1:7007)
- M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
- slots: (0 slots) master
- 0 additional replica(s)
- S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
- slots: (0 slots) slave
- replicates f9886c71e98a53270f7fda961e1c5f730382d48f
- M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001
- slots:0-5460 (5461 slots) master
- 1 additional replica(s)
- M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
- slots:10923-16383 (5461 slots) master
- 1 additional replica(s)
- S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
- slots: (0 slots) slave
- replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
- M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
- slots:5461-10922 (5462 slots) master
- 1 additional replica(s)
- S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004
- slots: (0 slots) slave
- replicates dd19221c404fb2fc4da37229de56bab755c76f2b
- [OK] All nodes agree about slots configuration.
- >>> Check for open slots...
- >>> Check slots coverage...
- [OK] All 16384 slots covered.
- [root@localhost redis-cluster]#
M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
slots: (0 slots) master
0 additional replica(s)
上面信息可以看到有4个M节点,3个S节点,7007成为了M主节点,它没有附属的从节点,而且Cluster并未给7007分配哈希卡槽(0 slots)。
可以从客户端连接集群查看一下,集群节点的连接情况
- [root@localhost redis-cluster]# cd redis07/
- [root@localhost redis07]# ./redis-cli -c -p 7007
- 127.0.0.1:7007> cluster nodes
- 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006 slave f9886c71e98a53270f7fda961e1c5f730382d48f 0 1462955393326 3 connected
- dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001 master - 0 1462955388247 1 connected 0-5460
- ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007 myself,master - 0 0 0 connected
- f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003 master - 0 1462955390270 3 connected 10923-16383
- 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002 slave a5db243087d8bd423b9285fa8513eddee9bb59a6 0 1462955394334 7 connected
- a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005 master - 0 1462955392309 7 connected 5461-10922
- 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004 slave dd19221c404fb2fc4da37229de56bab755c76f2b 0 1462955389663 1 connected
- 127.0.0.1:7007>
redis-cluster在新增节点时并未分配卡槽,需要我们手动对集群进行重新分片迁移数据,需要重新分片命令 reshard
redis-trib.rb reshard 127.0.0.1:7005
这个命令是用来迁移slot节点的,后面的127.0.0.1:7005是表示是哪个集群,端口填[7000-7007]都可以,执行结果如下:
- [root@localhost redis-cluster]# ./redis-trib.rb reshard 127.0.0.1:7005
- >>> Performing Cluster Check (using node 127.0.0.1:7005)
- M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
- slots:5461-10922 (5462 slots) master
- 1 additional replica(s)
- S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004
- slots: (0 slots) slave
- replicates dd19221c404fb2fc4da37229de56bab755c76f2b
- M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
- slots:10923-16383 (5461 slots) master
- 1 additional replica(s)
- S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
- slots: (0 slots) slave
- replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
- M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
- slots: (0 slots) master
- 0 additional replica(s)
- M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001
- slots:0-5460 (5461 slots) master
- 1 additional replica(s)
- S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
- slots: (0 slots) slave
- replicates f9886c71e98a53270f7fda961e1c5f730382d48f
- [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)?
它提示我们需要迁移多少slot到7007上,我们平分16384个哈希槽给4个节点:16384/4 = 4096,我们需要移动4096个槽点到7007上。
- [OK] All 16384 slots covered.
- How many slots do you want to move (from 1 to 16384)? 4096
- What is the receiving node ID?
需要输入7007的节点id,ee3efb90e5ac0725f15238a64fc60a18a71205d7
- 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:
redis-trib 会向你询问重新分片的源节点(source node),即,要从特点的哪个节点中取出 4096 个哈希槽,还是从全部节点提取4096个哈希槽, 并将这些槽移动到7007节点上面。
如果我们不打算从特定的节点上取出指定数量的哈希槽,那么可以向redis-trib输入 all,这样的话, 集群中的所有主节点都会成为源节点,redis-trib从各个源节点中各取出一部分哈希槽,凑够4096个,然后移动到7007节点上:
- Source node #1:all
然后开始从别的主节点迁移哈希槽,并且确认。
- Moving slot 1343 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1344 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1345 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1346 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1347 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1348 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1349 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1350 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1351 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1352 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1353 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1354 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1355 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1356 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1357 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1358 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1359 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1360 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1361 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1362 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1363 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Moving slot 1364 from dd19221c404fb2fc4da37229de56bab755c76f2b
- Do you want to proceed with the proposed reshard plan (yes/no)? yes
确认之后,redis-trib就开始执行分片操作,将哈希槽一个一个从源主节点移动到7007目标主节点。
重新分片结束后我们可以check以下节点的分配情况。
- [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7001
- >>> Performing Cluster Check (using node 127.0.0.1:7001)
- M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001
- slots:1365-5460 (4096 slots) master
- 1 additional replica(s)
- M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
- slots:0-1364,5461-6826,10923-12287 (4096 slots) master
- 0 additional replica(s)
- M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
- slots:6827-10922 (4096 slots) master
- 1 additional replica(s)
- S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
- slots: (0 slots) slave
- replicates f9886c71e98a53270f7fda961e1c5f730382d48f
- M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
- slots:12288-16383 (4096 slots) master
- 1 additional replica(s)
- S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
- slots: (0 slots) slave
- replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
- S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004
- slots: (0 slots) slave
- replicates dd19221c404fb2fc4da37229de56bab755c76f2b
- [OK] All nodes agree about slots configuration.
- >>> Check for open slots...
- >>> Check slots coverage...
- [OK] All 16384 slots covered.
- [root@localhost redis-cluster]#
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
可以看到7007节点分片的哈希槽片不是连续的,间隔的移动。
- [root@localhost redis-cluster]# cd redis07/
- [root@localhost redis07]# ./redis-cli -c 7007
- Could not connect to Redis at 127.0.0.1:6379: Connection refused
- [root@localhost redis07]# ./redis-cli -c -p 7007
- 127.0.0.1:7007> keys *
- 1) "name"
- 2) "age"
- 127.0.0.1:7007>
- 127.0.0.1:7007>
可以看到将7001的age[741]和name[5798]移动到7007节点上,
主节点7007添加成功。
redis节点管理-新增主节点的更多相关文章
- redis节点管理-新增从节点
原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg12.html 新增从节点 新增一个节点7008节点,使用add-node --slave命令. [pl ...
- redis节点管理-节点的移除
原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg13.html 节点的移除 和节点添加一样,移除节点也有移除主节点,从节点. 1.移除主节点 移除节点使 ...
- 编译安装redis之快速增加redis节点
#: 下载安装包 [root@localhost ~]# wget http://download.redis.io/releases/redis-4.0.14.tar.gz #:解压 [root@l ...
- redis 集群新增节点,slots槽分配,删除节点, [ERR] Calling MIGRATE ERR Syntax error, try CLIENT (LIST | KILL | GET...
redis reshard 重新分槽(slots) https://github.com/antirez/redis/issues/5029 redis 官方已确认该bug redis 集群重新(re ...
- Redis客户端管理
1.客户端管理 Redis提供了客户端相关API对其状态进行监控和管理,本节将深入介绍各个API的使用方法以及在开发运维中可能遇到的问题. 1.1 客户端API 1.client list clien ...
- redis的管理工具
phpredisadmin工具 rdbtools管理工具 saltstack管理redis 通过codis完成redis管理 一:phpredisadmin工具:类似于mysqladmin管理mysq ...
- redis cluster管理工具redis-trib.rb详解
redis cluster管理工具redis-trib.rb详解 来源 http://weizijun.cn/2016/01/08/redis%20cluster%E7%AE%A1%E7%90%86% ...
- cachecloud:Redis云管理平台
https://github.com/sohutv/cachecloud 一.CacheCloud是做什么的 CacheCloud提供一个Redis云管理平台:实现多种类型(Redis Standal ...
- element-ui组件,全选树节点,新增数据子节点数据,出现回填问题
案情分析:全选后父节点被选中保存,在这个树节点下新增数据时,就会出现,也被选中,事实上数据是没有被选中,也就意味着权限未被配置,而显示是已经配置了,显然这个是一个bug 1.处理前,直接用下面的方法很 ...
随机推荐
- 怎么快速入门一个老的java项目
作者:eilen著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1.有文档肯定先看文档,先看设计文档,产品的.技术的设计文档,接口文档写的好的可以看看,要是写的不好不着急看. 2 ...
- iframe自适应高度的方法
不带边框的iframe因为能和网页无缝的结合从而不刷新新页面的情况下实现更新页面部分的数据成为可能,可是iframe却不像层那样可以收缩自如,iframe高度需要动态的调整需要JS来配合使用,只能通过 ...
- servlet为什么要配置web.xml
(1).为Servlet命名: <servlet> <servlet-name>servlet1</servlet-name> <- 这是用于,在serv ...
- DateTimeToUnix/UnixToDateTime 对接时间转换
问题,通过毫秒数来解析出时间:(很多对接的时候经常需要用到) <?php $MyJson = '{"jingdong_vas_subscribe_get_responce": ...
- Django视图之ORM数据库查询操作API
查询表记录 查询相关API 操作:models.表名.objects.方法() all(): 查询所有结果 filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 get(**kwar ...
- java入门概念梳理总结
Java入门学习 简介 public class HelloWorld { public static void main(String []args) { System.out.println(&q ...
- 使用python获取网易云音乐无损音频教程
博客园主页:http://www.cnblogs.com/handoing/ github项目:https://github.com/handoing/get-163-music 环境:Python ...
- 封装CSS动画
写在前面:感谢腾讯课堂与妙味课堂的移动端公开课 对于需要设置动画的元素需要提前设置css()样式,这样数据才会被记录起来. function css(ele, attr, val) { if (/ro ...
- 解决lazarus 多线程报错问题
很多人都在Windows中使用线程技术,然后同样的代码移植到Linux下一运行就出错.一开始不解其中的奥妙.既然Lazarus提供了TThread类,也没注明非要在Windows下使用.没道理在Lin ...
- 最小生成树算法详解(prim+kruskal)
最小生成树概念: 一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的最少的边. 最小生成树可以用kruskal(克鲁斯卡尔)算法或prim(普里 ...