redis在Windows下以后台服务一键搭建集群(单机--伪集群)

一、概述

此教程介绍如何在windows系统中同一台机器上布置redis伪集群,同时要以后台服务的模式运行。布置以脚本的形式,一键完成。关于在多台机器上用脚本搭建集群参见另一博文《redis在Windows下以后台服务一键搭建集群(多机)》。

二、准备的工具与环境

2.1资源下载

以下准备的工具,想要了解详细过程的,可以逐一按下面的分步说明,一一下载。当然,不想麻烦的,这里有一个包含所有工具的完整的包,直接下载即可,csdn下载链接:http://download.csdn.net/download/mingojiang/10186166

1.下载Redis for windows的最新版本,解压到c:\redis目录下备用。github下载链接:https://github.com/MSOpenTech/redis/releases

2.下载ruby环境RubyInstaller,这是ruby的运行环境。官网下载:http://rubyinstaller.org/downloads/ 我选的是“Ruby 2.3.3 (x64)”。

3,安装 GEM,Redis的ruby支持环境。由于GFW的问题,GEM的源在国内不可用,可以@翻##墙,提供一下免费&&翻@#墙工具,百度网盘下载链接:https://pan.baidu.com/s/1eSiLWo6密码: enfm,下载后需要解压码:edsryu4yu9hgfr34kj098@#^%(*@#FHk43ee6y9p8743。

4,下载 redis-trib.rb ,放到c:\redis目录下备用

github下载链接:https://github.com/antirez/redis/tree/3.2/src

这个是redis集群工作要用到的小工具,ruby语言开发的小工具。

2.2安装环境

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

redis在Windows下以后台服务一键搭建集群(单机--伪集群)的更多相关文章

  1. redis在Windows下以后台服务一键搭建哨兵(主从复制)模式(多机)

    redis在Windows下以后台服务一键搭建哨兵(主从复制)模式(多机) 一.概述 此教程介绍如何在windows系统中多个服务器之间,布置redis哨兵模式(主从复制),同时要以后台服务的模式运行 ...

  2. redis在Windows下以后台服务一键搭建哨兵(主从复制)模式(单机)

    redis在Windows下以后台服务一键搭建哨兵(主从复制)模式(单机) 一.概述 此教程介绍如何在windows系统中单机布置redis哨兵模式(主从复制),同时要以后台服务的模式运行.布置以脚本 ...

  3. redis在Windows下以后台服务一键搭建集群(多机器)

    redis在Windows下以后台服务一键搭建集群(多机器) 一.概述 此教程介绍如何在windows系统中多台机器之间布置redis集群,同时要以后台服务的模式运行.布置以脚本的形式,一键完成.多台 ...

  4. centos7环境下zookeeper的搭建步骤之单机伪集群

    首先说明:这里是单机版的伪集群搭建 第一步:下载zookeeper:zookeeper的下载地址: http://mirror.bit.edu.cn/apache/zookeeper/ 第二步:安装: ...

  5. Redis在windows下的环境搭建

    Redis在windows下的环境搭建 下载windows版本redis,,官方下载地址:http://redis.io/download, 不过官方没有Windows版本,官网只提供linux版本的 ...

  6. Redis在windows下的配置

    Redis在windows下的配置(在windows-64下安装redis,请参考微软redis的github:https://github.com/MSOpenTech/redis/releases ...

  7. Redis在windows下安装过程(转)

    (转)原文:http://www.cnblogs.com/M-LittleBird/p/5902850.html 要使redis在PHP下运行, 需在PHP文件下的ext扩展文件夹中添加扩展文件 ph ...

  8. redis在windows下安装教程

    安装过程 1.首先先把下载的压缩包解压到一个文件夹中2.打开cmd指令窗口3.输入你刚才解压的文件路径4.然后输入redis-server redis.windows.conf 命令接下来部署Redi ...

  9. windows下启动mysql服务

    当你无法连接你的mysql数据库时,或者因为某些原因导致与mysql数据库的连接丢失时,可通过以下方式启动mysql服务 1.命令行下启动mysql服务 以管理员身份运行cmd,进入mysql安装目录 ...

随机推荐

  1. MIC-3395单板机不识别PCI设备

    硬件环境: 单板机:MIC-3395 外设设备:自研的DSP6678板卡 现象: MIC-3395单板机不能识别DSP6678板卡,但是在MIC-3392上能够正常识别,排查若干问题后,升级3395的 ...

  2. [转]成为优秀Java程序员的10大技巧

    转自:http://www.codeceo.com/article/10-good-java-programmer-tips.html Java程序员有许多应遵循的守则或最佳实践方式.本文概述了每个开 ...

  3. 对Json的一些理解

    标准json格式:{"name":"王大昭","url":"https://www.cnblogs.com/codezhao/&q ...

  4. eros --- Windows Android真机调试

    1.下载并安装JDK 2.下载并安装Android Studio 上面两项不管用weex还是eros都是前置条件,度娘有大量教程. 开始eros 手脚架安装: $ npm i -g eros-cli ...

  5. spring cloud微服务三:Eureka服务治理之注册服务提供者及服务的发现和消费

    当服务注册中心成功建立以后,就需要有服务的注册和消费,否则这个服务注册中心就没有了存在的意义,而实际上,一个简单的服务注册也是非常简单的,仅仅需要实现四部曲就好. 首先,还是建立一个基本的spring ...

  6. Android Gradle 学习笔记(五):Gradle 任务 Task

    在之前的学习中,我们了解到Gradle的构建工作都是由Task组合完成的.本节我们就来介绍一下 Task - 任务. 一.多种方式创建任务 在Gradle中,我们可以有很多种方式来创建任务.为什么有这 ...

  7. chromedriver对应chrom版本

    chromedriver版本 支持的Chrome版本 v2.37 v64-66 v2.36 v63-65 v2.35 v62-64 v2.34 v61-63 v2.33 v60-62 v2.32 v5 ...

  8. gitlab web端使用

    https://jenkins.io/zh/doc/pipeline/tour/getting-started/ http://www.cnblogs.com/cheng95/p/6542036.ht ...

  9. (二)异步解决方案之callback

    回调定义 就是一个函数里面使用 作为参数的函数. Function1(Function2) { Function2(); }; 同步调用 - 老实说,这和我们 不将代码封装成 函数没有差别 也就是说 ...

  10. python入门之socket代码练习

    Part.1 简单的socket单次数据传输 服务端: #服务器端 import socket server = socket.socket() # 声明socket类型,同时生成socket连接对象 ...