redis-cluster安裝和配置
阿新 • • 發佈:2018-12-25
redis-cluster是redis官方寫的叢集功能,目前還未加入穩定版,據說會在3.0上線的時候加入,但是開發版已經包含該功能
開發版的下載方式是git clone https://github.com/antirez/redis.git,前提是安裝了git
安裝配置過程參考官方已經出的教程http://redis.io/topics/cluster-tutorial,全英文
1、原始碼下載,make
2、新建6個instance,3個master,3個slave;
新建例項之前要改一下redis.conf的內容,先改埠號,再改下面的cluster配置項
################################ REDIS CLUSTER ############################### # # Normal Redis instances can't be part of a Redis Cluster;only nodes that are # started as cluster nodes can. In order to start a Redisinstance as a # cluster node enable the cluster support uncommenting thefollowing: # cluster-enabled yes3、src下面的ruby指令碼,建立叢集: --replicas 1的意思是每個master有1個slave。
./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
|
如果指令碼報錯:
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>'
那麼說明Ruby的redis介面沒有安裝,可以通過sudo gem install redis 進行安裝。
可能會詢問是否儲存設定
Can I set the above configuration? (type 'yes' to accept):
回答yes
再輸出一連串資訊後,會顯示OK
[OK] All 16384 slots covered.
這樣redis-cluster叢集就啟動了
檢視叢集目前狀況:
$ 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"