一、环境描述
DB:redis 3.2.5
OS:centos 6.6_x64
IP:192.168.80.131/132/133
PORT:7000
redis 集群模式,服务已启动
二、具体操作
1.三个独立的集群节点,每个集群只有自己一个节点
[root@mysql-131 ~]# 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>