Redis集群搭建
1.下载Redis
下载一个稳定(Stable)的版本,解压
2.设置配置文件
打开redis.windows-service.conf
修改
bind 127.0.0.1
port 6379
protected-mode yes
requirepass 12345678
masterauth 12345678
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
将上述配置一一修改后,然后将所有文件放在6379文件夹中
3.创建多个端口
因为项目需要我部署了6个端口,所以将6379文件夹复制6份,改名成6380,6381,6382,6383,6384方便自己区分。
再分别更改每个文件夹中的redis.windows-service.conf
修改port
改为6380,6381,6382,6383,6384。
4.创建一个启动文件
在Redis
目录下创建一个stratall.bat
文件,打开修改
cd 6379
del nodes.conf,appendonly.aof
start /b redis-server.exe redis.windows-service.conf
cd ..
cd 6380
del nodes.conf,appendonly.aof
start /b redis-server.exe redis.windows-service.conf
cd ..
cd 6381
del nodes.conf,appendonly.aof
start /b redis-server.exe redis.windows-service.conf
cd ..
cd 6382
del nodes.conf,appendonly.aof
start /b redis-server.exe redis.windows-service.conf
cd ..
cd 6383
del nodes.conf,appendonly.aof
start /b redis-server.exe redis.windows-service.conf
cd ..
cd 6384
del nodes.conf,appendonly.aof
start /b redis-server.exe redis.windows-service.conf
cd ..
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
pause
这个文件此时开启无法运行,我们还需要安装Ruby。
5.安装Ruby
由于Redis
的集群使用Ruby
脚本编写,所以系统需要有Ruby
环境。
http://www.ruby-lang.org/en/downloads/
Stable releases选择一个需要的版本下载解压安装。
然后我们需要一个Ruby写的集群脚本,打开下面的网站,复制内容,在Redis文件夹下创建一个redis-trib.rb
文件,写入刚才复制的内容。
https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb
结果如图:
6.安装Ruby模块
下载地址https://rubygems.org/pages/download,下载后解压,然后在命令行执行
ruby setup.rb
当前目录切换到解压目录中,如 D:\Redis-x64-3.2.100\rubygems-2.6.11,安装后执行
gem install redis
安装服务。
7.启动Redis
启动之前写的startall.bat
文件,当屏幕上出现如下提示时输入yes,保持命令行不要关闭。
Can I set the above configuration? (type ‘yes’ to accept):
停止调试,关闭服务的时候直接将命令行叉掉就可以了。
8.资源下载
在这里我将我的Redis
配置上传,帮助大家更快的搭建Redis集群环境
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。