windows下安装redis3.2.100单机和集群详解
下载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 7001 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.100 D: start redis-server ../single/redis.conf
双击start.bat开启单机的redis。。
使用netstat -aon|findstr 端口号 查看端口被哪个进程占用
tasklist|findstr 进程号查看进程被哪个程序占用
集群模式
增加配置
在cluster文件夹下增加1个配置文件redis.7001.conf.内容如下。然后复制此文件5份,将内容中的7001部分改为7002、7003、7004、7005、7006
至此,我们增加了6个配置文件。
bind 127.0.0.1 port 7001 loglevel verbose logfile "D:/Program Files/redis/log/logredis7001_log.txt" appendonly yes appendfilename "appendonly.7001.aof" cluster-enabled yes cluster-config-file nodes-7001.conf cluster-node-timeout 15000 cluster-slave-validity-factor 10 cluster-migration-barrier 1 cluster-require-full-coverage yes
图片出自http://www.cnblogs.com/xckk/p/6144447.html
增加启动脚本start.bat,内容如下:
@echo off cd D:\Program Files\redis\Redis-x64-3.2.100 D: start redis-server ../cluster/redis.7001.conf start redis-server ../cluster/redis.7002.conf start redis-server ../cluster/redis.7003.conf start redis-server ../cluster/redis.7004.conf start redis-server ../cluster/redis.7005.conf start redis-server ../cluster/redis.7006.conf
启动6个redis实例
双击start.bat启动6个redis实例,会看到6个窗口。可以查看log目录的日志确认是否启动成功
目前这6个实例都起了,但是是相对独立了,还不是集群。。还需要后面的步骤。。
安装ruby
下载地址http://dl.bintray.com/oneclick/rubyinstaller/。我下载的rubyinstaller-2.3.3.exe。
。
下载后双击安装。。注意勾选
安装Redis的Ruby库
打开ruby客户端:
执行命令gem install redis
C:\WINDOWS\system32>gem install redis Fetching: redis-4.0.1.gem (100%) Successfully installed redis-4.0.1 Parsing documentation for redis-4.0.1 Installing ri documentation for redis-4.0.1 Done installing documentation for redis after 2 seconds 1 gem installed
下载集群脚本redis-trib
下载地址 https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb
拷贝到某个文件夹,比如D:\Program Files\redis\cluster下
启动集群
打开命令窗口,执行命令
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
D:\Program Files\redis\run>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 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 Adding replica 127.0.0.1:7004 to 127.0.0.1:7001 Adding replica 127.0.0.1:7005 to 127.0.0.1:7002 Adding replica 127.0.0.1:7006 to 127.0.0.1:7003 M: 72a6b973a34ec0ca414ac480fdca1124cebd3717 127.0.0.1:7001 slots:0-5460 (5461 slots) master M: 7167e439fc6d545821d27f06efbcc9c2adc8c784 127.0.0.1:7002 slots:5461-10922 (5462 slots) master M: fee1f5f1f19bc2c459895d97d4a5e30524d288bb 127.0.0.1:7003 slots:10923-16383 (5461 slots) master S: 760fb1d95f36535ebb6295c1159760c19812d311 127.0.0.1:7004 replicates 72a6b973a34ec0ca414ac480fdca1124cebd3717 S: 27f0f3bf2482b8cc9425b82947e5d1fe75f26c73 127.0.0.1:7005 replicates 7167e439fc6d545821d27f06efbcc9c2adc8c784 S: 0cadc0d954614c3bec7881661c727312ddd7f88e 127.0.0.1:7006 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:7001) M: 72a6b973a34ec0ca414ac480fdca1124cebd3717 127.0.0.1:7001 slots:0-5460 (5461 slots) master M: 7167e439fc6d545821d27f06efbcc9c2adc8c784 127.0.0.1:7002 slots:5461-10922 (5462 slots) master M: fee1f5f1f19bc2c459895d97d4a5e30524d288bb 127.0.0.1:7003 slots:10923-16383 (5461 slots) master M: 760fb1d95f36535ebb6295c1159760c19812d311 127.0.0.1:7004 slots: (0 slots) master replicates 72a6b973a34ec0ca414ac480fdca1124cebd3717 M: 27f0f3bf2482b8cc9425b82947e5d1fe75f26c73 127.0.0.1:7005 slots: (0 slots) master replicates 7167e439fc6d545821d27f06efbcc9c2adc8c784 M: 0cadc0d954614c3bec7881661c727312ddd7f88e 127.0.0.1:7006 slots: (0 slots) master replicates fee1f5f1f19bc2c459895d97d4a5e30524d288bb [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 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.csdn.net/yys79/article/details/51566417
http://blog.csdn.net/qiuyufeng/article/details/70474001
http://www.cnblogs.com/xckk/p/6144447.html
Linux安装可参考:
http://blog.csdn.net/chen8238065/article/details/52318635
http://www.cnblogs.com/cxzdy/p/5132108.html
http://www.cnblogs.com/xckk/p/6144447.html