【Azure Redis 缓存】Windows版创建 Redis Cluster 实验 (精简版)

本文涉及的产品
云数据库 Redis 版,标准版 2GB
推荐场景:
搭建游戏排行榜
云原生内存数据库 Tair,内存型 2GB
简介: 【Azure Redis 缓存】Windows版创建 Redis Cluster 实验 (精简版)

简介

学习Redis Cluster的第一步,即本地搭建Redis Cluster。但是在Redis的官方文档中,是介绍在Linux系统中搭建Redis Cluster。本文主要介绍在Windows系统中如何快速创建一个3主/3从的Redis Cluster(Redis集群)。

 

 

准备工具

1)在GitHub中下载由Microsoft发布的Windows版Redis文件(当前最新版本为3.2.100, 下载ZIP文件,解压后双击 redis-server.exe 就可以启用一个单机的Reids服务)。下载地址:https://github.com/MicrosoftArchive/redis/releases

 

2)Redis 3版本需要使用  redis-trib.rb create 来执行集群的创建工作,也需要从Github中下载 redis-trib.rb文件(如无法下载,可在本文的附录中复制)。下载地址:https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb

 

3)Ruby 运行环境(因为redis-trib.rb是Ruby语言编写,所以需要在Windows本机中安装Ruby运行环境)。下载地址:https://rubyinstaller.org/downloads/

 

4)Ruby Redis驱动 Redis gem。下载地址:https://rubygems.org/gems/redis/versions/4.5.1

For Redis version 3 or 4, there is the older tool called redis-trib.rb which is very similar. You can find it in the src directory of the Redis source code distribution. You need to install redis gem to be able to run redis-trib.

Source: https://redis.io/topics/cluster-tutorial#creating-the-cluster

 

 

第一步:准备Redis配置文件(redis.conf)

创建 cluster_test文件夹,这次实验使用7000,7001,7002,7003,7004,7005 这六个端口。

mkdir cluster-test

cd cluster-test

mkdir 7000 7001 7002 7003 7004 7005

分别创建好这个6个子文件夹后,创建redis.conf文件,把下面最基本的配置文件内容分别放在在这六个文件夹中

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

注: 每个子文件夹中的端口需要对应修改为7001,... 7005。

最终效果为:

第二步:分别启动6个Redis

复制redis-server.exe文件到cluster-test中,然后打开6个CMD窗口,分别进入到7000, ... 7005 目录中。运行启动Redis Service命令

..\redis-server .\redis.conf

注:需要在6个CMD中对7000,7001,7002,7003,7004,7005 启动Reids Server

第三步:  安装Ruby运行环境

双击安装即可,所有选项保持默认。

第四步:安装Redis的驱动 Redis gem

复制 redis-4.5.1.gem 文件到Ruby的安装目录,运行   gem install --local C:\Ruby30-x64\redis-4.5.1.gem   ,等待安装成功。

第五步:redis-trib.rb create 创建集群

把下载的redis-trib.rb文件放在cluster_test目录中,CMD窗口进入 cluster_test 目录,执行 redis-trib.rb create

redis-trib.rb create --replicas 1 127.0.0.1:7000 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

当从日志中看见 [OK] All 16384 slots covered日志,表示集群创建完成。表示至少一个主节点可以对16384个槽(slots)提供服务了。

创建动画图:

 

 

测试验证

使用 redis-cli.exe 工具(包含Redis的下载ZIP文件中)可以非常容易的查看Cluster Node信息和 Set, Get Key

redis-cli.exe -c -p 7000
redis 127.0.0.1:7000> set foo bar
-> Redirected to slot [12182] located at 127.0.0.1:7002
OK
redis 127.0.0.1:7002> set hello world
-> Redirected to slot [866] located at 127.0.0.1:7000
OK
redis 127.0.0.1:7000> get foo
-> Redirected to slot [12182] located at 127.0.0.1:7002
"bar"
redis 127.0.0.1:7002> get hello
-> Redirected to slot [866] located at 127.0.0.1:7000
"world"

使用 cluster nodes查看节点信息:

 

附件1:redis-trib.rb 文件内容

View Code

 

附件2:如何设置Cluster的密码

1) 使用 redis-cli.exe -c -p 7000 连接到集群

2) 使用 CONFIG SET requirepass "mypassword" 设置密码

3) 重新连接:redis-cli.exe -c -p 7000 -a password@123

#Set a Password
CONFIG SET requirepass "mypassword"
#设置密码后的连接方式:
C:\tool\cluster-test>redis-cli.exe -c -p 7000
127.0.0.1:7000> ping
(error) NOAUTH Authentication required.
127.0.0.1:7000> auth password@123
OK
127.0.0.1:7000> get message1
"value11111"
127.0.0.1:7000> exit
C:\tool\cluster-test>redis-cli.exe -c -p 7000 -a password@123
127.0.0.1:7000> ping
PONG
127.0.0.1:7000> cluster nodes

 

参考资料

Redis Cluster turorial: https://redis.io/topics/cluster-tutorial#creating-the-cluster

在Windows系统下搭建Redis集群: https://www.cnblogs.com/yy3b2007com/p/11033009.html

 

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
25天前
|
NoSQL 网络协议 Redis
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
|
25天前
|
NoSQL 安全 网络安全
【Azure Redis】PHPRedis遇见SSL Connection Timeout问题
【Azure Redis】PHPRedis遇见SSL Connection Timeout问题
【Azure Redis】PHPRedis遇见SSL Connection Timeout问题
|
25天前
|
NoSQL Redis 容器
【Azure Cache for Redis】Redis的导出页面无法配置Storage SAS时通过az cli来完成
【Azure Cache for Redis】Redis的导出页面无法配置Storage SAS时通过az cli来完成
|
25天前
|
存储 NoSQL Redis
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
【Azure Developer】一个复制Redis Key到另一个Redis服务的工具(redis_copy_net8)
|
25天前
|
Kubernetes NoSQL Redis
【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server
【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server
【Azure Redis】部署在AKS中的应用连接Redis时候出现Unable to connect to Redis server
|
25天前
|
NoSQL Redis
【Azure Redis】中国区Redis在东三区的资源无法在通过门户上与北三区资源之间建立灾备链接
【Azure Redis】中国区Redis在东三区的资源无法在通过门户上与北三区资源之间建立灾备链接
【Azure Redis】中国区Redis在东三区的资源无法在通过门户上与北三区资源之间建立灾备链接
|
25天前
|
NoSQL 网络协议 Linux
【AKS+Redis】AKS中客户端(ioredis)遇见Azure Redis服务Failover后链接中断的可能性
【AKS+Redis】AKS中客户端(ioredis)遇见Azure Redis服务Failover后链接中断的可能性
|
25天前
|
网络安全 API 数据安全/隐私保护
【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Windows)
【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Windows)
|
25天前
|
NoSQL Redis C++
【Azure Redis】对Azure Redis服务指标解释(Connections Created/Closed Per Second VS Connected Clinents)
【Azure Redis】对Azure Redis服务指标解释(Connections Created/Closed Per Second VS Connected Clinents)
|
25天前
|
NoSQL 网络协议 Linux
【Azure Redis】Lettuce客户端遇见连接Azure Redis长达15分钟的超时
【Azure Redis】Lettuce客户端遇见连接Azure Redis长达15分钟的超时