一、準備文件
1.下載Redis for windows 的最新版本
下載地址:https://github.com/MSOpenTech/redis/releases
安裝到 c:\Redis 目錄下(Redis-x64-3.2.100.msi Windows服務版>)
2.下載 RubyInstaller
下載地址:http://rubyinstaller.org/downloads/
安裝時,勾選:(所使用版本rubyinstaller-2.3.1-x64.exe)
Install Td/Tk Support
Add Ruby executables to your PATH
Associate .rb and .rbw files with this Ruby installation
3.下載 redis-trib.rb
下載地址:https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb
復制源碼,新建文本,修改文件名
復制到 c:\redis 目錄下(redis-trib.rb)
4. 下載redis-3.2.1.gem
下載地址:https://rubygems.org/
二、部署
1. 在服務器上用HAPER-V新建6臺服務器(虛擬機)
01:192.168.0.71,02:192.168.0.109,03:192.168.0.148
04:192.168.0.187,05:192.168.0.240,06:192.168.0.25
關閉防火墻并確保每臺機子都是互通

2.每臺服務器安裝Redis-x64-3.2.100.msi
3.替換配置文件
新建記事本修改名稱和擴展名:redis.windows-service.conf(注意文件編碼要和安裝redis后的配置文件編碼一致)
編寫其下內容(其中在bind是該機IP地址,文件名可改可不改)
綠色字體為開啟集群功能
port 999
bind192.168.0.111
cluster-enabled yes
cluster-config-file nodes-cache01.conf
cluster-node-timeout 5000
appendonly yes
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
maxmemory 3999mb
替換c:\Redis\ redis.windows-service.conf文件
重啟Redis服務(任務管理器中)啟動完成會在Redis文件夾下生成appendonly.aof文件和nodes-cache01文件
4.在第一臺(操作集群的)安裝以下內容
rubyinstaller-2.3.1-x64.exe
復制redis-trib.rb文件到 c:\redis 目錄下(redis-trib.rb是用ruby語言編寫的,所以運行需要在服務器上安裝Ruby程序)
redis-3.2.1.gem文件復制到C:/Redis中
命令控制臺,cd/redis 進入C盤的redis文件夾Start-Server 啟動redis實例
修改gem的源
命令gem sources 查看當前源的地址

命令 gem sources –r https://rubygems.org/刪除當前源

命令 gem sources –ahttp://gems.github.com (淘寶源不能用了這里找了一個新的)

命令gem install redis

三、創(chuàng)建集群
1.啟動其余Rredis的客戶端(命令 start redis-server)

2.輸入命令創(chuàng)建集群
redis-trib.rb create --replicas1 192.168.0.71:999 192.168.0.109:999 192.168.0.148:999 192.168.0.187:999 192.168.0.240:999 192.168.0.25:999
--replicas 1 表示每個主數據庫擁有從數據庫個數為1。之前遇到錯誤提示master節(jié)點不能少于3個

3.輸入yes

4.最后測試
命令 redis-cli –c –h ”地址” –p "端口號"

此處必須-c
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:- linux環(huán)境部署及docker安裝redis的方法
- 如何用docker部署redis cluster的方法
- PHP的Laravel框架結合MySQL與Redis數據庫的使用部署
- Linux下Redis的安裝和部署
- kubernetes環(huán)境部署單節(jié)點redis數據庫的方法