一句话,在windows/macOS 上用 docker desktop 部署单 graphd, metad, storaged 集群,暴露 thrift 端口给 host network,配置 etc/hosts 增加 graphd, metad0, storaged0 域名解析。
见 https://gist.github.com/wey-gu/97554f1e84e977a3803c64e6757c452d
创建 docker-compose.yaml
mkdir nebulagraph_docker
cd nebulagraph_docker
vim docker-compose.yaml
像这样:
version: '3.4'
services:
metad0:
image: vesoft/nebula-metad:nightly
environment:
USER: root
command:
- --meta_server_addrs=metad0:9559
- --local_ip=metad0
- --ws_ip=metad0
- --port=9559
- --ws_http_port=19559
- --data_path=/data/meta
- --log_dir=/logs
- --v=0
- --minloglevel=0
healthcheck:
test: ["CMD", "curl", "-sf", "http://metad0:19559/status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
ports:
- 9559:9559
- 19559:19559
- 19560
volumes:
- ./data/meta0:/data/meta
- ./logs/meta0:/logs
networks:
- nebula-net
restart: on-failure
cap_add:
- SYS_PTRACE
storaged0:
image: vesoft/nebula-storaged:nightly
environment:
USER: root
TZ: "${TZ}"
command:
- --meta_server_addrs=metad0:9559
- --local_ip=storaged0
- --ws_ip=storaged0
- --port=9779
- --ws_http_port=19779
- --data_path=/data/storage
- --log_dir=/logs
- --v=0
- --minloglevel=0
depends_on:
- metad0
healthcheck:
test: ["CMD", "curl", "-sf", "http://storaged0:19779/status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
ports:
- 9779:9779
- 19779:19779
- 19780
volumes:
- ./data/storage0:/data/storage
- ./logs/storage0:/logs
networks:
- nebula-net
restart: on-failure
cap_add:
- SYS_PTRACE
graphd:
image: vesoft/nebula-graphd:nightly
environment:
USER: root
TZ: "${TZ}"
command:
- --meta_server_addrs=metad0:9559
- --port=9669
- --local_ip=graphd
- --ws_ip=graphd
- --ws_http_port=19669
- --log_dir=/logs
- --v=0
- --minloglevel=0
depends_on:
- storaged0
healthcheck:
test: ["CMD", "curl", "-sf", "http://graphd:19669/status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
ports:
- 9669:9669
- 19669:19669
- 19670
volumes:
- ./logs/graph:/logs
networks:
- nebula-net
restart: on-failure
cap_add:
- SYS_PTRACE
networks:
nebula-net:
启动集群
docker-compose up -d
等一等 metad 和 graphd。
$ docker-compose ps
NAME COMMAND SERVICE STATUS PORTS
nebulagraph_docker_nebula-graphd-1 "/usr/local/nebula/b…" graphd running (healthy) 0.0.0.0:9669->9669/tcp, 0.0.0.0:19669->19669/tcp, 0.0.0.0:60789->19670/tcp
nebulagraph_docker_nebula-metad0-1 "/usr/local/nebula/b…" metad0 running (healthy) 0.0.0.0:9559->9559/tcp, 0.0.0.0:19559->19559/tcp, 9560/tcp, 0.0.0.0:60785->19560/tcp
nebulagraph_docker_nebula-storaged0-1 "/usr/local/nebula/b…" storaged0 running (unhealthy) 9777-9778/tcp, 0.0.0.0:9779->9779/tcp, 9780/tcp, 0.0.0.0:19779->19779/tcp, 0.0.0.0:60786->19780/tcp
storaged 激活一下
# I am m1 Mac, thus download the darwin-arm64 console binary
wget https://github.com/vesoft-inc/nebula-console/releases/download/v3.3.1/nebula-console-darwin-arm64-v3.3.1
chmod +x nebula-console-darwin-arm64-v3.3.1
./nebula-console-darwin-arm64-v3.3.1 -addr 127.0.0.1 -port 9669 -user root -p nebula
# now we are in the Nebula Graph
> ADD HOSTS "storaged0":9779
> :play basketballplayer
为 metad/storaged/graphd 添加主机、DNS 信息
sudo vim /etc/hosts
To ensure this line exists
127.0.0.1 storaged0 metad0 graphd
确认信息
from nebula3.mclient import MetaCache, HostAddr
from nebula3.sclient.GraphStorageClient import GraphStorageClient
# the metad servers's address
meta_cache = MetaCache([('metad0', 9559)], 50000)
graph_storage_client = GraphStorageClient(meta_cache)
resp = graph_storage_client.scan_vertex(
space_name='basketballplayer',
tag_name='team')
while resp.has_next():
result = resp.next()
for vertex_data in result:
print(vertex_data)
好的,它已经正常运行了:
In [1]: from nebula3.mclient import MetaCache, HostAddr
...: from nebula3.sclient.GraphStorageClient import GraphStorageClient
...:
...: # the metad servers's address
...: meta_cache = MetaCache([('metad0', 9559)], 50000)
...:
...: graph_storage_client = GraphStorageClient(meta_cache)
...: resp = graph_storage_client.scan_vertex(
...: space_name='basketballplayer',
...: tag_name='team')
...: while resp.has_next():
...: result = resp.next()
...: for vertex_data in result:
...: print(vertex_data)
...:
("team201" :team{name: "Nuggets"})
("team212" :team{name: "Grizzlies"})
("team214" :team{name: "Suns"})
("team200" :team{name: "Warriors"})
("team203" :team{name: "Trail Blazers"})
("team220" :team{name: "Pacers"})
("team202" :team{name: "Rockets"})
("team208" :team{name: "Kings"})
("team216" :team{name: "Cavaliers"})
("team217" :team{name: "Celtics"})
("team223" :team{name: "Knicks"})
("team224" :team{name: "Pistons"})
("team206" :team{name: "Jazz"})
("team210" :team{name: "Lakers"})
("team219" :team{name: "76ers"})
("team227" :team{name: "Nets"})
("team204" :team{name: "Spurs"})
("team218" :team{name: "Raptors"})
("team229" :team{name: "Heat"})
("team207" :team{name: "Clippers"})
("team211" :team{name: "Pelicans"})
("team221" :team{name: "Bulls"})
("team222" :team{name: "Hawks"})
("team205" :team{name: "Thunders"})
("team213" :team{name: "Mavericks"})
("team215" :team{name: "Hornets"})
("team228" :team{name: "Wizards"})
("team209" :team{name: "Timberwolves"})
("team225" :team{name: "Bucks"})
("team226" :team{name: "Magic"})
In [2]: