使用 Docker Compose 运行 Undermoon

本文涉及的产品
云数据库 Redis 版,标准版 2GB
推荐场景:
搭建游戏排行榜
云原生内存数据库 Tair,内存型 2GB
简介: 使用 Docker Compose 运行 Undermoon

以下示例使用 docker 创建一个 undermoon 集群。

要求:


  • docker-compose
  • redis-cli
  • jq


在 docker-compose 中运行集群

直接下载并运行集群:


$ make docker-mem-broker-example


或者自己构建并运行 undermoon docker 镜像:


$ make docker-build-test-image
$ make docker-mem-broker


注册代理


一切就绪后,运行初始化脚本,通过 HTTP API 注册存储资源:


$ ./examples/mem-broker/init.sh


我们有 6 个可用的代理。


$ curl http://localhost:7799/api/v3/proxies/addresses


创建集群


由于每个代理都有 2 个对应的 Redis 节点,所以我们总共有 12 个节点。请注意,集群的数量只能是 4 的倍数。让我们创建一个有 4 个节点的集群。


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


在连接到集群之前,您需要将这些主机添加到您的 /etc/hosts 中:


# /etc/hosts
127.0.0.1 server_proxy1
127.0.0.1 server_proxy2
127.0.0.1 server_proxy3
127.0.0.1 server_proxy4
127.0.0.1 server_proxy5
127.0.0.1 server_proxy6


让我们检查一下我们的集群。它是由一些随机选择的代理创建的。我们需要先找出它们。请注意,您需要安装 jq 命令以轻松解析以下命令的 json


# List the proxies of the our "mycluster`:
$ curl -s http://localhost:7799/api/v3/clusters/meta/mycluster | jq '.cluster.nodes[].proxy_address' | uniq
"server_proxy5:6005"
"server_proxy6:6006"


为集群 mycluster 选择上面的代理地址之一(在我的例子中是 server_proxy5:6005)并连接到它。


# Add `-c` to enable cluster mode:
$ redis-cli -h server_proxy5 -p 6005 -c
# List the proxies:
server_proxy5:6005> cluster nodes
mycluster___________d71bc00fbdddf89_____ server_proxy5:6005 myself,master - 0 0 7 connected 0-8191
mycluster___________8de73f9146386295____ server_proxy6:6006 master - 0 0 7 connected 8192-16383
# Send out some requests:
server_proxy5:6005> get a
-> Redirected to slot [15495] located at server_proxy6:6006
(nil)
server_proxy6:6006> get b
-> Redirected to slot [3300] located at server_proxy5:6005
(nil)


Great! 我们可以像使用官方的 Redis 集群一样使用我们创建的集群。


扩大规模


它实际上有 4Redis 节点。


# List the nodes of the our "mycluster`:
$ curl -s http://localhost:7799/api/v3/clusters/meta/mycluster | jq '.cluster.nodes[].address'
"redis9:6379"
"redis10:6379"
"redis11:6379"
"redis12:6379"


其中两个是 master,另外两个是 replica

让我们扩展到 8 个节点:


# Add 4 nodes
$ curl -XPATCH -H 'Content-Type: application/json' \
    http://localhost:7799/api/v3/clusters/nodes/mycluster -d '{"node_number": 4}'
# Start migrating the data
$ curl -XPOST http://localhost:7799/api/v3/clusters/migrations/expand/mycluster


现在我们有 4 个服务器代理:


$ redis-cli -h server_proxy5 -p 6005 -c
server_proxy5:6005> cluster nodes
mycluster___________d71bc00fbdddf89_____ server_proxy5:6005 myself,master - 0 0 12 connected 0-4095
mycluster___________8de73f9146386295____ server_proxy6:6006 master - 0 0 12 connected 8192-12287
mycluster___________be40fe317baf2cf7____ server_proxy2:6002 master - 0 0 12 connected 4096-8191
mycluster___________9434df4158f3c5a4____ server_proxy4:6004 master - 0 0 12 connected 12288-16383


8 个节点:


# List the nodes of the our "mycluster`:
$ curl -s http://localhost:7799/api/v3/clusters/meta/mycluster | jq '.cluster.nodes[].address'
"redis9:6379"
"redis10:6379"
"redis11:6379"
"redis12:6379"
"redis3:6379"
"redis4:6379"
"redis7:6379"
"redis8:6379"


故障转移


如果你关闭任何一个 proxyreplica 就会被提升为 master。并且只要整个 undermoon 集群有剩余的空闲 proxy,它可以自动替换失效的 proxy


# List the proxies of the our "mycluster`:
$ curl -s http://localhost:7799/api/v3/clusters/meta/mycluster | jq '.cluster.nodes[].proxy_address' | uniq
"server_proxy5:6005"
"server_proxy6:6006"
"server_proxy2:6002"
"server_proxy4:6004"


让我们在这里关闭其中一个代理,例如 server_proxy5:6005


$ docker ps | grep server_proxy5 | awk '{print $1}' | xargs docker kill


undermoon 会检测到故障,更换故障 proxy,提升新的 master,并将新的 replica 添加到新的 master


# server_proxy5 is replaced by server_proxy3
$ curl -s http://localhost:7799/api/v3/clusters/meta/mycluster | jq '.cluster.nodes[].proxy_address' | uniq
"server_proxy3:6003"
"server_proxy6:6006"
"server_proxy2:6002"
"server_proxy4:6004"


现在我们可以从 undermoon 集群中删除 server_proxy3 了。


$ curl -XDELETE http://localhost:7799/api/v3/proxies/meta/server_proxy3:6003
相关实践学习
基于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
相关文章
|
21天前
|
JSON JavaScript 开发者
Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
【8月更文挑战第7天】Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
Composerize神器:自动化转换Docker运行命令至Compose配置,简化容器部署流程
|
16天前
|
Kubernetes Shell 测试技术
在Docker中,可以在一个容器中同时运行多个应用进程吗?
在Docker中,可以在一个容器中同时运行多个应用进程吗?
|
17天前
|
Shell Docker 容器
在Docker中,如何停止所有正在运行的容器?
在Docker中,如何停止所有正在运行的容器?
|
18天前
|
前端开发 PHP 开发者
React Server Component 使用问题之怎么使用Docker运行PHP应用
React Server Component 使用问题之怎么使用Docker运行PHP应用
|
21天前
|
Ubuntu Shell 应用服务中间件
在Ubuntu 14.04上安装和使用Docker Compose的方法
在Ubuntu 14.04上安装和使用Docker Compose的方法
26 1
|
7天前
|
前端开发 jenkins 持续交付
jenkins学习笔记之二十:docker in docker运行pipeline
jenkins学习笔记之二十:docker in docker运行pipeline
|
11天前
|
Kubernetes Linux Docker
【Azure 应用服务】使用Docker Compose创建App Service遇见"Linux Version is too long. It cannot be more than 4000 characters"错误
【Azure 应用服务】使用Docker Compose创建App Service遇见"Linux Version is too long. It cannot be more than 4000 characters"错误
|
12天前
|
开发框架 监控 .NET
【Azure 应用程序见解】在Docker中运行的ASP.NET Core应用如何开启Application Insights的Profiler Trace呢?
【Azure 应用程序见解】在Docker中运行的ASP.NET Core应用如何开启Application Insights的Profiler Trace呢?
|
13天前
|
开发工具 git Docker
深入挖掘Docker Compose
【8月更文挑战第24天】
18 0
|
16天前
|
Docker 容器
docker: 修改运行容器的端口
docker: 修改运行容器的端口
下一篇
DDNS