標籤:節點 複製 內容 lan .com 解壓 start 叢集 conf
註:原文轉自 73715947 ,僅用作為方便查閱
一 所需軟體:Redis、Ruby語言運行環境、Redis的Ruby驅動redis-xxxx.gem、建立Redis叢集的工具redis-trib.rb
二 安裝配置redis
redis https://github.com/MSOpenTech/redis/releases ; 下載Redis-x64-3.2.100.zip。
叢集規劃有三個節點的叢集,每個節點有一主一備。需要6台虛擬機器。
把 redis 解壓後,再複製出 5 份,配置 三主三從叢集。 由於 redis 預設連接埠號碼為 6379,那麼其它5份的連接埠可以為6380,6381,6382,6383,6384。 並且把目錄使用連接埠號碼命名
開啟目錄6379下有一個檔案 redis.windows.conf,修改裡面的連接埠號碼,以及叢集支援配置。
修改其他配置支援叢集
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
appendonly yes
如果cluster-enabled 不為yes, 那麼在使用JedisCluster叢集代碼擷取的時候,會報錯。
cluster-node-timeout 調整為 15000,那麼在建立叢集的時候,不會逾時。
cluster-config-file nodes-6379.conf 是為該節點的配置資訊,這裡使用 nodes-連接埠.conf命名方法。服務啟動後會在目錄產生該檔案。
編寫一個 bat 來啟動 redis,在每個節點目錄下建立 start.bat,內容如下:
title redis-6380
redis-server.exe redis.windows.conf
三 安裝Ruby
redis的叢集使用 ruby指令碼編寫,所以系統需要有 Ruby 環境 , http://dl.bintray.com/oneclick/rubyinstaller/:rubyinstaller-2.3.3-x64.exe
安裝時3個選項都勾選。
四 安裝Redis的Ruby驅動redis-xxxx.gem
https://rubygems.org/pages/download, 下載後解壓,目前的目錄切換到解壓目錄中,如 D:\Program Files\redis\rubygems-2.6.12 然後在命令列執行 ruby setup.rb。
然後GEM 安裝 Redis :切換到redis安裝目錄,需要在命令列中,執行 gem install redis
五 安裝叢集指令碼redis-trib
https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb
開啟該連結如果沒有下載,而是開啟一個頁面,那麼將該頁面儲存為redis-trib.rb,建議儲存到一個Redis的目錄下,例如放到6379目錄下。
叢集的命令為
redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384
--replicas 1 表示每個主要資料庫擁有從資料庫個數為1。master節點不能少於3個,所以我們用了6個redis
六 啟動每個節點並且執行叢集構建指令碼
把每個節點下的 start.bat雙擊啟動, 在切換到redis目錄在命令列中執行 redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384
備忘:有朋友反應上面的語句執行不成功。可以在前面加上ruby再運行。
ruby redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384
在出現 Can I set the above configuration? (type ‘yes‘ to accept): 請確定並輸入 yes 。成功後的結果如下:
七測試
使用Redis用戶端Redis-cli.exe來查看資料記錄數,以及叢集相關資訊
命令 redis-cli –c –h ”地址” –p "連接埠號碼" ; c 表示叢集
輸入dbsize查詢 記錄總數
輸入cluster info可以從用戶端的查看叢集的資訊
redis叢集步驟(windows環境)