1. 程式人生 > >【redis】redis叢集配置小結

【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個從節點)時,報了這個錯誤:

[email protected]:/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包就行了:

[email protected]:~# 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...
[email protected]
:~#
安裝成功後,叢集最後一步搭建也就可以繼續了:
[email protected]:/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.

檢視叢集目前情況:

[email protected]:/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中將會支援,一起期待吧~