前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Undermoon - 手动设置 Redis 集群

Undermoon - 手动设置 Redis 集群

作者头像
为少
发布2022-03-31 19:23:22
4970
发布2022-03-31 19:23:22
举报
文章被收录于专栏:黑客下午茶黑客下午茶

项目地址:https://github.com/doyoubi/undermoon

本教程将引导您完成手动设置 undermoon 集群的过程,以更好地了解 undermoon 的工作原理。

架构

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

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

构建二进制文件

代码语言:javascript
复制
$ cargo build

请注意,您还需要安装 Redis

部署 Memory Broker

代码语言:javascript
复制
$ RUST_LOG=undermoon=debug,mem_broker=debug UNDERMOON_ADDRESS=127.0.0.1:7799 target/debug/mem_broker

部署 Coordinator

运行 coordinator 并指定 memory broker 地址。

代码语言:javascript
复制
$ 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

运行 Server Proxy 与 Redis

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

代码语言:javascript
复制
# 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 它们在不同的主机中。

代码语言:javascript
复制
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 个节点。

代码语言:javascript
复制
$ 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 的集群。

代码语言:javascript
复制
$ curl -XPOST -H 'Content-Type: application/json' http://localhost:7799/api/v3/clusters/meta/mycluster -d '{"node_number": 4}'

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

代码语言:javascript
复制
$ 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"
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-01-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 黑客下午茶 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 架构
  • 构建二进制文件
  • 部署 Memory Broker
  • 部署 Coordinator
  • 部署 Server Proxy 与 Redis
    • Chunk
      • 运行 Server Proxy 与 Redis
      • 将 Server Proxy 和 Redis 注册到 Memory Broker
      • 创建集群
      相关产品与服务
      云数据库 Redis
      腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档