dgraph cluster docker-compose 安装
Posted rongfengliang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dgraph cluster docker-compose 安装相关的知识,希望对你有一定的参考价值。
dgraph 是一款基于golang 的图数据库,使用了graphql+ 的查询方式
集群的安装官方也提供了对应的模版,比较简单
docker-compose 文件
我做了一些简单修改(数据存储的问题)
version: "3"
services:
zero:
image: dgraph/dgraph:latest
volumes:
- ./data0/data-volume:/dgraph
ports:
- 5080:5080
- 6080:6080
command: dgraph zero --my=zero:5080 --replicas 3
server_1:
image: dgraph/dgraph:latest
hostname: "server_1"
volumes:
- ./data1/data-volume:/dgraph
ports:
- 8080:8080
- 9080:9080
command: dgraph server --my=server_1:7080 --lru_mb=2048 --zero=zero:5080
server_2:
image: dgraph/dgraph:latest
hostname: "server_2"
volumes:
- ./data2/data-volume:/dgraph
ports:
- 8081:8081
- 9081:9081
command: dgraph server --my=server_2:7081 --lru_mb=2048 --zero=zero:5080 -o 1
server_3:
image: dgraph/dgraph:latest
hostname: "server_3"
volumes:
- ./data3/data-volume:/dgraph
ports:
- 8082:8082
- 9082:9082
command: dgraph server --my=server_3:7082 --lru_mb=2048 --zero=zero:5080 -o 2
ratel:
image: dgraph/dgraph:latest
hostname: "ratel"
ports:
- 8000:8000
command: dgraph-ratel
启动
docker-compose up -d
效果
http://localhost:8000
导入数据&&查询测试
- 导入数据
curl localhost:8080/mutate -H "X-Dgraph-CommitNow: true" -XPOST -d $‘
{
set {
_:luke <name> "Luke Skywalker" .
_:leia <name> "Princess Leia" .
_:han <name> "Han Solo" .
_:lucas <name> "George Lucas" .
_:irvin <name> "Irvin Kernshner" .
_:richard <name> "Richard Marquand" .
_:sw1 <name> "Star Wars: Episode IV - A New Hope" .
_:sw1 <release_date> "1977-05-25" .
_:sw1 <revenue> "775000000" .
_:sw1 <running_time> "121" .
_:sw1 <starring> _:luke .
_:sw1 <starring> _:leia .
_:sw1 <starring> _:han .
_:sw1 <director> _:lucas .
_:sw2 <name> "Star Wars: Episode V - The Empire Strikes Back" .
_:sw2 <release_date> "1980-05-21" .
_:sw2 <revenue> "534000000" .
_:sw2 <running_time> "124" .
_:sw2 <starring> _:luke .
_:sw2 <starring> _:leia .
_:sw2 <starring> _:han .
_:sw2 <director> _:irvin .
_:sw3 <name> "Star Wars: Episode VI - Return of the Jedi" .
_:sw3 <release_date> "1983-05-25" .
_:sw3 <revenue> "572000000" .
_:sw3 <running_time> "131" .
_:sw3 <starring> _:luke .
_:sw3 <starring> _:leia .
_:sw3 <starring> _:han .
_:sw3 <director> _:richard .
_:st1 <name> "Star Trek: The Motion Picture" .
_:st1 <release_date> "1979-12-07" .
_:st1 <revenue> "139000000" .
_:st1 <running_time> "132" .
}
}
‘ | python -m json.tool | less
- 查询
类似graphql 的语法
{
me(func: has(starring)) {
name
}
}
说明
zero 组件运行了一个,实际生产需要运行多个实例(一般是奇数 1, 3, 5)
参考资料
https://docs.dgraph.io/get-started
https://docs.dgraph.io/deploy/
以上是关于dgraph cluster docker-compose 安装的主要内容,如果未能解决你的问题,请参考以下文章