redis在Windows下之後臺服務一鍵搭建集羣(單機--僞集羣)node
此教程介紹如何在windows系統中同一臺機器上佈置redis僞集羣,同時要之後臺服務的模式運行。佈置以腳本的形式,一鍵完成。關於在多臺機器上用腳本搭建集羣參見另外一博文《redis在Windows下之後臺服務一鍵搭建集羣(多機)》。git
如下準備的工具,想要了解詳細過程的,能夠逐一按下面的分步說明,一一下載。固然,不想麻煩的,這裏有一個包含全部工具的完整的包,直接下載便可,csdn下載連接:http://download.csdn.net/download/mingojiang/10186166github
1.下載Redis for windows的最新版本,解壓到c:\redis目錄下備用。github下載連接:https://github.com/MSOpenTech/redis/releasesredis
2.下載ruby環境RubyInstaller,這是ruby的運行環境。官網下載:http://rubyinstaller.org/downloads/ 我選的是「Ruby 2.3.3 (x64)」。windows
3,安裝 GEM,Redis的ruby支持環境。因爲GFW的問題,GEM的源在國內不可用,能夠@翻##牆,提供一下免費&&翻@#牆工具,百度網盤下載連接:https://pan.baidu.com/s/1eSiLWo6密碼: enfm,下載後須要解壓碼:edsryu4yu9hgfr34kj098@#^%(*@#FHk43ee6y9p8743。安全
4,下載 redis-trib.rb ,放到c:\redis目錄下備用ruby
github下載連接:https://github.com/antirez/redis/tree/3.2/srcmarkdown
這個是redis集羣工做要用到的小工具,ruby語言開發的小工具。運維
1. 安裝RubyInstaller工具
安裝2.1章中第2節下載的RubyInstaller,勾選
Install Td/Tk Support
Add Ruby executables to your PATH
Associate .rb and .rbw files with this Ruby installation
、
2.安裝 GEM
番@#!牆:運行第2.1章3節中下載的工具
顯示已經鏈接成功了,這個時候,你能夠直接安裝redis與ruby之間通訊的一個組件了,直接在命令行輸入命令:
gem install redis
提示成功便可。
至此環境準備完閉
注意:因爲中英文可能遇到兼容問題,因此運行腳本時,請把腳本文件放到英文目錄下。
關於腳本,嫌麻煩的,經過本人csdn下載連接可直接下載,裏面包含了所需的全部資料,下載連接爲:http://download.csdn.net/download/mingojiang/10186166
建立一文本「install.bat」,可直接運行此腳本,完成一鍵安裝redis羣集。打開腳本編輯,第二行是指定安裝的根目錄,可自行編輯:
rem 你要安裝的盤符,可自行配置
set InstallPath=D:
set sourcePath=%~dp0
cd /d %InstallPath%
mkdir redis-cluster
cd redis-cluster
mkdir 31001 31002 31003 32001 32002 32003 33001 33002 33003
copy %sourcePath%redis-server.exe 31001
copy %sourcePath%redis-server.exe 31002
copy %sourcePath%redis-server.exe 31003
copy %sourcePath%redis-server.exe 32001
copy %sourcePath%redis-server.exe 32002
copy %sourcePath%redis-server.exe 32003
copy %sourcePath%redis-server.exe 33001
copy %sourcePath%redis-server.exe 33002
copy %sourcePath%redis-server.exe 33003
copy %sourcePath%EventLog.dll 31001
copy %sourcePath%EventLog.dll 31002
copy %sourcePath%EventLog.dll 31003
copy %sourcePath%EventLog.dll 32001
copy %sourcePath%EventLog.dll 32002
copy %sourcePath%EventLog.dll 32003
copy %sourcePath%EventLog.dll 33001
copy %sourcePath%EventLog.dll 33002
copy %sourcePath%EventLog.dll 33003
copy %sourcePath%redis.windows-service.conf 31001
copy %sourcePath%redis.windows-service.conf 31002
copy %sourcePath%redis.windows-service.conf 31003
copy %sourcePath%redis.windows-service.conf 32001
copy %sourcePath%redis.windows-service.conf 32002
copy %sourcePath%redis.windows-service.conf 32003
copy %sourcePath%redis.windows-service.conf 33001
copy %sourcePath%redis.windows-service.conf 33002
copy %sourcePath%redis.windows-service.conf 33003
copy %sourcePath%redis-trib.rb
copy %sourcePath%redis.windows-service.conf
copy %sourcePath%redis-cli.exe
copy %sourcePath%startAllRedisService.bat
copy %sourcePath%stopAllRedisService.bat
copy %sourcePath%uninstall.bat
rename 31001\redis.windows-service.conf redis.conf
rename 31002\redis.windows-service.conf redis.conf
rename 31003\redis.windows-service.conf redis.conf
rename 32001\redis.windows-service.conf redis.conf
rename 32002\redis.windows-service.conf redis.conf
rename 32003\redis.windows-service.conf redis.conf
rename 33001\redis.windows-service.conf redis.conf
rename 33002\redis.windows-service.conf redis.conf
rename 33003\redis.windows-service.conf redis.conf
rem 關閉回顯
@echo off
rem 定義變量延遲環境
setlocal enabledelayedexpansion
rem 讀取全部內容
for /f "eol=* tokens=*" %%i in (31001\redis.conf) do (
rem 設置變量a爲每行內容
set a=%%i
rem 若是該行有123,則將其改成456
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
rem 把修改後的所有行存入$
set "a=!a:port 6379=port 31001!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\31001\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
rem 用$的內容替換原來a.txt內容
move $ 31001\redis.conf
for /f "eol=* tokens=*" %%i in (31002\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 31002!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\31002\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 31002\redis.conf
for /f "eol=* tokens=*" %%i in (31003\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 31003!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\31003\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 31003\redis.conf
for /f "eol=* tokens=*" %%i in (32001\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 32001!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\32001\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 32001\redis.conf
for /f "eol=* tokens=*" %%i in (32002\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 32002!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\32002\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 32002\redis.conf
for /f "eol=* tokens=*" %%i in (32003\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 32003!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\32003\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 32003\redis.conf
for /f "eol=* tokens=*" %%i in (33001\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 33001!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\33001\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 33001\redis.conf
for /f "eol=* tokens=*" %%i in (33002\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 33002!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\33002\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 33002\redis.conf
for /f "eol=* tokens=*" %%i in (33003\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 33003!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\33003\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 33003\redis.conf
@echo on
echo modify redis.conf file finished....
echo begin install redis windows services.....
31001\redis-server.exe --service-install %InstallPath%\redis-cluster\31001\redis.conf --service-name 31001redisM
31002\redis-server.exe --service-install %InstallPath%\redis-cluster\31002\redis.conf --service-name 31002redisM
31003\redis-server.exe --service-install %InstallPath%\redis-cluster\31003\redis.conf --service-name 31003redisM
32001\redis-server.exe --service-install %InstallPath%\redis-cluster\32001\redis.conf --service-name 32001redisM
32002\redis-server.exe --service-install %InstallPath%\redis-cluster\32002\redis.conf --service-name 32002redisM
32003\redis-server.exe --service-install %InstallPath%\redis-cluster\32003\redis.conf --service-name 32003redisM
33001\redis-server.exe --service-install %InstallPath%\redis-cluster\33001\redis.conf --service-name 33001redisM
33002\redis-server.exe --service-install %InstallPath%\redis-cluster\33002\redis.conf --service-name 33002redisM
33003\redis-server.exe --service-install %InstallPath%\redis-cluster\33003\redis.conf --service-name 33003redisM
echo install redis windows services finished.....
echo begin start all the redis as windows service......
31001\redis-server.exe --service-start --service-name 31001redisM
31002\redis-server.exe --service-start --service-name 31002redisM
31003\redis-server.exe --service-start --service-name 31003redisM
32001\redis-server.exe --service-start --service-name 32001redisM
32002\redis-server.exe --service-start --service-name 32002redisM
32003\redis-server.exe --service-start --service-name 32003redisM
33001\redis-server.exe --service-start --service-name 33001redisM
33002\redis-server.exe --service-start --service-name 33002redisM
33003\redis-server.exe --service-start --service-name 33003redisM
echo start all the redis as windows service finished....
echo begin create redis cluster......
redis-trib.rb create --replicas 2 127.0.0.1:31001 127.0.0.1:32001 127.0.0.1:33001 127.0.0.1:32002 127.0.0.1:33002 127.0.0.1:31002 127.0.0.1:33003 127.0.0.1:31003 127.0.0.1:32003
echo create redis cluster finished....
echo off
rem 延時20秒,自動關閉窗口
ping -n 20 127.0>nul
對安裝後的集羣服務,若是想要卸載,流程是,先中止全部節點服務,而後再反註冊便可。建立一個文本,命名「uninstall.bat」,而後編輯腳本:
echo begin stop all the redis as windows service......
%~dp031001\redis-server.exe --service-stop --service-name 31001redisM
%~dp031002\redis-server.exe --service-stop --service-name 31002redisM
%~dp031003\redis-server.exe --service-stop --service-name 31003redisM
%~dp032001\redis-server.exe --service-stop --service-name 32001redisM
%~dp032002\redis-server.exe --service-stop --service-name 32002redisM
%~dp032003\redis-server.exe --service-stop --service-name 32003redisM
%~dp033001\redis-server.exe --service-stop --service-name 33001redisM
%~dp033002\redis-server.exe --service-stop --service-name 33002redisM
%~dp033003\redis-server.exe --service-stop --service-name 33003redisM
echo stop all the redis as windows service finished....
echo "unistall redis service....."
%~dp031001\redis-server.exe --service-uninstall --service-name 31001redisM
%~dp031002\redis-server.exe --service-uninstall --service-name 31002redisM
%~dp031003\redis-server.exe --service-uninstall --service-name 31003redisM
%~dp032001\redis-server.exe --service-uninstall --service-name 32001redisM
%~dp032002\redis-server.exe --service-uninstall --service-name 32002redisM
%~dp032003\redis-server.exe --service-uninstall --service-name 32003redisM
%~dp033001\redis-server.exe --service-uninstall --service-name 33001redisM
%~dp033002\redis-server.exe --service-uninstall --service-name 33002redisM
%~dp033003\redis-server.exe --service-uninstall --service-name 33003redisM
echo "uninstall redis service finished"
echo off
rem 延時20秒,自動關閉窗口
ping -n 5 127.0>nul
有時想要中止全部節點服務,在服務管理器中,一個一個手動中止也是一種辦法,可是麻煩,一個一個操做,費事,可經過腳本一鍵中止,建立一個文本,命名「stopAllRedisService.bat」,編輯腳本:
echo begin stop all the redis as windows service......
%~dp031001\redis-server.exe --service-stop --service-name 31001redisM
%~dp031002\redis-server.exe --service-stop --service-name 31002redisM
%~dp031003\redis-server.exe --service-stop --service-name 31003redisM
%~dp032001\redis-server.exe --service-stop --service-name 32001redisM
%~dp032002\redis-server.exe --service-stop --service-name 32002redisM
%~dp032003\redis-server.exe --service-stop --service-name 32003redisM
%~dp033001\redis-server.exe --service-stop --service-name 33001redisM
%~dp033002\redis-server.exe --service-stop --service-name 33002redisM
%~dp033003\redis-server.exe --service-stop --service-name 33003redisM
echo stop all the redis as windows service finished....
echo off
rem 延時20秒,自動關閉窗口
ping -n 5 127.0>nul
有時想要啓動全部節點服務,在服務管理器中,一個一個手動啓動也是一種辦法,可是麻煩,一個一個操做,費事,可經過腳本一鍵啓動,建立一個文本,命名「startAllRedisService.bat」,編輯腳本:
echo begin start all the redis as windows service......
%~dp031001\redis-server.exe --service-start --service-name 31001redisM
%~dp031002\redis-server.exe --service-start --service-name 31002redisM
%~dp031003\redis-server.exe --service-start --service-name 31003redisM
%~dp032001\redis-server.exe --service-start --service-name 32001redisM
%~dp032002\redis-server.exe --service-start --service-name 32002redisM
%~dp032003\redis-server.exe --service-start --service-name 32003redisM
%~dp033001\redis-server.exe --service-start --service-name 33001redisM
%~dp033002\redis-server.exe --service-start --service-name 33002redisM
%~dp033003\redis-server.exe --service-start --service-name 33003redisM
echo start all the redis as windows service finished....
echo off
rem 延時20秒,自動關閉窗口
ping -n 5 127.0>nul
Redis是經過簡單的密碼來保證安全的,若是想開放給外網環境,那須要給配置密碼,密碼最長爲256個字符,給集羣配置密碼,有幾種方法,一種經過修改redis-trib.rb腳本的代碼能夠實現,這種方法,通常不適合初學者使用,對於初學者建議採用先搭建無密碼的集羣,再給集羣經過命令加密的方式。或者直接用腳本,一鍵安裝,實現邏輯,也是先無密碼搭建,而後經過腳本把服務中止,腳本方式增長密碼,而後再啓動服務的方式,在此介紹這兩種方法。
先按以上方法,建立集羣,而後經過redis-cli.exe工具遂一鏈接各個redis節點:而後執行如下四個命令。注意,密碼必須同樣,才能保證集羣相互交互成功。
config set masterauth abc
config set requirepass abc
auth abc
config rewrite
直接經過腳本,一鍵安裝,建立文本文件,重命名爲「install-auth.bat」,也就是說以上第三章節的腳本,以如下腳本替換。
rem 你要安裝的盤符,可自行配置
set InstallPath=D:
rem 給你的集羣加上密碼,可自行配置
set auth_password=#disiswnin((ndw0rksinm0stP0SIXsyst#mslik#Linux@*BSD@0ux(nd0SX(r#th#tw00p#r(tingsyst#
set sourcePath=%~dp0
cd /d %InstallPath%
mkdir redis-cluster
cd redis-cluster
mkdir 31001 31002 31003 32001 32002 32003 33001 33002 33003
copy %sourcePath%redis-server.exe 31001
copy %sourcePath%redis-server.exe 31002
copy %sourcePath%redis-server.exe 31003
copy %sourcePath%redis-server.exe 32001
copy %sourcePath%redis-server.exe 32002
copy %sourcePath%redis-server.exe 32003
copy %sourcePath%redis-server.exe 33001
copy %sourcePath%redis-server.exe 33002
copy %sourcePath%redis-server.exe 33003
copy %sourcePath%EventLog.dll 31001
copy %sourcePath%EventLog.dll 31002
copy %sourcePath%EventLog.dll 31003
copy %sourcePath%EventLog.dll 32001
copy %sourcePath%EventLog.dll 32002
copy %sourcePath%EventLog.dll 32003
copy %sourcePath%EventLog.dll 33001
copy %sourcePath%EventLog.dll 33002
copy %sourcePath%EventLog.dll 33003
copy %sourcePath%redis.windows-service.conf 31001
copy %sourcePath%redis.windows-service.conf 31002
copy %sourcePath%redis.windows-service.conf 31003
copy %sourcePath%redis.windows-service.conf 32001
copy %sourcePath%redis.windows-service.conf 32002
copy %sourcePath%redis.windows-service.conf 32003
copy %sourcePath%redis.windows-service.conf 33001
copy %sourcePath%redis.windows-service.conf 33002
copy %sourcePath%redis.windows-service.conf 33003
copy %sourcePath%redis-trib.rb
copy %sourcePath%redis.windows-service.conf
copy %sourcePath%redis-cli.exe
copy %sourcePath%startAllRedisService.bat
copy %sourcePath%stopAllRedisService.bat
copy %sourcePath%uninstall.bat
rename 31001\redis.windows-service.conf redis.conf
rename 31002\redis.windows-service.conf redis.conf
rename 31003\redis.windows-service.conf redis.conf
rename 32001\redis.windows-service.conf redis.conf
rename 32002\redis.windows-service.conf redis.conf
rename 32003\redis.windows-service.conf redis.conf
rename 33001\redis.windows-service.conf redis.conf
rename 33002\redis.windows-service.conf redis.conf
rename 33003\redis.windows-service.conf redis.conf
rem 關閉回顯
@echo off
rem 定義變量延遲環境
setlocal enabledelayedexpansion
rem 讀取全部內容
for /f "eol=* tokens=*" %%i in (31001\redis.conf) do (
rem 設置變量a爲每行內容
set a=%%i
rem 若是該行有123,則將其改成456
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
rem 把修改後的所有行存入$
set "a=!a:port 6379=port 31001!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\31001\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
rem 用$的內容替換原來a.txt內容
move $ 31001\redis.conf
for /f "eol=* tokens=*" %%i in (31002\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 31002!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\31002\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 31002\redis.conf
for /f "eol=* tokens=*" %%i in (31003\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 31003!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\31003\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 31003\redis.conf
for /f "eol=* tokens=*" %%i in (32001\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 32001!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\32001\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 32001\redis.conf
for /f "eol=* tokens=*" %%i in (32002\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 32002!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\32002\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 32002\redis.conf
for /f "eol=* tokens=*" %%i in (32003\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 32003!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\32003\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 32003\redis.conf
for /f "eol=* tokens=*" %%i in (33001\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 33001!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\33001\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 33001\redis.conf
for /f "eol=* tokens=*" %%i in (33002\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 33002!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\33002\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 33002\redis.conf
for /f "eol=* tokens=*" %%i in (33003\redis.conf) do (
set a=%%i
set "a=!a:# cluster-enabled yes=cluster-enabled yes!"
set "a=!a:port 6379=port 33003!"
set "a=!a:dir ./=dir %InstallPath%\redis-cluster\33003\!"
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
echo !a!>>$)
move $ 33003\redis.conf
@echo on
echo modify redis.conf file finished....
echo begin install redis windows services.....
31001\redis-server.exe --service-install %InstallPath%\redis-cluster\31001\redis.conf --service-name 31001redisM
31002\redis-server.exe --service-install %InstallPath%\redis-cluster\31002\redis.conf --service-name 31002redisM
31003\redis-server.exe --service-install %InstallPath%\redis-cluster\31003\redis.conf --service-name 31003redisM
32001\redis-server.exe --service-install %InstallPath%\redis-cluster\32001\redis.conf --service-name 32001redisM
32002\redis-server.exe --service-install %InstallPath%\redis-cluster\32002\redis.conf --service-name 32002redisM
32003\redis-server.exe --service-install %InstallPath%\redis-cluster\32003\redis.conf --service-name 32003redisM
33001\redis-server.exe --service-install %InstallPath%\redis-cluster\33001\redis.conf --service-name 33001redisM
33002\redis-server.exe --service-install %InstallPath%\redis-cluster\33002\redis.conf --service-name 33002redisM
33003\redis-server.exe --service-install %InstallPath%\redis-cluster\33003\redis.conf --service-name 33003redisM
echo install redis windows services finished.....
echo begin start all the redis as windows service......
31001\redis-server.exe --service-start --service-name 31001redisM
31002\redis-server.exe --service-start --service-name 31002redisM
31003\redis-server.exe --service-start --service-name 31003redisM
32001\redis-server.exe --service-start --service-name 32001redisM
32002\redis-server.exe --service-start --service-name 32002redisM
32003\redis-server.exe --service-start --service-name 32003redisM
33001\redis-server.exe --service-start --service-name 33001redisM
33002\redis-server.exe --service-start --service-name 33002redisM
33003\redis-server.exe --service-start --service-name 33003redisM
echo start all the redis as windows service finished....
echo begin create redis cluster......
redis-trib.rb create --replicas 2 127.0.0.1:31001 127.0.0.1:32001 127.0.0.1:33001 127.0.0.1:32002 127.0.0.1:33002 127.0.0.1:31002 127.0.0.1:33003 127.0.0.1:31003 127.0.0.1:32003
echo create redis cluster finished....
echo begin stop all the redis as windows service......
31001\redis-server.exe --service-stop --service-name 31001redisM
31002\redis-server.exe --service-stop --service-name 31002redisM
31003\redis-server.exe --service-stop --service-name 31003redisM
32001\redis-server.exe --service-stop --service-name 32001redisM
32002\redis-server.exe --service-stop --service-name 32002redisM
32003\redis-server.exe --service-stop --service-name 32003redisM
33001\redis-server.exe --service-stop --service-name 33001redisM
33002\redis-server.exe --service-stop --service-name 33002redisM
33003\redis-server.exe --service-stop --service-name 33003redisM
echo stop all the redis as windows service finished....
echo begin add password to the windows service redis......
@echo off
rem 讀取全部內容
for /f "eol=* tokens=*" %%i in (31001\redis.conf) do (
rem 設置變量a爲每行內容
set a=%%i
rem 若是該行有123,則將其改成456
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
rem 用$的內容替換原來a.txt內容
move $ 31001\redis.conf
for /f "eol=* tokens=*" %%i in (31002\redis.conf) do (
set a=%%i
set "a=!a:# cluster-config-file nodes-6379.conf=cluster-config-file nodes.conf!"
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 31002\redis.conf
for /f "eol=* tokens=*" %%i in (31003\redis.conf) do (
set a=%%i
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 31003\redis.conf
for /f "eol=* tokens=*" %%i in (32001\redis.conf) do (
set a=%%i
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 32001\redis.conf
for /f "eol=* tokens=*" %%i in (32002\redis.conf) do (
set a=%%i
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 32002\redis.conf
for /f "eol=* tokens=*" %%i in (32003\redis.conf) do (
set a=%%i
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 32003\redis.conf
for /f "eol=* tokens=*" %%i in (33001\redis.conf) do (
set a=%%i
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 33001\redis.conf
for /f "eol=* tokens=*" %%i in (33002\redis.conf) do (
set a=%%i
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 33002\redis.conf
for /f "eol=* tokens=*" %%i in (33003\redis.conf) do (
set a=%%i
set "a=!a:# requirepass foobared=requirepass %auth_password%!"
set "a=!a:# masterauth <master-password>=masterauth %auth_password%!"
echo !a!>>$)
move $ 33003\redis.conf
@echo on
echo end add password to the windows service redis......
echo begin start all the redis as windows service......
31001\redis-server.exe --service-start --service-name 31001redisM
31002\redis-server.exe --service-start --service-name 31002redisM
31003\redis-server.exe --service-start --service-name 31003redisM
32001\redis-server.exe --service-start --service-name 32001redisM
32002\redis-server.exe --service-start --service-name 32002redisM
32003\redis-server.exe --service-start --service-name 32003redisM
33001\redis-server.exe --service-start --service-name 33001redisM
33002\redis-server.exe --service-start --service-name 33002redisM
33003\redis-server.exe --service-start --service-name 33003redisM
echo start all the redis as windows service finished....
echo off
rem 延時30秒,自動關閉窗口
ping -n 30 127.0>nul
集羣搭建後,須要測試,調試,運維等,涉及到不少的命令與方法,請參加另外一博文:http://blog.csdn.net/mingojiang/article/details/78902370