2021-07-09

HugeGraphServer Quick Start
2 依赖
2.1 安装JDK-1.8

HugeGraph-Server 基于jdk-1.8开发,代码用到了较多jdk-1.8中的类和方法,请用户自行安装配置。

java -version

2.2 安装GCC-4.3.0(GLIBCXX_3.4.10)或更新版本(可选)

如果使用的是RocksDB后端,请务必执行gcc --version命令查看gcc版本;若使用其他后端,则不需要。

gcc --version

3 部署
有三种方式可以部署HugeGraph-Server组件:
方式1:一键部署
方式2:下载tar包
方式3:源码编译

3.1 一键部署

HugeGraph-Tools提供了一键部署的命令行工具,用户可以使用该工具快速地一键下载、解压、配置并启动HugeGraphServer和HugeGraphStudio。 当然,还是得先下载HugeGraph-Tools的tar包。

wget https://github.com/hugegraph/hugegraph-tools/releases/download/v${version}/hugegraph-tools-${version}.tar.gz
tar -zxvf hugegraph-tools-${version}.tar.gz
cd hugegraph-tools-${version}

HugeGraph-Tools 的总入口脚本是bin/hugegraph,用户可以使用help子命令查看其用法,这里只介绍一键部署的命令。

bin/hugegraph deploy -v {hugegraph-version} -p {install-path} [-u {download-path-prefix}]

{hugegraph-version}表示要部署的HugeGraphServer及HugeGraphStudio的版本,用户可查看conf/version-mapping.yaml文件获取版本信息,{install-path}指定HugeGraphServer及HugeGraphStudio的安装目录,{download-path-prefix}可选,指定HugeGraphServer及HugeGraphStudio tar包的下载地址,不提供时使用默认下载地址,比如要启动 0.6 版本的HugeGraph-Server及HugeGraphStudio将上述命令写为bin/hugegraph deploy -v 0.6 -p services即可。

3.2 下载tar包

wget https://github.com/hugegraph/hugegraph/releases/download/v${version}/hugegraph-${version}.tar.gz
tar -zxvf hugegraph-${version}.tar.gz

3.3 源码编译
下载HugeGraph源代码

git clone https://github.com/hugegraph/hugegraph.git

编译打包生成tar包

cd hugegraph
mvn package -DskipTests

执行成功后,在hugegraph目录下生成 hugegraph-*.tar.gz 文件,就是编译生成的tar包。

4 配置
如果需要快速启动HugeGraph仅用于测试,那么只需要进行少数几个配置项的修改即可(见下一节)。 详细的配置介绍请参考配置文档及配置项介绍

5 启动
启动分为"首次启动"和"非首次启动",这么区分是因为在第一次启动前需要初始化后端数据库,然后启动服务。 而在人为停掉服务后,或者其他原因需要再次启动服务时,因为后端数据库是持久化存在的,直接启动服务即可。

HugeGraphServer启动时会连接后端存储并尝试检查后端存储版本号,如果未初始化后端或者后端已初始化但版本不匹配时(旧版本数据),HugeGraphServer会启动失败,并给出错误信息。

如果需要外部访问HugeGraphServer,请修改rest-server.properties的restserver.url配置项 (默认为http://127.0.0.1:8080),修改成机器名或IP地址。修改为http://0.0.0.0:8080)

由于各种后端所需的配置(hugegraph.properties)及启动步骤略有不同,下面逐一对各后端的配置及启动做介绍。

5.1 Memory
修改 hugegraph.properties

backend=memory
serializer=text

Memory后端的数据是保存在内存中无法持久化的,不需要初始化后端,这也是唯一一个不需要初始化的后端。
启动 server
**

bin/start-hugegraph.sh
Starting HugeGraphServer...
Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK

提示的 url 与 rest-server.properties 中配置的 restserver.url 一致
(在安装软件包中添加logs文件夹以及hugegraph-server.log空文本文件,否则会一直出现错误)***

5.2 RocksDB
RocksDB是一个嵌入式的数据库,不需要手动安装部署, 要求 GCC 版本 >= 4.3.0(GLIBCXX_3.4.10),如不满足,需要提前升级 GCC

修改 hugegraph.properties

backend=rocksdb
serializer=binary
rocksdb.data_path=.
rocksdb.wal_path=.

初始化数据库(仅第一次启动时需要)

cd hugegraph-${version}
bin/init-store.sh

启动server

bin/start-hugegraph.sh
Starting HugeGraphServer...
Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK

5.3 Cassandra
用户需自行安装 Cassandra,要求版本 3.0 以上,下载地址
Installation from Debian packages
For the specify the major version number, without dot, and with an appended x.The latest is 311x.
For older releases, the can be one of 30x, 22x, or 21x.
Add the Apache repository of Cassandra to /etc/apt/sources.list.d/cassandra.sources.list, for example for the latest 3.11 version:

echo "deb https://downloads.apache.org/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list

Add the Apache Cassandra repository keys:

curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -

Update the repositories:***(需要有sudo或root权限)***

sudo apt-get update

If you encounter this error:

GPG error: http://www.apache.org 311x InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A278B781FE4B2BDA

Then add the public key A278B781FE4B2BDA as follows:

sudo apt-key adv --keyserver pool.sks-keyservers.net --recv-key A278B781FE4B2BDA

and repeat sudo apt-get update. The actual key may be different, you get it from the error message itself. For a full list of Apache contributors public keys, you can refer to Cassandra KEYS.

sudo apt-get install cassandra

修改 hugegraph.properties

backend=cassandra
serializer=cassandra

初始化数据库(仅第一次启动时需要)

cd hugegraph-${version}
bin/init-store.sh

启动server

bin/start-hugegraph.sh
Starting HugeGraphServer...
Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK

6 访问Server
6.1 服务启动状态校验
jps查看服务进程

jps

6475 HugeGraphServer
curl请求RESTfulAPI

echo `curl -o /dev/null -s -w %{http_code} "http://localhost:8080/graphs/hugegraph/graph/vertices"`

返回结果200,代表server启动正常

6.2 请求Server
HugeGraphServer的RESTful API包括多种类型的资源,典型的包括graph、schema、gremlin、traverser和task,
graph包含vertices、edges
schema 包含vertexlabels、 propertykeys、 edgelabels、indexlabels
gremlin包含各种Gremlin语句,如g.v(),可以同步或者异步执行
traverser包含各种高级查询,包括最短路径、交叉点、N步可达邻居等
task包含异步任务的查询和删除
6.2.1 获取hugegraph的顶点及相关属性

curl http://localhost:8080/graphs/hugegraph/graph/vertices

说明

由于图的点和边很多,对于 list 型的请求,比如获取所有顶点,获取所有边等,Server 会将数据压缩再返回, 所以使用 curl 时得到一堆乱码,可以重定向至 gunzip 进行解压。推荐使用 Chrome 浏览器 + Restlet 插件发送 HTTP 请求进行测试。

curl "http://localhost:8080/graphs/hugegraph/graph/vertices" | gunzip

当前HugeGraphServer的默认配置只能是本机访问,可以修改配置,使其能在其他机器访问。

 vim conf/rest-server.properties

restserver.url=http://0.0.0.0:8080
7 停止Server

$cd hugegraph-${version}
$bin/stop-hugegraph.sh
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值