美文网首页
Nebula Graph基础

Nebula Graph基础

作者: Jlan | 来源:发表于2022-09-09 14:57 被阅读0次

    服务部署

    1. Nebula Graph安装与启动

    https://docs.nebula-graph.com.cn/3.2.0/4.deployment-and-installation/2.compile-and-install-nebula-graph/2.install-nebula-graph-by-rpm-or-deb/

    1. RPM/DEB包安装和启动
    wget https://oss-cdn.nebula-graph.com.cn/package/3.2.0/nebula-graph-3.2.0.ubuntu1804.amd64.deb  # 下载安装包
    dpkg -i nebula-graph-3.2.0.ubuntu1804.amd64.deb  # 安装
    
    sudo /usr/local/nebula/scripts/nebula.service start all  # 启动服务
    sudo /usr/local/nebula/scripts/nebula.service status all  # 查看状态
    
    1. 使用docker compose安装和启动
    git clone -b release-3.2 https://github.com/vesoft-inc/nebula-docker-compose.git
    
    cd nebula-docker-compose/
    docker compose up -d  # 启动 Nebula Graph 服务
    
    docker compose ps  # 查看 Nebula Console 容器名称
    NAME                                COMMAND                   SERVICE             STATUS              PORTS
    nebula-docker-compose-console-1     "sh -c 'sleep 3 &&\nn…"   console             running             
    nebula-docker-compose-graphd-1      "/usr/local/nebula/b…"    graphd              running (healthy)   0.0.0.0:9669->9669/tcp, 0.0.0.0:32793->19669-19670/tcp
    nebula-docker-compose-graphd1-1     "/usr/local/nebula/b…"    graphd1             running (healthy)   0.0.0.0:32792->9669/tcp, 0.0.0.0:32790->19669-19670/tcp
    nebula-docker-compose-graphd2-1     "/usr/local/nebula/b…"    graphd2             running (healthy)   0.0.0.0:32789->9669/tcp, 0.0.0.0:32787->19669-19670/tcp
    nebula-docker-compose-metad0-1      "/usr/local/nebula/b…"    metad0              running (healthy)   0.0.0.0:32776->9559/tcp, 0.0.0.0:32774->19559-19560/tcp
    nebula-docker-compose-metad1-1      "/usr/local/nebula/b…"    metad1              running (healthy)   0.0.0.0:32775->9559/tcp, 0.0.0.0:32773->19559-19560/tcp
    nebula-docker-compose-metad2-1      "/usr/local/nebula/b…"    metad2              running (healthy)   0.0.0.0:32772->9559/tcp, 0.0.0.0:32769->19559-19560/tcp
    nebula-docker-compose-storaged0-1   "/usr/local/nebula/b…"    storaged0           running (healthy)   0.0.0.0:32781->9779/tcp, 0.0.0.0:32778->19779-19780/tcp
    nebula-docker-compose-storaged1-1   "/usr/local/nebula/b…"    storaged1           running (healthy)   0.0.0.0:32785->9779/tcp, 0.0.0.0:32783->19779-19780/tcp
    nebula-docker-compose-storaged2-1   "/usr/local/nebula/b…"    storaged2           running (healthy)   0.0.0.0:32784->9779/tcp, 0.0.0.0:32782->19779-19780/tcp
    
    docker exec -it nebuladockercompose_console_1 /bin/sh  # 进入Nebula Console 容器
    
    /usr/local/bin/nebula-console -u <user_name> -p <password> --address=graphd --port=9669  # 通过 Nebula Console 连接 Nebula Graph
    
    nebula> SHOW HOSTS;  # 查看集群状态
    +-------------+------+-----------+----------+--------------+----------------------+------------------------+---------+
    | Host        | Port | HTTP port | Status   | Leader count | Leader distribution  | Partition distribution | Version |
    +-------------+------+-----------+----------+--------------+----------------------+------------------------+---------+
    | "storaged0" | 9779 | 19669     | "ONLINE" | 0            | "No valid partition" | "No valid partition"   | "3.2.0" |
    | "storaged1" | 9779 | 19669     | "ONLINE" | 0            | "No valid partition" | "No valid partition"   | "3.2.0" |
    | "storaged2" | 9779 | 19669     | "ONLINE" | 0            | "No valid partition" | "No valid partition"   | "3.2.0" |
    +-------------+------+-----------+----------+--------------+----------------------+------------------------+---------+
    
    

    2. Nebula Studio安装与启动

    https://docs.nebula-graph.com.cn/3.2.0/nebula-studio/deploy-connect/st-ug-deploy/

    wget https://oss-cdn.nebula-graph.com.cn/nebula-graph-studio/3.4.1/nebula-graph-studio-3.4.1.x86_64.rpm  # 下载安装包
    sudo rpm -i nebula-graph-studio-3.4.1.x86_64.rpm
    

    顺利安装后会自动启动,在浏览器地址栏输入 http://127.0.0.1:7001


    输入Nebula Graph 的 Graph 服务本机 IP 地址以及服务所用端口,默认端口为 9669。

    3. 部署遇到的问题

    1. 使用docker compose安装nebula-graph时可能会出现由于网络问题导致下载文件失败,可以多试几次。
    2. Nebula Studio的deb包无法在WSL环境安装,会提示System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

    用法

    支持nGQL和openCypher 9
    https://docs.nebula-graph.com.cn/3.1.0/3.ngql-guide/14.native-index-statements/1.create-native-index/

    1. MATCH语句
      MATCH语句提供基于模式(pattern)匹配的搜索功能。
      一个MATCH语句定义了一个搜索模式,用该模式匹配存储在 Nebula Graph 中的数据,然后用RETURN子句检索数据。
      参考:https://docs.nebula-graph.com.cn/3.1.0/3.ngql-guide/7.general-query-statements/2.match/
      使用MATCH语句时注意需要创建索引

      # 匹配节点
      MATCH (v:Disease) RETURN v LIMIT 10;
      MATCH (v:Disease{name: "上感"}) RETURN v;
      MATCH (v:Disease) where v.Disease.name=="上感" RETURN v;
      
      # 匹配连接的点
      # v1--v2表示v1和v2之间的连接
      # v1-->v2表示v1到v2之间的连接,对于v1是出边,对于v2是入边
      # v1<--v2表示v2到v1之间的连接
      
      # -->表示边从 v 开始,指向 v2。对于点 v 来说是出边,对于点 v2 来说是入边。
      MATCH (v:Disease{name:"急性上呼吸道感染"})-->(v2:Disease) RETURN v2.Disease.name AS Name;
      
      # 匹配路径
      # 连接起来的点和边构成了路径。用户可以使用自定义变量命名路径。
      MATCH p=(v:Disease{name:"上感"})-->(v2) RETURN p;
      
      # 匹配边
      # 和点一样,用户可以用:<edge_type>表示模式中的 Edge type,例如-[e:follow]-
      MATCH (v:Disease{name:"流行性脑脊髓膜炎"})-[e:ClinicalManifestation]->(v2) RETURN e;
      MATCH (v:Disease{name:"流行性脑脊髓膜炎"})-[e:ClinicalManifestation{inStage:"初期"}]->(v2) RETURN e;
      
    2. FIND PATH语句
      FIND PATH语句查找指定起始点和目的点之间的路径。
      参考:https://docs.nebula-graph.com.cn/3.1.0/3.ngql-guide/16.subgraph-and-path/2.find-path/

      # "急性上呼吸道感染" 到 "咽干" 的最短路径
      FIND SHORTEST PATH FROM "急性上呼吸道感染" TO "咽干" OVER * YIELD path AS p;
      
    3. GET SUBGRAPH语句
      GET SUBGRAPH语句检索指定 Edge type 的起始点可以到达的点和边的信息,返回子图信息。
      参考:https://docs.nebula-graph.com.cn/3.1.0/3.ngql-guide/16.subgraph-and-path/1.get-subgraph/

      # 查询从点急性上呼吸道感染开始、0~1 跳、所有Edge type的子图。
      GET SUBGRAPH 1 STEPS FROM "急性上呼吸道感染" YIELD VERTICES AS nodes, EDGES AS relationships
      
      # 查询从点急性上呼吸道感染开始、0~1 跳、DiseaseClassification类型的出边的子图。
      GET SUBGRAPH 1 STEPS FROM "急性上呼吸道感染" OUT DiseaseClassification YIELD VERTICES AS nodes, EDGES AS relationships;
      

    Python接口

    参考:https://github.com/vesoft-inc/nebula/tree/master/tests/tck/features/fetch

    相关文章

      网友评论

          本文标题:Nebula Graph基础

          本文链接:https://www.haomeiwen.com/subject/xmtznrtx.html