Windows下搭建Redis叢集

來源:互聯網
上載者:User

標籤:分享圖片   filename   意思   開啟檔案   sso   解壓   tor   info   ruby開發   

Windows下搭建Redis叢集 Redis叢集:

 如果部署到多台電腦,就跟普通的叢集一樣;因為Redis是單線程處理的,多核CPU也只能使用一個核,

所以部署在同一台電腦上,通過運行多個Redis執行個體,並將這些執行個體組成叢集,就可以提高CPU的利用率。

在Windows系統下搭建Redis叢集:

需要4個組件:

Redis、Ruby語言運行環境、Redis的Ruby驅動redis-3.2.2.gem、建立Redis叢集的工具redis-trib.rb

安裝Redis,並運行3個執行個體(Redis叢集需要至少3個以上節點,低於3個無法建立);

使用redis-trib.rb工具來建立Redis叢集,由於該檔案是用ruby語言寫的,所以需要安裝Ruby開發環境,以及驅動redis-3.2.2.gem

1.下載並安裝Redis

其GitHub路徑如下:https://github.com/MSOpenTech/redis/releases/

Redis提供msi和zip格式的下載檔案,這裡下載zip格式 3.0.504版本

將下載到的Redis-x64-3.0.504.zip解壓即可,為了方便使用,將目錄名改為Redis,並放在D盤根目錄下(D:/Redis),

通過設定檔來啟動3個不同的Redis執行個體,由於Redis預設連接埠為6379,所以這裡使用了6380、6381、6382來運行3個Redis執行個體。

注意:為了避免不必要的錯誤,請將設定檔儲存為utf8格式,並且不要包含注釋;  

為了記錄Redis的日誌,所以需要在Redis目錄D:/Redis下建立 Logs檔案夾

redis.6380.conf 內容如下:

port 6380      loglevel notice    logfile "D:/Redis/Logs/redis6380_log.txt"       appendonly yesappendfilename "appendonly.6380.aof"   cluster-enabled yes                                    cluster-config-file nodes.6380.confcluster-node-timeout 15000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage yes

redis.6381.conf 內容如下:

port 6381       loglevel notice   logfile "D:/Redis/Logs/redis6381_log.txt"       appendonly yesappendfilename "appendonly.6381.aof"    cluster-enabled yes                                    cluster-config-file nodes.6381.confcluster-node-timeout 15000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage yes

redis.6382.conf 內容如下:

port 6382       loglevel notice    logfile "D:/Redis/Logs/redis6382_log.txt"         appendonly yesappendfilename "appendonly.6382.aof"    cluster-enabled yes                                    cluster-config-file nodes.6382.confcluster-node-timeout 15000cluster-slave-validity-factor 10cluster-migration-barrier 1cluster-require-full-coverage yes

配置內容的解釋如下:

 port 6380               #連接埠號碼 loglevel notice         #日誌的記錄層級,notice是適合生產環境的 logfile "D:/Redis/Logs/redis6380_log.txt"      #指定log的保持路徑,預設是建立在Redis安裝目錄下,如果有子目錄需要手動建立,如此處的Logs目錄 syslog-enabled yes                       #是否使用系統日誌 syslog-ident redis6380                   #在系統日誌的標識名 appendonly yes                           #資料的儲存為aof格式 appendfilename "appendonly.6380.aof"     #資料儲存檔案 cluster-enabled yes                      #是否開啟叢集 cluster-config-file nodes.6380.conf cluster-node-timeout 15000 cluster-slave-validity-factor 10 cluster-migration-barrier 1 cluster-require-full-coverage yes

將上述設定檔儲存到D:/Redis目錄下,並使用這些設定檔安裝3個redis服務,命令如下:

注意:redis.6380.conf等設定檔要使用完整路徑,避免重啟Redis叢集出現問題,此處的安裝目錄為 D:/Redis

D:/Redis/redis-server.exe --service-install D:/Redis/redis.6380.conf --service-name redis6380
D:/Redis/redis-server.exe --service-install D:/Redis/redis.6381.conf --service-name redis6381
D:/Redis/redis-server.exe --service-install D:/Redis/redis.6382.conf --service-name redis6382

啟動這3個服務,命令如下:

D:/Redis/redis-server.exe --service-start --service-name Redis6382D:/Redis/redis-server.exe --service-start --service-name Redis6381D:/Redis/redis-server.exe --service-start --service-name Redis6380

執行結果:

2.下載並安裝ruby  2.1. 下載路徑如下:

http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe

下載後,雙擊安裝即可,為了操作方便,安裝到 C盤根目錄下(C:\Ruby22-x64),

安裝時選中以下兩個選項:

Add ruby executables to your PATH

Associate .rb and .rbw files with this Ruby installation

意思是將ruby添加到系統的環境變數中,在cmd命令中能直接使用ruby的命令;並主動關聯.rb和.rbw格式的檔案。

   2.2.下載ruby環境下Redis的驅動,考慮到相容性,這裡下載的是3.2.2版本

https://rubygems.org/gems/redis/versions/3.2.2

注意:下載在頁面右下角相關串連一項中

 

安裝該驅動,命令如下:

C:\Ruby22-x64\bin\gem install --local c:\Ruby22-x64\redis-3.2.2.gem

      2.3.下載Redis官方提供的建立Redis叢集的ruby指令檔redis-trib.rb,路徑如下:

https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb

開啟該連結如果沒有下載,而是開啟一個頁面,那麼將該頁面儲存為redis-trib.rb   (.rb為尾碼名,是ruby檔案的儲存格式),並儲存到D:/Redis目錄下。

  3.建立Redis叢集

CMD下切換到Redis目錄,使用redis-trib.rb來建立Redis叢集:

redis-trib.rb create --replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382

注意:因為redis-trib.rb是ruby代碼,必須用ruby來開啟,若redis-trib.rb無法識別,需要手動選擇該檔案的開啟檔案:

  **選擇ruby為的開啟檔案後,redis-trib.rb的logo都會發生改變,如:

 

執行結果:

當出現提示時,需要手動輸入yes,輸入後,當出現以下內容,說明已經建立了Redis叢集

檢驗是否真的建立成功,輸入以下命令:

redis-trib.rb check 127.0.0.1:6380

出現以下資訊,說明建立的Redis叢集是沒問題的

使用Redis用戶端Redis-cli.exe來查看資料記錄數,以及叢集相關資訊

D:/Redis/redis-cli.exe -c -p 6380

-c 表示 cluster

-p 表示 port 連接埠號碼

輸入dbsize查詢 記錄總數

dbsize

或者一次輸入完整命令:

D:/Redis/redis-cli.exe -c -p 6380 dbsize

結果如下:

輸入cluster info可以從用戶端的查看叢集的資訊:

cluster info

結果如下:

Windows下搭建Redis叢集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.