标签:
这里只记录操作步骤和集群测试,保证快速搭建集群环境。具体原理请查阅官方文档(中文版):
http://redisdoc.com/topic/cluster-tutorial.html
http://redisdoc.com/topic/cluster-spec.html
下载并编译redis
创建6个以端口号为名字的目录,7000~7005,修改redis.conf的端口号
修改配置:
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
分别启动这6个服务:./redis-server redis.conf
sudo apt-get install ruby
安装ruby的redis接口:
sudo gem install redis
如果不安装,后面执行脚本会报错:
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 ./redis-trib.rb:25:in `<main>‘
进入到redis的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
命令的意义如下:
给定 redis-trib.rb
程序的命令是 create
, 这表示我们希望创建一个新的集群。
选项 --replicas 1
表示我们希望为集群中的每个主节点创建一个从节点。
之后跟着的其他参数则是实例的地址列表, 我们希望程序使用这些地址所指示的实例来创建新集群。
$ 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:6
cluster_size:3
cluster_current_epoch:0
cluster_stats_messages_sent:8770
cluster_stats_messages_received:8770
127.0.0.1:7000> set foo bar
-> Redirected to slot [12182] located at 127.0.0.1:7002
OK
127.0.0.1:7002> set hello world
-> Redirected to slot [866] located at 127.0.0.1:7000
OK
127.0.0.1:7000> get foo
-> Redirected to slot [12182] located at 127.0.0.1:7002
"bar"
127.0.0.1:7000> get hello
-> Redirected to slot [866] located at 127.0.0.1:7000
"world"
标签:
原文地址:http://my.oschina.net/tongyufu/blog/406829