可以用下面的命令查看集群的状态,从下面可以看出有4个master,2个slave~~~,这个是由于我太年轻kill了7000的redis又加入了进来,原先他的slave 7003 也变成了master顶替了他。
[root@localhost src]# ./redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OK
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 4eb95ab689288dbb3ebf7ed380a0593ec9daa878 127.0.0.1:7000
slots: (0 slots) master
0 additional replica(s)
S: 11174332eb6ad40c0327750536fa776d706caf85 127.0.0.1:7005
slots: (0 slots) slave
replicates 5814305e71552ab45c44b9b8233681a63c3a57b1
M: e50676757acbe7c6a21e8abf4eda26ababb08285 127.0.0.1:7003
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: 5814305e71552ab45c44b9b8233681a63c3a57b1 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
M: d3058a19483d7be5c30c042779e56130f6ebf074 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: ab307ba26d6dabe8edb2f2a7287be6f01aa46d88 127.0.0.1:7004
slots: (0 slots) slave
replicates d3058a19483d7be5c30c042779e56130f6ebf074
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
可以进入redis中玩一玩:查了一下使用redis-cli命令的时候应该加上 -c ,意思是在集群模式下,否则你会以一种独立的redis进入,然后各种moved报错。
看着存储位置跳来跳去,貌似简单的集群也就搭建完成了。
[root@localhost src]# ./redis-cli -c -p 7000
127.0.0.1:7000> set linuxidc weikang
-> Redirected to slot [1357] located at 127.0.0.1:7003
OK
127.0.0.1:7003> set linuxidc qiang
OK
127.0.0.1:7003> set weikang linuxidc
-> Redirected to slot [12142] located at 127.0.0.1:7002
OK
127.0.0.1:7002> get linuxidc
-> Redirected to slot [1357] located at 127.0.0.1:7003
"linuxidc"
127.0.0.1:7003> get weikang
-> Redirected to slot [12142] located at 127.0.0.1:7002
"linuxidc"
4.遗留的一些问题:
(1)搭建的集群连接上客户端后,所有的redis只有db0可用,不知道是什么原因。(难道是互相之间只连接了db0吗?)
(2)增删改节点还有待继续研究,不能只是单纯的写命令就可以了,要理解在什么场景下应该做如何的处理。
(3)集群管理工具在redis 3.0之后自己出了一个叫做redis-sentinel的,这个需要着重研究。
只有在深入理解的集群的意义和所配置的每个参数的含义之后,才能使用到生产环境中,以上只是个入门,学习redis集群才只是刚刚开始~~
下面关于Redis的文章您也可能喜欢,不妨参考下:
Ubuntu 14.04下Redis安装及简单测试
Redis集群明细文档
Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis
CentOS 6.3安装Redis