在Windows系统下搭建Redis集群

准备工作

需要4个部件:Redis、Ruby语言运行环境、Redis的Ruby驱动redis-xxxx.gem、创建Redis集群的工具redis-trib.rb。使用redis-trib.rb工具来创建Redis集群,由于该文件是用ruby语言写的,所以需要安装Ruby开发环境,以及驱动redis-xxxx.gem。

1)下载Redis安装文件:https://github.com/MSOpenTech/redis/releases/,Redis提供msi和zip格式的下载文件,这里下载zip格式Redis-x64-3.2.100版本。

2)下载Ruby安装文件:http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe

3)下载Ruby环境下Redis的驱动:https://rubygems.org/gems/redis/versions/3.2.2,考虑到兼容性,这里下载的是3.2.2版本

注意:下载在页面右下角相关连接一项中

4)下载Redis官方提供的创建Redis集群的ruby脚本文件redis-trib.rb,路径如下:https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb

安装Redis

将下载到的Redis-x64-3.2.100.zip解压即可,为了方便使用,建议放在盘符根目录下,如:D:\Redis-Cluster\Redis-x64-3.2.100。

安装Redis,并运行3个实例(Redis集群需要至少3个以上节点,低于3个无法创建);

通过配置文件来启动6个不同的Redis实例,由于Redis默认端口为6379,所以这里使用了6380、6381、6382、6383、6384、6385来运行6个Redis实例。

注意:

  1)为了避免不必要的错误,配置文件尽量保存为utf8格式,并且不要包含注释;

  2)配置文件中以下两种保存日志的方式(保存在文件中、保存到System Log中)请根据需求选择其中一种即可:

loglevel notice                                                     #日志的记录级别,notice是适合生产环境的
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6380_log.txt" #指定log的保持路径,默认是创建在Redis安装目录下,如果有子目录需要手动创建,如此处的Logs目录
syslog-enabled yes                                                  #是否使用系统日志   
syslog-ident redis6380                                              #在系统日志的标识名

这里使用了保存在文件中的方式,所以先在Redis目录D:\Redis-Cluster\Redis-x64-3.2.100下新建Logs文件夹

在Redis安装根目录下,创建编码格式为utf-8的配置文件:redis.6380.conf、redis.6381.conf、redis.6382.conf、redis.6383.conf、redis.6384.conf、redis.6385.conf。

redis.6380.conf、

port 6380
loglevel notice
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6380_log.txt"
appendonly yes
appendfilename "appendonly.6380.aof"
cluster-enabled yes
cluster-config-file nodes.6380.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

redis.6381.conf、

port 6381
loglevel notice
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6381_log.txt"
appendonly yes
appendfilename "appendonly.6381.aof"
cluster-enabled yes
cluster-config-file nodes.6381.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

redis.6382.conf、

port 6382
loglevel notice
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6382_log.txt"
appendonly yes
appendfilename "appendonly.6382.aof"
cluster-enabled yes
cluster-config-file nodes.6382.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

redis.6383.conf、

port 6383
loglevel notice
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6383_log.txt"
appendonly yes
appendfilename "appendonly.6383.aof"
cluster-enabled yes
cluster-config-file nodes.6383.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

redis.6384.conf、

port 6384
loglevel notice
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6384_log.txt"
appendonly yes
appendfilename "appendonly.6384.aof"
cluster-enabled yes
cluster-config-file nodes.6384.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

redis.6385.conf

port 6385
loglevel notice
logfile "D:/Redis-Cluster/Redis-x64-3.2.100/Logs/redis6385_log.txt"
appendonly yes
appendfilename "appendonly.6385.aof"
cluster-enabled yes
cluster-config-file nodes.6385.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

配置解释如下:

 1 port 6380                                 #端口号
 2 loglevel notice                           #日志的记录级别,notice是适合生产环境的
 3 logfile "Logs/redis6380_log.txt"          #指定log的保持路径,默认是创建在Redis安装目录下,如果有子目录需要手动创建,如此处的Logs目录
 4 syslog-enabled yes                        #是否使用系统日志
 5 syslog-ident redis6380                    #在系统日志的标识名
 6 appendonly yes                            #数据的保存为aof格式
 7 appendfilename "appendonly.6380.aof"      #数据保存文件
 8 cluster-enabled yes                       #是否开启集群
 9 cluster-config-file nodes.6380.conf
10 cluster-node-timeout 15000
11 cluster-slave-validity-factor 10
12 cluster-migration-barrier 1
13 cluster-require-full-coverage yes

将上述配置文件保存到Redis目录下,并使用这些配置文件安装6个redis服务,命令如下:

D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6380.conf --service-name redis6380
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6381.conf --service-name redis6381
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6382.conf --service-name redis6382
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6383.conf --service-name redis6383
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6384.conf --service-name redis6384
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-install D:/Redis-Cluster/Redis-x64-3.2.100/redis.6385.conf --service-name redis6385

注意:

1)redis.6380.conf等配置文件最好使用完整路径,避免重启Redis集群出现问题

2)卸载命令为:

D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6380.conf --service-name redis6380
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6381.conf --service-name redis6381
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6382.conf --service-name redis6382
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6383.conf --service-name redis6383
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6384.conf --service-name redis6384
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-uninstall D:/Redis-Cluster/Redis-x64-3.2.100/redis.6385.conf --service-name redis6385

启动这6个服务,命令如下:

D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6380
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6381
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6382
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6383
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6384
D:/Redis-Cluster/Redis-x64-3.2.100/redis-server.exe --service-start --service-name redis6385

执行结果:

安装ruby

1)Ruby环境安装。

双击下载的“rubyinstaller-2.2.4-x64.exe”安装即可,同样,为了操作方便,也是建议安装在盘符根目录下,如: C:\Ruby22-x64 ,安装时这里选中后两个选项,

意思是将ruby添加到系统的环境变量中,在cmd命令中能直接使用ruby的命令

2)安装Ruby环境下Redis的驱动

将下载的"Ruby环境下Redis的驱动文件(redis-3.2.2.gem)"拷贝到Ruby安装根目录(C:\Ruby22-x64)下。

然后执行安装命令如下:

gem install --local path_to_gem/filename.gem  

创建Redis集群

将下载的“创建Redis集群的ruby脚本文件redis-trib.rb”文件拷贝到Redis安装根目录(D:\Redis-Cluster\Redis-x64-3.2.100)下。

1)使用redis-trib.rb来创建Redis集群

MD下切换到Redis目录(D:\Redis-Cluster\Redis-x64-3.2.100)

D:/Redis-Cluster/Redis-x64-3.2.100/redis-trib.rb create --replicas 1 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 127.0.0.1:6385
D:\Redis-Cluster\Redis-x64-3.2.100>redis-trib.rb create --replicas 1 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 127.0.0.1:6385
>>> Creating cluster
Connecting to node 127.0.0.1:6380: OK
Connecting to node 127.0.0.1:6381: OK
Connecting to node 127.0.0.1:6382: OK
Connecting to node 127.0.0.1:6383: OK
Connecting to node 127.0.0.1:6384: OK
Connecting to node 127.0.0.1:6385: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:6380
127.0.0.1:6381
127.0.0.1:6382
Adding replica 127.0.0.1:6383 to 127.0.0.1:6380
Adding replica 127.0.0.1:6384 to 127.0.0.1:6381
Adding replica 127.0.0.1:6385 to 127.0.0.1:6382
M: bb6ef615bb0ae13275943caec0db9d30b9f35c5e 127.0.0.1:6380   slots:0-5460      (5461 slots) master
M: b4d120f2983ad683f7b68992e1ba414722238db7 127.0.0.1:6381   slots:5461-10922  (5462 slots) master
M: 837779b3965e2c9d4dd4385750aaaaf9a9039fb0 127.0.0.1:6382   slots:10923-16383 (5461 slots) master
S: 5d154137180284d926ef51a91fc75f9438249ef8 127.0.0.1:6383   replicates bb6ef615bb0ae13275943caec0db9d30b9f35c5e
S: ad151680a3e36cf2083ef822be0bdb075a7d36de 127.0.0.1:6384   replicates b4d120f2983ad683f7b68992e1ba414722238db7
S: 9a2260a5a6a2add84b622a453a6a7b86a29d180d 127.0.0.1:6385   replicates 837779b3965e2c9d4dd4385750aaaaf9a9039fb0
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:6380)M: bb6ef615bb0ae13275943caec0db9d30b9f35c5e 127.0.0.1:6380   slots:0-5460      (5461 slots) master
M: b4d120f2983ad683f7b68992e1ba414722238db7 127.0.0.1:6381   slots:5461-10922  (5462 slots) master
M: 837779b3965e2c9d4dd4385750aaaaf9a9039fb0 127.0.0.1:6382   slots:10923-16383 (5461 slots) master
M: 5d154137180284d926ef51a91fc75f9438249ef8 127.0.0.1:6383   slots:            (0 slots)    master   replicates bb6ef615bb0ae13275943caec0db9d30b9f35c5e
M: ad151680a3e36cf2083ef822be0bdb075a7d36de 127.0.0.1:6384   slots:            (0 slots)    master   replicates b4d120f2983ad683f7b68992e1ba414722238db7
M: 9a2260a5a6a2add84b622a453a6a7b86a29d180d 127.0.0.1:6385   slots:            (0 slots)    master   replicates 837779b3965e2c9d4dd4385750aaaaf9a9039fb0
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

备注:

1)--replicas #指定集群中每个主节点配备几个从节点,这里设置为1。

2) redis-trib.rb工具的使用

1、create:创建集群
2、check:检查集群
3、info:查看集群信息
4、fix:修复集群
5、reshard:在线迁移slot
6、rebalance:平衡集群节点slot数量
7、add-node:将新节点加入集群
8、del-node:从集群中删除节点
9、set-timeout:设置集群节点间心跳连接的超时时间
10、call:在集群全部节点上执行命令
11、import:将外部redis数据导入集群

2)检验是否真的创建成功

输入以下命令:

redis-trib.rb check 127.0.0.1:6380

如果现实信息如下,则说明创建的Redis集群是没问题。

D:\Redis-Cluster\Redis-x64-3.2.100>redis-trib.rb check 127.0.0.1:6380
Connecting to node 127.0.0.1:6380: OK
Connecting to node 127.0.0.1:6383: OK
Connecting to node 127.0.0.1:6382: OK
Connecting to node 127.0.0.1:6384: OK
Connecting to node 127.0.0.1:6385: OK
Connecting to node 127.0.0.1:6381: OK
>>> Performing Cluster Check (using node 127.0.0.1:6380)
M: bb6ef615bb0ae13275943caec0db9d30b9f35c5e 127.0.0.1:6380   slots:0-5460      (5461 slots) master   1 additional replica(s)
S: 5d154137180284d926ef51a91fc75f9438249ef8 127.0.0.1:6383   slots:            (0 slots)    slave    replicates bb6ef615bb0ae13275943caec0db9d30b9f35c5e
M: 837779b3965e2c9d4dd4385750aaaaf9a9039fb0 127.0.0.1:6382   slots:10923-16383 (5461 slots) master   1 additional replica(s)
S: ad151680a3e36cf2083ef822be0bdb075a7d36de 127.0.0.1:6384   slots:            (0 slots)    slave    replicates b4d120f2983ad683f7b68992e1ba414722238db7
S: 9a2260a5a6a2add84b622a453a6a7b86a29d180d 127.0.0.1:6385   slots:            (0 slots)    slave    replicates 837779b3965e2c9d4dd4385750aaaaf9a9039fb0
M: b4d120f2983ad683f7b68992e1ba414722238db7 127.0.0.1:6381   slots:5461-10922  (5462 slots) master   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

D:\Redis-Cluster\Redis-x64-3.2.100>

3)信息查询

使用Redis客户端Redis-cli.exe来查看数据记录数,以及集群相关信息

D:\Redis-Cluster\Redis-x64-3.2.100>redis-cli.exe -h 127.0.0.1 -p 6380
127.0.0.1:6380> cluster nodes
5d154137180284d926ef51a91fc75f9438249ef8 127.0.0.1:6383 slave          bb6ef615bb0ae13275943caec0db9d30b9f35c5e 0 1560690706115 4 connected
bb6ef615bb0ae13275943caec0db9d30b9f35c5e 127.0.0.1:6380 myself,master  -                                        0 0             1 connected 0-5460
837779b3965e2c9d4dd4385750aaaaf9a9039fb0 127.0.0.1:6382 master         -                                        0 15606907021143  connected 10923-16383
ad151680a3e36cf2083ef822be0bdb075a7d36de 127.0.0.1:6384 slave          b4d120f2983ad683f7b68992e1ba414722238db7 0 1560690705116 5 connected
9a2260a5a6a2add84b622a453a6a7b86a29d180d 127.0.0.1:6385 slave          837779b3965e2c9d4dd4385750aaaaf9a9039fb0 0 1560690703615 6 connected
b4d120f2983ad683f7b68992e1ba414722238db7 127.0.0.1:6381 master         -                                        0 15606907071152  connected 5461-10922
127.0.0.1:6380> dbsize
(integer) 0
127.0.0.1:6380>

原文地址:https://www.cnblogs.com/yy3b2007com/p/11033009.html

时间: 2024-11-02 23:37:09

在Windows系统下搭建Redis集群的相关文章

windows环境下搭建redis集群

Redis.Ruby语言运行环境.Redis的Ruby驱动redis-xxxx.gem.创建Redis集群的工具redis-trib.rb(注意:Redis集群需要至少3个以上节点,低于3个无法创建) 1.下载(zip格式)并安装Redis:(https://github.com/MSOpenTech/redis/releases/) 1)将下载到的Redis-x64-3.0.504.zip解压即可,为了方便使用,建议放在盘符根目录下,并修改目录名为Redis,如:D:\Redis 2)通过配置

Windows环境下搭建rabbitmq集群与负载

欢迎提出意见及建议,发现错误请留言 需要的文件下载: 百度云:链接:https://pan.baidu.com/s/1gpZa2NjNxviEnihjS2Viuw  提取码:39hi  复制这段内容后打开百度网盘手机App,操作更方便哦 蓝奏云:下载:https://www.lanzous.com/i54x5da 密码:cgb9 参考博文: https://blog.csdn.net/elie_yang/article/details/86657851 https://blog.csdn.net

Windows下搭建Redis集群

Redis集群:运行多个Redis实例,然后通过特定的工具,将这些实例以某种关系连接起来,形成一个Redis网络. 详细的内容可以阅读:Redis 集群教程 里面会详细介绍Redis集群的设计思想和内部结构,以及如何搭建Redis集群等. 本文主要讲述如何在Windows系统下快速搭建Redis集群: 1.下载Redis 其GitHub连接如下:https://github.com/MSOpenTech/redis/releases/ Redis提供msi和zip格式的下载文件,这里下载zip格

Redis → Windows下搭建redis集群

一,redis集群介绍 Redis cluster(redis集群)是在版本3.0后才支持的架构,和其他集群一样,都是为了解决单台服务器不够用的情况,也防止了主服务器宕机无备用服务器,多个节点网络互联数据共享,所有节点都是一主一从(也可以一主多从),其中不提供服务,只做为备份,emmm我就不多说废话了,直接进入主题. 没有多的服务器就只能单机搭建集群了 原文地址:https://www.cnblogs.com/BalmyLee/p/12019398.html

centos下搭建redis集群

必备的工具: redis-3.0.0.tar redis-3.0.0.gem   (ruby和redis接口) 分析:     首先,集群数需要基数,这里搭建一个简单的redis集群(6个redis实例进行集群). 在一台服务器上操作,因此仅需要6个不同的端口号即可.分别是:7001.7002.7003.7004.7005.7006. 步骤:     1.上传redis-3.0.0.tar到服务器(自己指定自己的软件目录),解压redis-3.0.0.tar. 2.安装c语言环境(安装cento

在windows环境下搭建mysql集群

1. 前(fei)言(hua) 最近实训老师给我们布置了一个建立mysql集群的任务,并扔了两个博客链接给我们参考,然后就没有然后了.根据老师给的博客上面的步骤试了一下,发现并不能成功建立,于是自己百度,找到了一个挺靠谱的博客,于是参考了一下,感觉总体还是不错的~ 靠谱的博客: http://blog.csdn.net/mazhaojuan/article/details/42211857 2. 理论基础知识 首先需要了解什么是管理节点.数据节点和SQL节点~ (1)管理结点:从名字可以看出来,

Windows 环境搭建Redis集群

环境以及引用资料 1.windows server 2008 r2 enterprise  (木有办法,公司的服务器全是如此,就这种环境搭建吧) 2.redis官方资料下载: https://redis.io/download 3.redis官方没有提供相关的程序包,但是Microsoft Open Tech group提供并维护了相关的redis安装包 https://github.com/MSOpenTech/redis(只是提供64位程序) 这里说一句,很多公司的redis都是部署在lin

在windows上搭建redis集群

一 所需软件 Redis.Ruby语言运行环境.Redis的Ruby驱动redis-xxxx.gem.创建Redis集群的工具redis-trib.rb 二 安装配置redis redis下载地址   https://github.com/MSOpenTech/redis/releases ;  下载Redis. 集群规划有三个节点的集群,每个节点有一主一备.需要6台虚拟机. 把 redis 解压后,再复制出 5 份,配置 三主三从集群. 由于 redis 默认端口号为 6379,那么其它5份的

windows下安装redis集群

前几天在自己在本机win10 电脑下部署了redis集群. 主要通过的是网上两个博客: 如何在windows下部署redis集群:https://blog.csdn.net/zsg88/article/details/73715947 redis的一些操作:https://blog.csdn.net/mlc1218559742/article/details/52640180 原文地址:https://www.cnblogs.com/tuanz/p/9359037.html