码迷,mamicode.com
首页 > 其他好文 > 详细

Dgraph安装以及使用1

时间:2019-04-07 13:17:13      阅读:429      评论:0      收藏:0      [点我收藏+]

标签:prism   添加   test   javascrip   roi   mon   details   用户   number   

1.首先安装docker和docker-compose:

 docker:

    curl -sSL https://get.daocloud.io/docker | sh

将当前用户添加到docker用户组:
sudo gpasswd -a ${USER} docker
su root             切换到root用户
su yifan          再切换到原来的应用用户以上配置才生效

   docker-compose:

   apt remove docker-compose

   pip install docker-compose -i https://mirrors.aliyun.com/pypi/simple/

   在.bashrc中增加

   export PATH="/home/yifan/.local/bin":$PATH

2. 编写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 alpha --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 alpha --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 alpha --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
 
3.启动docker-compose:
docker-compose up -d
 
4.查看界面:
http://localhost:8000
 
以下内容参考了:https://blog.csdn.net/hotqin888/article/details/81156959

运行

1) 添加数据

{
  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" .
  }
}

拷贝到命令行,切换到mutate,然后run

2) 添加索引

curl localhost:8080/alter -XPOST -d $‘
  name: string @index(term) .
  release_date: datetime @index(year) .
  revenue: float .
  running_time: int .
‘ | python -m json.tool | less

3) 查询

{
  me(func:allofterms(name, "Star Wars")) @filter(ge(release_date, "1980")) {
    name
    release_date
    revenue
    running_time
    director {
     name
    }
    starring {
     name
    }
  }
}

拷贝到命令行,切换到query,然后run

技术图片
 
 
 

Dgraph安装以及使用1

标签:prism   添加   test   javascrip   roi   mon   details   用户   number   

原文地址:https://www.cnblogs.com/jy451/p/10664431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!