首页 / REDIS / Redis-集群操作
Redis-集群操作
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Redis-集群操作,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含7245字,纯文字阅读大概需要11分钟。
内容图文
![Redis-集群操作](/upload/InfoBanner/zyjiaocheng/1332/e9fb25c5d5ce43bfad4510ff4cce0572.jpg)
一、查看集群状态
1.查看集群状态
/opt/redis/src/redis-cli -h 本机IP -p redsi实例端口 -c #连接redis实例 /opt/redis/src/redis-cli -h 10.105.199.48 -p 7000 -c
10.105.199.48:7000> cluster info #查看集群状态
cluster_state:ok #ok表示集群正常
cluster_slots_assigned:16384 #已分配的槽
cluster_slots_ok:16384 #槽的状态是ok的数目
cluster_slots_pfail:0 #可能失效的槽的数目
cluster_slots_fail:0 #已经失效的槽的数目
cluster_known_nodes:6 #集群中节点个数
cluster_size:3 #集群中设置的分片个数
cluster_current_epoch:7 #集群中的currentEpoch总是一致的,currentEpoch越高,代表节点的配置或者操作越新,集群中最大的那个node epoch
cluster_my_epoch:2 #当前节点的config epoch,每个主节点都不同,一直递增, 其表示某节点最后一次变成主节点或获取新slot所有权的逻辑时间.
cluster_stats_messages_sent:337616 #
cluster_stats_messages_received:334496
2.查看节点信息
10.105.199.48:7000> cluster nodes #查看集群节点 88370db287d1a30e262167008e9ff60009c33628 10.105.199.48:7000 myself,slave 9b865041519484766bfa4b0d72f179f767c18091 001 connected e93cbc4a0f50b41b2384f582b73b33bb4e598bda 10.105.199.48:7005 slave 216694a6a93fdc2bb3231771d0fde5133e19c513 015226761449586 connected 216694a6a93fdc2bb3231771d0fde5133e19c513 10.105.199.48:7002 master - 015226761439553 connected 10923-16383 9b865041519484766bfa4b0d72f179f767c18091 10.105.199.48:7003 master - 015226761454587 connected 0-5460 7618157e849b73aeff856f05d4f9a9e860d30da2 10.105.199.48:7001 master - 015226761444572 connected 5461-10922 0ff033100f41af1f19f2faba600ae60affc47da8 10.105.199.48:7004 slave 7618157e849b73aeff856f05d4f9a9e860d30da2 015226761459605 connected #说明 节点ID:例如88370db287d1a30e262167008e9ff60009c33628 ip:port:节点的ip地址和端口号,例如10.105.199.48:7000 flags:节点的角色(master,slave,myself)以及状态(pfail,fail) 如果节点是一个从节点的话,那么跟在flags之后的将是主节点的节点ID,例如10.105.199.48:7000主节点的ID就是9b865041519484766bfa4b0d72f179f767c18091 集群最近一次向节点发送ping命令之后,过了多长时间还没接到回复 节点最近一次返回pong回复的时间 节点的配置纪元(config epoch) 本节点的网络连接情况 节点目前包含的槽,例如10.105.199.48:7002目前包含的槽为10923-16383
二、Redis集群操作
1.删除从节点
(1)删除从节点
/opt/redis/src/redis-trib.rb del-node 10.105.199.48:7005 e93cbc4a0f50b41b2384f582b73b33bb4e598bda #删除节点,使用“redis-trib.rb del-node IP:端口实例ID”
>>> Removing node e93cbc4a0f50b41b2384f582b73b33bb4e598bda from cluster 10.105.199.48:7005
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
(2)查看集群状态
# /opt/redis/src/redis-cli -h 10.105.199.48 -p 7000 -c
10.105.199.48:7000> cluster nodes
88370db287d1a30e262167008e9ff60009c33628 10.105.199.48:7000 myself,slave 9b865041519484766bfa4b0d72f179f767c18091 0 0 1 connected
216694a6a93fdc2bb3231771d0fde5133e19c513 10.105.199.48:7002 master - 0 1522676241162 3 connected 10923-16383
9b865041519484766bfa4b0d72f179f767c18091 10.105.199.48:7003 master - 0 1522676240661 7 connected 0-5460
7618157e849b73aeff856f05d4f9a9e860d30da2 10.105.199.48:7001 master - 0 1522676242165 2 connected 5461-10922
0ff033100f41af1f19f2faba600ae60affc47da8 10.105.199.48:7004 slave 7618157e849b73aeff856f05d4f9a9e860d30da2 0 1522676241664 5 connected
(3)查看节点状态
10.105.199.48:7000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:5 #发现少了一个节点
cluster_size:3
cluster_current_epoch:7
cluster_my_epoch:7
cluster_stats_messages_sent:5281
cluster_stats_messages_received:4448
2.删除主节点
(1)重新分配槽,将想删除的主节点槽重新分配为0 # /opt/redis/src/redis-trib.rb reshard 10.105.199.48:7000 >>> Performing Cluster Check (using node 10.105.199.48:7000) M: b1b5a9fa3ff177094cea730c2a63e2c185174af7 10.105.199.48:7000 slots:0-8079,8192-12175,12288-13827,13980-16271 (15896 slots) master 0 additional replica(s) M: ca016bd0b77820183a593658b2f7f15af5f9a30c 10.105.199.48:7004 slots:13828-13979 (152 slots) master 0 additional replica(s) M: bb8455d0387419acbb500bcb73b93036d5776c5b 10.105.199.48:7002 slots:12176-12287 (112 slots) master 0 additional replica(s) M: 596bf938bb2e02a233e7f8c112b143434aa6ddc1 10.105.199.48:7001 slots:8080-8191 (112 slots) master 0 additional replica(s) M: dc241e88be395bdc224bcfb11a111b9d9b0a9cfc 10.105.199.48:7003 slots:16272-16383 (112 slots) master 0 additional replica(s) [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)? 8192 #这个个数就是这个实例分配的槽数 What is the receiving node ID? bb8455d0387419acbb500bcb73b93036d5776c5b #输入接收内存槽的实例ID 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:all #输入all Do you want to proceed with the proposed reshard plan (yes/no)? yes #输入yes
(2)删除节点
# /opt/redis/src/redis-trib.rb del-node 10.105.199.48:7000 b1b5a9fa3ff177094cea730c2a63e2c185174af7
>>> Removing node b1b5a9fa3ff177094cea730c2a63e2c185174af7 from cluster 10.105.199.48:7000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
3.添加主节点
(1)添加节点
# /opt/redis/src/redis-trib.rb add-node 10.105.199.48:700510.105.199.48:7001 #redis-trib.rb add-node 新节点IP:端口 已有节点IP:端口 >>> Adding node 10.105.199.48:7005 to cluster 10.105.199.48:7001 >>> Performing Cluster Check (using node 10.105.199.48:7001) M: 596bf938bb2e02a233e7f8c112b143434aa6ddc1 10.105.199.48:7001 slots: (0 slots) master 0 additional replica(s) M: ca016bd0b77820183a593658b2f7f15af5f9a30c 10.105.199.48:7004 slots: (0 slots) master 0 additional replica(s) M: dc241e88be395bdc224bcfb11a111b9d9b0a9cfc 10.105.199.48:7003 slots:0-16383 (16384 slots) master 0 additional replica(s) M: bb8455d0387419acbb500bcb73b93036d5776c5b 10.105.199.48:7002 slots: (0 slots) master 0 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 10.105.199.48:7005 to make it join the cluster. [OK] New node added correctly.
(2)重新分配内存槽
# /opt/redis/src/redis-trib.rb reshard 10.105.199.48:7005
>>> Performing Cluster Check (using node 10.105.199.48:7005)
M: 77f2256c607d67705ad456fb0460ffef116409b4 10.105.199.48:7005
slots: (0 slots) master
0 additional replica(s)
M: bb8455d0387419acbb500bcb73b93036d5776c5b 10.105.199.48:7002
slots: (0 slots) master
0 additional replica(s)
M: ca016bd0b77820183a593658b2f7f15af5f9a30c 10.105.199.48:7004
slots: (0 slots) master
0 additional replica(s)
M: b1b5a9fa3ff177094cea730c2a63e2c185174af7 10.105.199.48:7000
slots: (0 slots) master
0 additional replica(s)
M: dc241e88be395bdc224bcfb11a111b9d9b0a9cfc 10.105.199.48:7003
slots:0-16383 (16384 slots) master
0 additional replica(s)
M: 596bf938bb2e02a233e7f8c112b143434aa6ddc1 10.105.199.48:7001
slots: (0 slots) master
0 additional replica(s)
[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)? 3276 #分配的槽数
What is the receiving node ID? 77f2256c607d67705ad456fb0460ffef116409b4 #新节点ID
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:all #all #输入all
Do you want to proceed with the proposed reshard plan (yes/no)?yes #输入yes
原文:https://www.cnblogs.com/dingkailinux/p/8698520.html
内容总结
以上是互联网集市为您收集整理的Redis-集群操作全部内容,希望文章能够帮你解决Redis-集群操作所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。