【redis】redis集群配置小结

--------2013/12/24

配了大半天的redis集群,居然还没有成功。一开始看起来挺顺利的,依着教程(Redis 命令参考 Release2.8-huangz),先是下载最新版本redis(https://github.com/antirez/redis,不是release版本,还在开发阶段),编译之后生成可执行文件redis-server。

然后创建监听不同端口的redis实例,一共开了6个端口,7000至7005。最后在运行命令,把各个实例连接通讯成为集群时(3个主节点,3个从节点)时,报了这个错误:

root@XIAOMO:/opt/cluster_test/redis-unstable/src# src/redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis (LoadError)
	from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
	from /opt/cluster_test/redis-unstable/src/redis-trib.rb:25:in `<main>'

ruby重新安装了几遍,redis环境变量也改了,似乎还是没有解决问题。这种问题一般都是版本不对或是环境变量没配好引起的;从错误输出看来,像是redis配置的问题。查阅了大部分论坛,也还没找到一个有效的方案,只能等到明天继续折腾了。

也希望有人帮忙指点一下啦~~


--------2013/12/25

折腾了这么久,原来是没装redis的第三方接口!既然ruby程序要访问redis数据库,总得有个连接接口。对于ruby这么安装client包就行了:

root@XIAOMO:~# gem install redis
Fetching: redis-3.0.6.gem (100%)
Successfully installed redis-3.0.6
1 gem installed
Installing ri documentation for redis-3.0.6...
Installing RDoc documentation for redis-3.0.6...
root@XIAOMO:~# 
安装成功后,集群最后一步搭建也就可以继续了:

root@XIAOMO:/cluster_test/redis-unstable/src# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
>>> Creating cluster
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7000 replica #1 is 127.0.0.1:7003
127.0.0.1:7001 replica #1 is 127.0.0.1:7004
127.0.0.1:7002 replica #1 is 127.0.0.1:7005
M: fc65c271d01fd2151da15f08d7af14e2be8c18c2 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: 5b487aa64fee6fd2322d16a3fd1633944bab58f2 127.0.0.1:7001
   slots:5461-10921 (5461 slots) master
M: 2e9be1c7a4af976d678ef26a91dda37c1623d445 127.0.0.1:7002
   slots:10922-16383 (5462 slots) master
S: a8cdcf9756b2e8334c28190d8de95375551c6a8a 127.0.0.1:7003
S: e4f044404413eb1dddef513500beca1e554e760a 127.0.0.1:7004
S: 5628c2985cb8612883b921e24982409bf87d17e0 127.0.0.1:7005
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join...
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: fc65c271d01fd2151da15f08d7af14e2be8c18c2 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: 5b487aa64fee6fd2322d16a3fd1633944bab58f2 127.0.0.1:7001
   slots:5461-10921 (5461 slots) master
M: 2e9be1c7a4af976d678ef26a91dda37c1623d445 127.0.0.1:7002
   slots:10922-16383 (5462 slots) master
M: a8cdcf9756b2e8334c28190d8de95375551c6a8a 127.0.0.1:7003
   slots: (0 slots) master
M: e4f044404413eb1dddef513500beca1e554e760a 127.0.0.1:7004
   slots: (0 slots) master
M: 5628c2985cb8612883b921e24982409bf87d17e0 127.0.0.1:7005
   slots: (0 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

查看集群目前情况:

root@XIAOMO:/cluster_test/redis-unstable/src# redis-cli -c -p 7000
127.0.0.1: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:6
cluster_size:3
cluster_current_epoch:0
cluster_stats_messages_sent:8770
cluster_stats_messages_received:8770
127.0.0.1:7000> 

到此为止,集群搭建成功。目前最新的2.8稳定版是还不支持分布式架构,在2.9中将会支持,一起期待吧~




你可能感兴趣的:(【redis】redis集群配置小结)