部署 Redis 群集


Windows 部署 Redis 群集

 

1,下載Redis for windows 的最新版本,解壓到 c:\Redis 目錄下備用
https://github.com/MSOpenTech/redis/releases
當前我使用的是 3.0.501

 

2,下載 RubyInstaller
http://rubyinstaller.org/downloads/


安裝時,勾選 
Install Td/Tk Support 
Add Ruby executables to your PATH
Associate .rb and .rbw files with this Ruby installation

 

3,下載 redis-trib.rb , 放到 c:\redis 目錄下備用
https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb

 

4,新建6個子文件夾
cmd
cd c:\redis
mkdir 7000 7001 7002 7003 7004 7005

 

5,將如下配置修改,分別放入上一步新建的6個子文件夾中, 保存為 redis.conf:

port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 5000
appendonly yes

注意,將 port 和 cluster-config-file 改掉(每個文件都不一樣)

 


6, 為方便啟動這些 Redis 實例,新建如下 bat 文件:

@echo off
cd c:\Redis
start Redis-Server ./7000/redis.conf
start Redis-Server ./7001/redis.conf
start Redis-Server ./7002/redis.conf
start Redis-Server ./7003/redis.conf
start Redis-Server ./7004/redis.conf
start Redis-Server ./7005/redis.conf

 

7, 運行上步新建的 bat 文件,會打開6個窗口,每個窗口承載一個 Redis 實例,端口從 7000 至 7005
在 c:\Redis 文件夾下會出現 nodes-7000.conf 至 nodes-7005.conf 這幾個文件

 

8,安裝 GEM,Redis 的 ruby 支持環境

 
由於 GFW的問題, GEM 的源在國內不可用,所以使用淘寶的映像:
 
添加:
gem sources -a  https://ruby.taobao.org
 
查看已存在的源:
gem sources -l
 
刪除被牆的源:
gem sources -r  https://rubygems.org/
 
安裝 Redis 支持環境:
gem install redis

 


9,創建群集

打開 cmd , 執行以下命令:
cd c:\redis
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

--replicas 1 即自動分配 Slave , 如果想手動指定 Slave  , 將該值變為 0 即可, 地址列表中,只需要 3個實例即可。

 

由於使用的是 6個實例,自動分配 Slave ,所以前3個為 master , 后3 個為 slave, 並確定3個主節點的 slots 范圍。

如果確認沒有問題, 輸入 yes
如果群集創建成功, 會輸出 OK XXXXX
如果出現:
err slot xxx is already busy, 請刪除 appendonly.aof 及 nodes-xxx.conf (cluster-config-file 所指的文件) 文件

 

10, 測試一下:
redis-cli.exe -c -p 7000

  

--------------------------------------

以上是同一台機器上的群集部署方案,同一台虛擬機,使用不同的實例, 創建群集時,一路順利。

 

但是將實例部署到不同的機器上,我分別在6台虛擬機上安裝了 Redis, 但一開始創建群集的時候,就卡在這里:

>>> 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....................

 

一直在這個 Waiting for the cluster to join 這里。。。

用 redis-trib.rb check 192.168.18.111:6379 檢查,提示

[ERR] Not all 16384 slots are covered by nodes

 

具體的就是某台 master 上的 sloats 是 0

用客戶端連接到那個沒有分配 sloat 的 redis 實例,發送以下命令:

cluster meet 192.168.18.111 6379

回頭在用 Redis-trib.rb check 檢查, 發現 

[OK] All 16384 slots covered.

 

但是群集的創建還是卡在那個 waiting 上 ,

繼續在其它節點上發送 cluster meet 命令,回頭在用 redis-trib.rb check , 神奇的 Not all 16384 slots are covered by nodes 居然又來了。

將那個slots 為 0的實例做為 slave (放到參數列表的最后),在創建,順利通過!這個問題真是神奇啊!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM