当前位置:网站首页>windows下Redis-cluster集群搭建
windows下Redis-cluster集群搭建
2022-07-05 04:26:00 【十一姐】
一、下载安装
需要下载如下三个:
Redis、Ruby语言运行环境、Redis的Ruby驱动redis-3.2.2.gem
1、Redis-x64-5.0.14.1.zip 下载, 6 台 redis 服务器,搭建伪集群,并运行在不同的端口 6380-6385
2、Ruby下载,ruby脚本来实现集群搭建,一路next,最后取消勾选,finish,然后cmd里面输出
ruby -v
代表安装成功3、安装Redis的Ruby驱动rubygems下载,是一个用于对 Ruby组件进行打包的 Ruby 打包系统;下载后解压,然后打开命令窗口切换到解压目录中,执行命令
ruby setup.rb
二、搭建Redis集群
要让集群正常运作至少需要3个主节点,建议配置3个主节点,其余3个作为各个主节点的从节点(也是官网推荐的模式),通过同一台电脑不同端口模拟
1、新建一个文件夹Redis-cluster,并将前面下载的
Redis-x64-5.0.14.1.zip
进行解压,并将文件夹重命名为63802、打开6380目录下的文件
redis.windows.conf
,修改里面的端口号port为6380,主要改了如下五处,1. port 6380 //修改为与当前文件夹名字一样的端口号 2. appendonly yes //指定是否在每次更新操作后进行日志记录,Redis在 默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导4. 致一段时间内的数据丢失。 yes表示:存储方式,aof,将写操作记录保存到日志中 3. cluster-enabled yes //开启集群模式 4. cluster-config-file nodes-6380.conf //保存节点配置,自动创建,自动更新(建议命名时加上端口号) 5. cluster-node-timeout 15000 //集群超时时间,节点超过这个时间没反应就断定是宕机
3、在6380目录下新建文件
start.bat
,内容如下,用来进入每个端口命名的文件夹下启动服务title redis-6380 redis-server.exe redis.windows.conf
4、复制6380文件夹,并分别重命名为6381-6385,同时修改各自目录下的
redis.windows.con
与start.bat
文件里面的端口号,将6380替换成对应的6381-63855、打开任意cmd窗口执行
gem install redis
6、构建集群脚本,从6380目录下复制粘贴
redis-cli.exe
到Redis-cluster目录下,同时6380~6385每个目录下的start.bat文件双击运行并不要关闭!!!
7、然后在当前Redis-cluster目录下打开cmd窗口,执行如下命令,到此集群构建完毕
redis-cli --cluster create 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 --cluster-replicas 1
三、集群环境测试
- 参考文档
redis-cli -c -h 127.0.0.1 -p 6380
- 查看集群信息:
cluster info
- 查看主从关系:
info replication
, 集群节点按照从主到从的方式从左到右依次排列6个redis 节点,因此也可以看出6380,6381,6382三个是主节点,6383,6384,6385是三个从节点,对应关系是:主6380从6383 - 查看各个节点分配slot:
cluster nodes
四、将redis-cluster注册生windows服务
控制台启动redis server如果控制台关闭了之后redis server也会一同被关闭,那么我们就需要让redis在后台运行需要将redis server注册为windows服务,然后再start
所以我们用如下方式可以解决上面的问题,到6380-6385目录下分别重命名服务,并启动,
请至少保证三个主节点服务已经启动在后台,否则会导致连接上redis-cluster,但是连不上里面的db0
# 通过service-name启动redis服务: redis-server --service-install redis.windows.conf --service-name redis6380 --loglevel verbose redis-server --service-start --service-name redis6380 # 通过service-name停止redis服务: redis-server --service-stop --service-name redis6380
如果服务启动失败,以管理员身份打开cmd执行
SC delete 服务名称
,然后当对应目录重新建服务
五、打开redis可视化工具,如图连接成功
- 如图,测试连接成功
- 默认是127.0.0.1可以访问,如下修改.conf,可以修改bind指定局域网ip访问,
修改配置后,需要重启服务方可生效
边栏推荐
- [Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
- Power management bus (pmbus)
- A real day for Beijing programmers!!!!!
- 蛇形矩阵
- OWASP top 10 vulnerability Guide (2021)
- 直播预告 | 容器服务 ACK 弹性预测最佳实践
- 快手、抖音、视频号交战内容付费
- 函数(基本:参数,返回值)
- Realize the attention function of the article in the applet
- Machine learning decision tree
猜你喜欢
Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...
[phantom engine UE] the difference between running and starting, and the analysis of common problems
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
Seven join join queries of MySQL
mxnet导入报各种libcudart*.so、 libcuda*.so找不到
How to realize real-time audio and video chat function
Hypothesis testing -- learning notes of Chapter 8 of probability theory and mathematical statistics
WeNet:面向工业落地的E2E语音识别工具
3 minutes learn to create Google account and email detailed tutorial!
【虚幻引擎UE】实现背景模糊下近景旋转操作物体的方法及踩坑记录
随机推荐
Longyuan war "epidemic" 2021 network security competition web easyjaba
This is an age of uncertainty
解密函数计算异步任务能力之「任务的状态及生命周期管理」
Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
How to realize real-time audio and video chat function
指针函数(基础)
网络安全-记录web漏洞修复
Hexadecimal to decimal
函數(易錯)
Function (error prone)
WGS84 coordinate system, web Mercator, gcj02 coordinate system, bd09 coordinate system - brief introduction to common coordinate systems
Is "golden nine and silver ten" the best time to find a job? Not necessarily
MacBook安装postgreSQL+postgis
Machine learning decision tree
Burpsuite grabs app packets
【虚幻引擎UE】实现背景模糊下近景旋转操作物体的方法及踩坑记录
Fonction (sujette aux erreurs)
open graph协议
OWASP top 10 vulnerability Guide (2021)
如何优雅的获取每个分组的前几条数据