windows下安装redis3.2.100单机和集群详解

时间:2022-06-28 12:58:10

下载redis

下载地址:https://github.com/MicrosoftArchive/redis/releases

我下载的是3.2.100版本的Redis-x64-3.2.100.zip,解压后放到某个目录,比如:D:\Program Files\redis

在此目录下增加三个文件夹:single、cluster、log

Single:存放单机模式的配置文件

Cluster:集群模式下的配置文件等信息

log:存放日志文件

单机模式

single文件夹下增加配置文件redis.conf,内容如下:

bind 127.0.0.1
port
loglevel verbose
logfile "D:/Program Files/redis/log/logredis7001_log.txt"
appendonly yes
appendfilename "appendonly.7001.aof"
cluster-enabled no

其中cluster-enabled=no表示不启用集群,即单机模式。。port为端口号。

single文件夹下增加一个启动文件start.bat,内容如下:

@echo off
cd D:\Program Files\redis\Redis-x64-3.2.
D:
start redis-server ../single/redis.conf

双击start.bat开启单机的redis。。

使用netstat -aon|findstr 端口号  查看端口被哪个进程占用

tasklist|findstr 进程号查看进程被哪个程序占用

windows下安装redis3.2.100单机和集群详解

集群模式

增加配置

在cluster文件夹下增加1个配置文件redis.7001.conf.内容如下。然后复制此文件5份,将内容中的7001部分改为7002、7003、7004、7005、7006

至此,我们增加了6个配置文件。

bind 127.0.0.1
port
loglevel verbose
logfile "D:/Program Files/redis/log/logredis7001_log.txt"
appendonly yes
appendfilename "appendonly.7001.aof"
cluster-enabled yes
cluster-config-file nodes-.conf
cluster-node-timeout
cluster-slave-validity-factor
cluster-migration-barrier
cluster-require-full-coverage yes

windows下安装redis3.2.100单机和集群详解

图片出自http://www.cnblogs.com/xckk/p/6144447.html

增加启动脚本start.bat,内容如下:

@echo off
cd D:\Program Files\redis\Redis-x64-3.2.
D:
start redis-server ../cluster/redis..conf
start redis-server ../cluster/redis..conf
start redis-server ../cluster/redis..conf
start redis-server ../cluster/redis..conf
start redis-server ../cluster/redis..conf
start redis-server ../cluster/redis..conf

启动6个redis实例

双击start.bat启动6个redis实例,会看到6个窗口。可以查看log目录的日志确认是否启动成功

目前这6个实例都起了,但是是相对独立了,还不是集群。。还需要后面的步骤。。

安装ruby

下载地址http://dl.bintray.com/oneclick/rubyinstaller/。我下载的rubyinstaller-2.3.3.exe。

windows下安装redis3.2.100单机和集群详解

下载后双击安装。。注意勾选

windows下安装redis3.2.100单机和集群详解

安装Redis的Ruby库

打开ruby客户端:windows下安装redis3.2.100单机和集群详解

执行命令gem install redis

windows下安装redis3.2.100单机和集群详解

C:\WINDOWS\system32>gem install redis
Fetching: redis-4.0..gem (%)
Successfully installed redis-4.0.
Parsing documentation for redis-4.0.
Installing ri documentation for redis-4.0.
Done installing documentation for redis after seconds
gem installed

下载集群脚本redis-trib

下载地址   https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb

拷贝到某个文件夹,比如D:\Program Files\redis\cluster下

windows下安装redis3.2.100单机和集群详解

启动集群

打开命令窗口,执行命令

ruby redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

windows下安装redis3.2.100单机和集群详解

D:\Program Files\redis\run>ruby redis-trib.rb create --replicas  127.0.0.1: 127.0.0.1: 127.0.0.1: 127.0.0.1: 127.0.0.1: 127.0.0.1:
>>> Creating cluster
>>> Performing hash slots allocation on nodes...
Using masters:
127.0.0.1:
127.0.0.1:
127.0.0.1:
Adding replica 127.0.0.1: to 127.0.0.1:
Adding replica 127.0.0.1: to 127.0.0.1:
Adding replica 127.0.0.1: to 127.0.0.1:
M: 72a6b973a34ec0ca414ac480fdca1124cebd3717 127.0.0.1:
slots:- ( slots) master
M: 7167e439fc6d545821d27f06efbcc9c2adc8c784 127.0.0.1:
slots:- ( slots) master
M: fee1f5f1f19bc2c459895d97d4a5e30524d288bb 127.0.0.1:
slots:- ( slots) master
S: 760fb1d95f36535ebb6295c1159760c19812d311 127.0.0.1:
replicates 72a6b973a34ec0ca414ac480fdca1124cebd3717
S: 27f0f3bf2482b8cc9425b82947e5d1fe75f26c73 127.0.0.1:
replicates 7167e439fc6d545821d27f06efbcc9c2adc8c784
S: 0cadc0d954614c3bec7881661c727312ddd7f88e 127.0.0.1:
replicates fee1f5f1f19bc2c459895d97d4a5e30524d288bb
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join......
>>> Performing Cluster Check (using node 127.0.0.1:)
M: 72a6b973a34ec0ca414ac480fdca1124cebd3717 127.0.0.1:
slots:- ( slots) master
M: 7167e439fc6d545821d27f06efbcc9c2adc8c784 127.0.0.1:
slots:- ( slots) master
M: fee1f5f1f19bc2c459895d97d4a5e30524d288bb 127.0.0.1:
slots:- ( slots) master
M: 760fb1d95f36535ebb6295c1159760c19812d311 127.0.0.1:
slots: ( slots) master
replicates 72a6b973a34ec0ca414ac480fdca1124cebd3717
M: 27f0f3bf2482b8cc9425b82947e5d1fe75f26c73 127.0.0.1:
slots: ( slots) master
replicates 7167e439fc6d545821d27f06efbcc9c2adc8c784
M: 0cadc0d954614c3bec7881661c727312ddd7f88e 127.0.0.1:
slots: ( slots) master
replicates fee1f5f1f19bc2c459895d97d4a5e30524d288bb
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.

根据运行结果可见前三个端口是主,后面三个是从。

可能会发现报错:

[136] 26 Jan 11:58:58.721 # Creating Server TCP listening socket *:7001: listen: Unknown error

[16656] 26 Jan 12:00:18.728 # Creating Server TCP listening socket *:7001: listen: Unknown error

这个报错需要在配置文件里加上

bind 127.0.0.1

参考文档

http://blog.****.net/yys79/article/details/51566417

http://blog.****.net/qiuyufeng/article/details/70474001

http://www.cnblogs.com/xckk/p/6144447.html

Linux安装可参考:

http://blog.****.net/chen8238065/article/details/52318635

http://www.cnblogs.com/cxzdy/p/5132108.html

http://www.cnblogs.com/xckk/p/6144447.html