1. 程式人生 > >linux redis3叢集安裝詳細步驟與測試 redis cluster

linux redis3叢集安裝詳細步驟與測試 redis cluster

執行redis的建立叢集命令建立叢集

./redis-trib.rb  create  --replicas  1  192.168.215.129:7000 192.168.215.129:7001  192.168.215.129:7002 192.168.215.130:7003  192.168.215.130:7004  192.168.215.130:7005


執行上面的命令的時候會報錯,因為是執行的ruby的指令碼,需要ruby的環境
錯誤內容:/usr/bin/env: ruby: No such file or directory6.1執行上面的命令的時候會報錯,因為是執行的ruby的指令碼,需要ruby的環境

所以需要安裝ruby的環境,這裡推薦使用

yum install ruby安裝

yum install ruby

然後再執行建立叢集命令,還會報錯,提示缺少rubygems元件,使用yum安裝

錯誤內容:

./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)

from ./redis-trib.rb:24

yum install rubygems

再次執行建立叢集命令,還會報錯,提示不能載入redis,是因為缺少redisruby的介面,使用gem 安裝

錯誤內容:

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)

from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

from ./redis-trib.rb:25

gem install  redis --version 3.0.0

注意:gem install redis --version 3.0.0 失敗的話,需要修改一下gem的源
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/

新增ruby-china源:

  1. [[email protected]
    software
    ]# gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
  2. [[email protected] software]# gem sources -l
  3. *** CURRENT SOURCES ***
  4. https://gems.ruby-china.org/
再次執行建立叢集的命令

結果操作一直阻塞在 Waiting for the cluster to join.........................

原因: redis叢集不僅需要開通redis客戶端連線的埠,而且需要開通叢集匯流排埠 叢集匯流排埠為redis客戶端連線的埠 + 10000 如redis埠為6379 則叢集匯流排埠為16379 故,所有伺服器的點需要開通redis的客戶端連線埠和叢集匯流排埠 netstat-tnlp| grep redis #可以看到redis監聽端


開放埠:執行 vi /etc/sysconfig/iptables

新增 -A INPUT -p tcp -m state --state NEW -m tcp --dport 16379 -j ACCEPT  即添加了16379埠 其他埠一樣()操作

然後儲存,重啟 service iptables restart

再次執行建立叢集的命令

再次執行建立叢集的命令,正常執行

[[email protected] src]# ./redis-trib.rb  create  --replicas  1  192.168.215.129:7000 192.168.215.129:7001  192.168.215.129:7002 192.168.215.130:7003  192.168.215.130:7004  192.168.215.130:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.215.129:7000
192.168.215.130:7003
192.168.215.129:7001
Adding replica 192.168.215.130:7004 to 192.168.215.129:7000
Adding replica 192.168.215.129:7002 to 192.168.215.130:7003
Adding replica 192.168.215.130:7005 to 192.168.215.129:7001
M: 16518afbfcbd961aeb76ef1592007a3e7fe24b1b 192.168.215.129:7000
   slots:0-5460 (5461 slots) master
M: 524219969118a57ceaac753ecef7585f634cdf26 192.168.215.129:7001
   slots:10923-16383 (5461 slots) master
S: ea4519ff0083a13cef8262490ee9e61e5a4b14b1 192.168.215.129:7002
   replicates 82c0e591b9bc7a289026dff2873a254d1c49d285
M: 82c0e591b9bc7a289026dff2873a254d1c49d285 192.168.215.130:7003
   slots:5461-10922 (5462 slots) master
S: baf74dd89c0605d2a71a8d1d3706005ff668563b 192.168.215.130:7004
   replicates 16518afbfcbd961aeb76ef1592007a3e7fe24b1b
S: f8192314d2232e12ba9f558e9ecbfcc890f4fb73 192.168.215.130:7005
   replicates 524219969118a57ceaac753ecef7585f634cdf26
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join.....
>>> Performing Cluster Check (using node 192.168.215.129:7000)
M: 16518afbfcbd961aeb76ef1592007a3e7fe24b1b 192.168.215.129:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: ea4519ff0083a13cef8262490ee9e61e5a4b14b1 192.168.215.129:7002
   slots: (0 slots) slave
   replicates 82c0e591b9bc7a289026dff2873a254d1c49d285
S: f8192314d2232e12ba9f558e9ecbfcc890f4fb73 192.168.215.130:7005
   slots: (0 slots) slave
   replicates 524219969118a57ceaac753ecef7585f634cdf26
S: baf74dd89c0605d2a71a8d1d3706005ff668563b 192.168.215.130:7004
   slots: (0 slots) slave
   replicates 16518afbfcbd961aeb76ef1592007a3e7fe24b1b
M: 524219969118a57ceaac753ecef7585f634cdf26 192.168.215.129:7001
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 82c0e591b9bc7a289026dff2873a254d1c49d285 192.168.215.130:7003
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

解釋下, –replicas 1 表示 自動為每一個master節點分配一個slave節點 上面有6個節點,程式會按照一定規則生成 3個master(主)3個slave(從) 
前面已經提醒過的 防火牆一定要開放監聽的埠,否則會建立失敗。