Undermoon - 手动设置 Redis 集群

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: Undermoon - 手动设置 Redis 集群

架构



我们将在一台机器上部署以下所有部件:

  • mem_broker(内存代理)
  • coordinator(协调器)
  • 2 个代理与 4Redis 节点


image.png


构建二进制文件



$ cargo build


请注意,您还需要安装 Redis


部署 Memory Broker



$ RUST_LOG=undermoon=debug,mem_broker=debug UNDERMOON_ADDRESS=127.0.0.1:7799 target/debug/mem_broker


部署 Coordinator



运行 coordinator 并指定 memory broker 地址。


$ RUST_LOG=undermoon=debug,coordinator=debug UNDERMOON_BROKER_ADDRESS=127.0.0.1:7799 target/debug/coordinator


部署 Server Proxy 与 Redis



Chunk


有关详细说明,请参阅:Rust 写的 Undermoon Redis 集群 - Chunk


image.png


运行 Server Proxy 与 Redis


运行 2 个服务器代理和 4Redis 节点:


# You need to run each line in different terminals
# The first half
$ redis-server --port 7001
$ redis-server --port 7002
$ RUST_LOG=undermoon=debug,server_proxy=debug UNDERMOON_ADDRESS=127.0.0.1:6001 target/debug/server_proxy
# The second Half
$ redis-server --port 7003
$ redis-server --port 7004
$ RUST_LOG=undermoon=debug,server_proxy=debug UNDERMOON_ADDRESS=127.0.0.1:6002 target/debug/server_proxy


将 Server Proxy 和 Redis 注册到 Memory Broker


Redis 集群永远无法在单台机器上创建。即使我们有足够的 nodeMemory broker 也无法创建集群,因为它们似乎都在同一主机 127.0.0.1 中;

但是由于我们在一台机器上部署了整个 undermoon 集群,我们需要通过在发布的 json 中将 host 字段指定为 localhost1localhost2 来明确告诉 memory broker 它们在不同的主机中。


curl -XPOST -H 'Content-Type: application/json' "http://localhost:7799/api/v3/proxies/meta" -d '{"proxy_address": "127.0.0.1:6001", "nodes": ["127.0.0.1:7001", "127.0.0.1:7002"], "host": "localhost1"}'
curl -XPOST -H 'Content-Type: application/json' "http://localhost:7799/api/v3/proxies/meta" -d '{"proxy_address": "127.0.0.1:6002", "nodes": ["127.0.0.1:7003", "127.0.0.1:7004"], "host": "localhost2"}'


现在我们有 2 个服务器代理与 4 个节点。


$ curl http://localhost:7799/api/v3/proxies/addresses
{"addresses":["127.0.0.1:6001","127.0.0.1:6002"]}
$ curl http://localhost:7799/api/v3/proxies/meta/127.0.0.1:6001
{"proxy":{"address":"127.0.0.1:6001","epoch":2,"nodes":[],"free_nodes":["127.0.0.1:7001","127.0.0.1:7002"],"peers":[],"clusters_config":{}}}
$ curl http://localhost:7799/api/v3/proxies/meta/127.0.0.1:6002
{"proxy":{"address":"127.0.0.1:6002","epoch":2,"nodes":[],"free_nodes":["127.0.0.1:7003","127.0.0.1:7004"],"peers":[],"clusters_config":{}}}


创建集群


使用 4Redis 节点创建一个名为 mycluster 的集群。


$ curl -XPOST -H 'Content-Type: application/json' http://localhost:7799/api/v3/clusters/meta/mycluster -d '{"node_number": 4}'


现在我们可以连接到集群:


$ redis-cli -h 127.0.0.1 -p 6001 -c
127.0.0.1:6001> cluster nodes
mycluster___________2261c530e98070a6____ 127.0.0.1:6001 myself,master - 0 0 3 connected 8192-16383
mycluster___________ad095468b9deeb2d____ 127.0.0.1:6002 master - 0 0 3 connected 0-8191
127.0.0.1:6001> get a
(nil)
127.0.0.1:6001> get b
-> Redirected to slot [3300] located at 127.0.0.1:6002
"1"
相关实践学习
基于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
相关文章
|
2月前
|
监控 NoSQL Redis
看完这篇就能弄懂Redis的集群的原理了
看完这篇就能弄懂Redis的集群的原理了
56 0
|
1月前
|
NoSQL Linux Redis
Linux Redis 服务设置开机自启动
【9月更文挑战第2天】在 Linux 系统中,可使用两种方法设置 Redis 开机自启动:一是通过创建 `redis.service` 文件并利用 systemd 进行管理,包括定义服务参数和启动脚本;二是编辑 `/etc/rc.local` 文件,在其中添加启动命令。推荐使用 systemd 方法,因为它更符合现代 Linux 系统的设计理念。设置完成后,可通过 `sudo systemctl status redis.service` 检查服务状态。
|
2月前
|
存储 缓存 NoSQL
【Azure Redis 缓存 Azure Cache For Redis】如何设置让Azure Redis中的RDB文件暂留更久(如7天)
【Azure Redis 缓存 Azure Cache For Redis】如何设置让Azure Redis中的RDB文件暂留更久(如7天)
|
2月前
|
NoSQL Redis
Redis——批量设置key的过期时间
Redis——批量设置key的过期时间
33 1
|
2月前
|
NoSQL 网络安全 Redis
用python安装redis并设置服务自启
用python安装redis并设置服务自启
18 0
|
2月前
|
NoSQL Redis
Redis——单机迁移cluster集群如何快速迁移
Redis——单机迁移cluster集群如何快速迁移
49 0
|
2月前
|
NoSQL Redis
Redis——设置最大内存 | key淘汰机制
Redis——设置最大内存 | key淘汰机制
42 0
|
2月前
|
NoSQL Linux Redis
使用docker-compose搭建redis-cluster集群
使用docker-compose搭建redis-cluster集群
228 0
|
2月前
|
NoSQL Linux Redis
基于redis6搭建集群
基于redis6搭建集群
下一篇
无影云桌面