hasura graphql-engine &&patroni docker-compose 环境运行
Posted rongfengliang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hasura graphql-engine &&patroni docker-compose 环境运行相关的知识,希望对你有一定的参考价值。
patroni 是一个很不错的pg ha 解决方案,graphql-engine 是一个很好的graphql 工具,为了方便使用
参考patroni官方的文档,使用docker-compose 将应用集成在一起,方便进行测试
环境准备
github 代码 https://github.com/rongfengliang/graphql-engine-patroni
- docker-compose 文件
version: "3"
services:
patroni_etcd:
container_name: patroni_etcd
image: dalongrong/patroni
command: --etcd
dbnode1:
image: dalongrong/patroni
hostname: dbnode1
ports:
- "5432:5432"
- "8008:8008"
links:
- patroni_etcd:patroni_etcd
volumes:
- ./patroni:/patroni
env_file: docker/patroni-secrets.env
environment:
PATRONI_ETCD_URL: http://patroni_etcd:2379
PATRONI_NAME: dbnode1
PATRONI_SCOPE: testcluster
dbnode2:
image: dalongrong/patroni
hostname: dbnode2
ports:
- "5433:5432"
- "8009:8008"
links:
- patroni_etcd:patroni_etcd
volumes:
- ./patroni:/patroni
env_file: docker/patroni-secrets.env
environment:
PATRONI_ETCD_URL: http://patroni_etcd:2379
PATRONI_NAME: dbnode2
PATRONI_SCOPE: testcluster
dbnode3:
image: dalongrong/patroni
hostname: dbnode3
ports:
- "5434:5432"
- "8010:8008"
links:
- patroni_etcd:patroni_etcd
volumes:
- ./patroni:/patroni
env_file: docker/patroni-secrets.env
environment:
PATRONI_ETCD_URL: http://patroni_etcd:2379
PATRONI_NAME: dbnode3
PATRONI_SCOPE: testcluster
haproxy:
image: dalongrong/patroni
links:
- patroni_etcd:patroni_etcd
ports:
- "5000:5000"
- "5001:5001"
- "7000:7000"
environment:
PATRONI_ETCD_URL: http://patroni_etcd:2379
PATRONI_SCOPE: testcluster
command: --confd
graphql-engine:
image: hasura/graphql-engine:v1.0.0-alpha30
ports:
- "8080:8080"
environment:
- "POSTGRES_PASSWORD:postgres"
command: >
/bin/sh -c "
graphql-engine --database-url postgres://postgres:[email protected]:5000/postgres serve --enable-console;
"
- 说明
挂在的数据卷: 很简单,主要是pg 状态的http server 代码,以及一些环境变量的配置
系统的访问通过haproxy进行,同时haproxy 集成了confd使用etcd 动态进行负载均衡的处理
基础镜像:镜像使用了patroni官方的代码进行了构建,参考https://github.com/rongfengliang/patroni
启动&&测试
- 启动
docker-compose up -d
- haproxy 界面
http://localhost:7000/,通过界面可以快速的看出master 以及replicas 节点的信息,同时基于haproxy 提供了读写分离的处理
- pg server 状态信息
http://localhost:80XX ,实际参考docker-compose 文件
- graphql 引擎界面
- 故障模拟
因为目前dbnode3 为master,尝试stop 掉,看看切换效果,很清晰,可以看到3剔除了,同时2成为master,grarphql 引擎基本不会影响
(haproxy的作用)
docker-compose stop dbnode3
重新启动3
从haproxy的界面可以看出,会有一个选举的过程,但是还是很不错的,都是自动的
docker-compose start dbnode3
master rest 接口的信息
参考资料
https://github.com/rongfengliang/patroni
https://github.com/zalando/patroni
https://github.com/rongfengliang/graphql-engine-patroni
https://github.com/hasura/graphql-engine
https://docs.hasura.io/1.0/graphql/manual/index.html
以上是关于hasura graphql-engine &&patroni docker-compose 环境运行的主要内容,如果未能解决你的问题,请参考以下文章
hasura graphql-engine ha 以及自动缩放的一些参考资料
一篇来自hasura graphql-engine 百万级别live query 的实践
hasura graphql-engine 最近版本的一些更新
madlib 集成 hasura graphql-engine 试用