redis 3.2.5 cluster 添加节点和指派槽位

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis 3.2.5 cluster 添加节点和指派槽位相关的知识,希望对你有一定的参考价值。

一、环境描述


DB:redis 3.2.5

OS:centos 6.6_x64


IP:192.168.80.131/132/133 

PORT:7000


redis 集群模式,服务已启动


二、具体操作


1.三个独立的集群节点,每个集群只有自己一个节点

[[email protected] ~]# redis-cli -c -p 7000

127.0.0.1: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:8

cluster_size:3

cluster_current_epoch:11

cluster_my_epoch:9

cluster_stats_messages_sent:156029

cluster_stats_messages_received:155663

127.0.0.1:7000> cluster reset


2.创建3节点集群

127.0.0.1:7000> cluster meet 192.168.80.132 7000

OK

127.0.0.1:7000> cluster meet 192.168.80.133 7000

OK

127.0.0.1:7000> cluster nodes

dd2dae9872c9eb58860c5fe0ae810e34fcbe4e83 192.168.80.132:7000 master - 0 1480991778893 2 connected

a03c14558ce425fd0fe64b611eb02fdb46db2fd4 192.168.80.133:7000 master - 0 1480991777891 11 connected

2591d73e867a298852f6e4e892ced37dac7c9034 192.168.80.131:7000 myself,master - 0 0 1 connected

127.0.0.1:7000> 


2.指派slots

192.168.80.131执行

#for i in {0..5000}

do

redis-cli -c -p 7000 cluster addslots $i 

done


192.168.80.132执行

#for i in {5001..10000}

do

redis-cli -c -p 7000 cluster addslots $i 

done


192.168.80.133执行

#for i in {10001..16383}

do

redis-cli -c -p 7000 cluster addslots $i 

done



3.查看集群状态ok

127.0.0.1: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:3

cluster_size:3

cluster_current_epoch:12

cluster_my_epoch:1

cluster_stats_messages_sent:187477

cluster_stats_messages_received:192003


127.0.0.1:7000> cluster slots

1) 1) (integer) 5001

   2) (integer) 10000

   3) 1) "192.168.80.132"

      2) (integer) 7000

      3) "dd2dae9872c9eb58860c5fe0ae810e34fcbe4e83"

2) 1) (integer) 10001

   2) (integer) 16383

   3) 1) "192.168.80.133"

      2) (integer) 7000

      3) "a03c14558ce425fd0fe64b611eb02fdb46db2fd4"

3) 1) (integer) 0

   2) (integer) 5000

   3) 1) "192.168.80.131"

      2) (integer) 7000

      3) "2591d73e867a298852f6e4e892ced37dac7c9034"

127.0.0.1:7000> 


4.验证写入

127.0.0.1:7000> set msg "hello world"

-> Redirected to slot [6257] located at 192.168.80.132:7000

OK

192.168.80.132:7000> cluster keyslot msg

(integer) 6257

192.168.80.132:7000> get msg

"hello world"

192.168.80.132:7000> 


本文出自 “dba003” 博客,请务必保留此出处http://dba003.blog.51cto.com/12318731/1880265

以上是关于redis 3.2.5 cluster 添加节点和指派槽位的主要内容,如果未能解决你的问题,请参考以下文章

Redis 5.0 cluster 添加和移除节点

redis cluster 添加 删除 重分配 节点

redis cluster中添加删除重分配节点例子

redis-cluster 添加密码设置

redis演练(10) redis Cluster 集群节点维护

第十二章 redis-cluster搭建(redis-3.2.5)