HugeGraph-Server Quick Start

1 HugeGraph-Server Overview

HugeGraph-Server is the core part of the HugeGraph Project, contains submodules such as Core, Backend, API.

The Core Module is an implementation of the Tinkerpop interface; The Backend module is used to save the graph data to the data store, currently supported backends include: Memory, Cassandra, ScyllaDB, RocksDB; The API Module provides HTTP Server, which converts Client’s HTTP request into a call to Core Module.

There will be two spellings HugeGraph-Server and HugeGraphServer in the document, and other modules are similar. There is no big difference in the meaning of these two ways of writing, which can be distinguished as follows: HugeGraph-Server represents the code of server-related components, HugeGraphServer represents the service process.

2 Dependency for Building/Running

2.1 Install Java 11 (JDK 11)

Consider use Java 11 to run HugeGraph-Server (also compatible with Java 8 now), and configure by yourself.

Be sure to execute the java -version command to check the jdk version before reading

3 Deploy

There are four ways to deploy HugeGraph-Server components:

  • Method 1: Download the binary tarball
  • Method 2: Source code compilation
  • Method 3: Use Docker container (Convenient for Test/Dev)
  • Method 4: One-click deployment

3.1 Download the binary tar tarball

You could download the binary tarball from the download page of ASF site like this:

  1. # use the latest version, here is 1.2.0 for example
  2. wget https://downloads.apache.org/incubator/hugegraph/{version}/apache-hugegraph-incubating-{version}.tar.gz
  3. tar zxf *hugegraph*.tar.gz
  4. # (Optional) verify the integrity with SHA512 (recommended)
  5. shasum -a 512 apache-hugegraph-incubating-{version}.tar.gz
  6. curl https://downloads.apache.org/incubator/hugegraph/{version}/apache-hugegraph-incubating-{version}.tar.gz.sha512

3.2 Source code compilation

Please ensure that the wget command is installed before compiling the source code

We could get HugeGraph source code by 2 ways: (So as the other HugeGraph repos/modules)

  • download the stable/release version from the ASF site
  • clone the unstable/latest version by GitBox(ASF) or GitHub
  1. # Way 1. download release package from the ASF site
  2. wget https://downloads.apache.org/incubator/hugegraph/{version}/apache-hugegraph-incubating-src-{version}.tar.gz
  3. tar zxf *hugegraph*.tar.gz
  4. # (Optional) verify the integrity with SHA512 (recommended)
  5. shasum -a 512 apache-hugegraph-incubating-src-{version}.tar.gz
  6. curl https://downloads.apache.org/incubator/hugegraph/{version}/apache-hugegraph-incubating-{version}-src.tar.gz.sha512
  7. # Way2 : clone the latest code by git way (e.g GitHub)
  8. git clone https://github.com/apache/hugegraph.git

Compile and generate tarball

  1. cd *hugegraph
  2. mvn package -DskipTests -ntp

The execution log is as follows:

  1. ......
  2. [INFO] Reactor Summary for hugegraph 1.2.0:
  3. [INFO]
  4. [INFO] hugegraph .......................................... SUCCESS [ 2.405 s]
  5. [INFO] hugegraph-core ..................................... SUCCESS [ 13.405 s]
  6. [INFO] hugegraph-api ...................................... SUCCESS [ 25.943 s]
  7. [INFO] hugegraph-cassandra ................................ SUCCESS [ 54.270 s]
  8. [INFO] hugegraph-scylladb ................................. SUCCESS [ 1.032 s]
  9. [INFO] hugegraph-rocksdb .................................. SUCCESS [ 34.752 s]
  10. [INFO] hugegraph-mysql .................................... SUCCESS [ 1.778 s]
  11. [INFO] hugegraph-palo ..................................... SUCCESS [ 1.070 s]
  12. [INFO] hugegraph-hbase .................................... SUCCESS [ 32.124 s]
  13. [INFO] hugegraph-postgresql ............................... SUCCESS [ 1.823 s]
  14. [INFO] hugegraph-dist ..................................... SUCCESS [ 17.426 s]
  15. [INFO] hugegraph-example .................................. SUCCESS [ 1.941 s]
  16. [INFO] hugegraph-test ..................................... SUCCESS [01:01 min]
  17. [INFO] ------------------------------------------------------------------------
  18. [INFO] BUILD SUCCESS
  19. [INFO] ------------------------------------------------------------------------
  20. ......

After successful execution, *hugegraph-*.tar.gz files will be generated in the hugegraph directory, which is the tarball generated by compilation.

3.3 Use Docker container (Convenient for Test/Dev)

You can refer to Docker deployment guide.

We can use docker run -itd --name=graph -p 8080:8080 hugegraph/hugegraph to quickly start an inner HugeGraph server with RocksDB in background.

Optional:

  1. use docker exec -it graph bash to enter the container to do some operations.
  2. use docker run -itd --name=graph -p 8080:8080 -e PRELOAD="true" hugegraph/hugegraph to start with a built-in example graph. We can use RESTful API to verify the result. The detailed step can refer to 5.1.1

Also, if we want to manage the other Hugegraph related instances in one file, we can use docker-compose to deploy, with the command docker-compose up -d (you can config only server). Here is an example docker-compose.yml:

  1. version: '3'
  2. services:
  3. graph:
  4. image: hugegraph/hugegraph
  5. # environment:
  6. # - PRELOAD=true
  7. # PRELOAD is a option to preload a build-in sample graph when initializing.
  8. ports:
  9. - 8080:8080

Note:

  1. The docker image of hugegraph is a convenience release to start hugegraph quickly, but not official distribution artifacts. You can find more details from ASF Release Distribution Policy.

  2. Recommand to use release tag(like 1.2.0) for the stable version. Use latest tag to experience the newest functions in development.

3.4 One-click deployment

HugeGraph-Tools provides a command-line tool for one-click deployment, users can use this tool to quickly download, decompress, configure and start HugeGraphServer and HugeGraph-Hubble with one click.

Of course, you should download the tarball of HugeGraph-Toolchain first.

  1. # download toolchain binary package, it includes loader + tool + hubble
  2. # please check the latest version (e.g. here is 1.2.0)
  3. wget https://downloads.apache.org/incubator/hugegraph/1.2.0/apache-hugegraph-toolchain-incubating-1.2.0.tar.gz
  4. tar zxf *hugegraph-*.tar.gz
  5. # enter the tool's package
  6. cd *hugegraph*/*tool*

note: ${version} is the version, The latest version can refer to Download Page, or click the link to download directly from the Download page

The general entry script for HugeGraph-Tools is bin/hugegraph, Users can use the help command to view its usage, here only the commands for one-click deployment are introduced.

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

{hugegraph-version} indicates the version of HugeGraphServer and HugeGraphStudio to be deployed, users can view the conf/version-mapping.yaml file for version information, {install-path} specify the installation directory of HugeGraphServer and HugeGraphStudio, {download-path-prefix} optional, specify the download address of HugeGraphServer and HugeGraphStudio tarball, use default download URL if not provided, for example, to start HugeGraph-Server and HugeGraphStudio version 0.6, write the above command as bin/hugegraph deploy -v 0.6 -p services.

4 Config

If you need to quickly start HugeGraph just for testing, then you only need to modify a few configuration items (see next section). for detailed configuration introduction, please refer to configuration document and introduction to configuration items

5 Startup

5.1 Use a startup script to startup

The startup is divided into “first startup” and “non-first startup”. This distinction is because the back-end database needs to be initialized before the first startup, and then the service is started. after the service is stopped artificially, or when the service needs to be started again for other reasons, because the backend database is persistent, you can start the service directly.

When HugeGraphServer starts, it will connect to the backend storage and try to check the version number of the backend storage. If the backend is not initialized or the backend has been initialized but the version does not match (old version data), HugeGraphServer will fail to start and give an error message.

If you need to access HugeGraphServer externally, please modify the restserver.url configuration item of rest-server.properties (default is http://127.0.0.1:8080), change to machine name or IP address.

Since the configuration (hugegraph.properties) and startup steps required by various backends are slightly different, the following will introduce the configuration and startup of each backend one by one.

If you want to use HugeGraph authentication mode, you should follow the Server Authentication Configuration configuration before you start Server later.

5.1.1 Memory

Click to expand/collapse Memory configuration and startup methods

Update hugegraph.properties

  1. backend=memory
  2. serializer=text

The data of the Memory backend is stored in memory and cannot be persisted. It does not need to initialize the backend. This is the only backend that does not require initialization.

Start server

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

The prompted url is the same as the restserver.url configured in rest-server.properties

5.1.2 RocksDB

Click to expand/collapse RocksDB configuration and startup methods

RocksDB is an embedded database that does not require manual installation and deployment. GCC version >= 4.3.0 (GLIBCXX_3.4.10) is required. If not, GCC needs to be upgraded in advance

Update hugegraph.properties

  1. backend=rocksdb
  2. serializer=binary
  3. rocksdb.data_path=.
  4. rocksdb.wal_path=.

Initialize the database (required on first startup or a new configuration was manually added under ‘conf/graphs/’)

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

Start server

  1. bin/start-hugegraph.sh
  2. Starting HugeGraphServer...
  3. Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK
5.1.3 Cassandra

Click to expand/collapse Cassandra configuration and startup methods

users need to install Cassandra by themselves, requiring version 3.0 or above, download link

Update hugegraph.properties

  1. backend=cassandra
  2. serializer=cassandra
  3. # cassandra backend config
  4. cassandra.host=localhost
  5. cassandra.port=9042
  6. cassandra.username=
  7. cassandra.password=
  8. #cassandra.connect_timeout=5
  9. #cassandra.read_timeout=20
  10. #cassandra.keyspace.strategy=SimpleStrategy
  11. #cassandra.keyspace.replication=3

Initialize the database (required on first startup or a new configuration was manually added under ‘conf/graphs/’)

  1. cd *hugegraph-${version}
  2. bin/init-store.sh
  3. Initing HugeGraph Store...
  4. 2017-12-01 11:26:51 1424 [main] [INFO ] org.apache.hugegraph.HugeGraph [] - Opening backend store: 'cassandra'
  5. 2017-12-01 11:26:52 2389 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph, try init keyspace later
  6. 2017-12-01 11:26:52 2472 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph, try init keyspace later
  7. 2017-12-01 11:26:52 2557 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph, try init keyspace later
  8. 2017-12-01 11:26:53 2797 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: huge_graph
  9. 2017-12-01 11:26:53 2945 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: huge_schema
  10. 2017-12-01 11:26:53 3044 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: huge_index
  11. 2017-12-01 11:26:53 3046 [pool-3-thread-1] [INFO ] org.apache.hugegraph.backend.Transaction [] - Clear cache on event 'store.init'
  12. 2017-12-01 11:26:59 9720 [main] [INFO ] org.apache.hugegraph.HugeGraph [] - Opening backend store: 'cassandra'
  13. 2017-12-01 11:27:00 9805 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph1, try init keyspace later
  14. 2017-12-01 11:27:00 9886 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph1, try init keyspace later
  15. 2017-12-01 11:27:00 9955 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph1, try init keyspace later
  16. 2017-12-01 11:27:00 10175 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: huge_graph
  17. 2017-12-01 11:27:00 10321 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: huge_schema
  18. 2017-12-01 11:27:00 10413 [main] [INFO ] org.apache.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: huge_index
  19. 2017-12-01 11:27:00 10413 [pool-3-thread-1] [INFO ] org.apache.hugegraph.backend.Transaction [] - Clear cache on event 'store.init'

Start server

  1. bin/start-hugegraph.sh
  2. Starting HugeGraphServer...
  3. Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK
5.1.4 ScyllaDB

Click to expand/collapse ScyllaDB configuration and startup methods

users need to install ScyllaDB by themselves, version 2.1 or above is recommended, download link

Update hugegraph.properties

  1. backend=scylladb
  2. serializer=scylladb
  3. # cassandra backend config
  4. cassandra.host=localhost
  5. cassandra.port=9042
  6. cassandra.username=
  7. cassandra.password=
  8. #cassandra.connect_timeout=5
  9. #cassandra.read_timeout=20
  10. #cassandra.keyspace.strategy=SimpleStrategy
  11. #cassandra.keyspace.replication=3

Since the scylladb database itself is an “optimized version” based on cassandra, if the user does not have scylladb installed, they can also use cassandra as the backend storage directly. They only need to change the backend and serializer to scylladb, and the host and post point to the seeds and port of the cassandra cluster. Yes, but it is not recommended to do so, it will not take advantage of scylladb itself.

Initialize the database (required on first startup or a new configuration was manually added under ‘conf/graphs/’)

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

Start server

  1. bin/start-hugegraph.sh
  2. Starting HugeGraphServer...
  3. Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK
5.1.5 HBase

Click to expand/collapse HBase configuration and startup methods

users need to install HBase by themselves, requiring version 2.0 or above,download link

Update hugegraph.properties

  1. backend=hbase
  2. serializer=hbase
  3. # hbase backend config
  4. hbase.hosts=localhost
  5. hbase.port=2181
  6. # Note: recommend to modify the HBase partition number by the actual/env data amount & RS amount before init store
  7. # it may influence the loading speed a lot
  8. #hbase.enable_partition=true
  9. #hbase.vertex_partitions=10
  10. #hbase.edge_partitions=30

Initialize the database (required on first startup or a new configuration was manually added under ‘conf/graphs/’)

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

Start server

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

for more other backend configurations, please refer tointroduction to configuration options

5.1.6 MySQL

Click to expand/collapse MySQL configuration and startup methods

Due to MySQL is under GPL license, which is not compatible with Apache License indeed, Users need to install MySQL, Download Link

Download MySQL’s [driver package] (https://repo1.maven.org/maven2/mysql/mysql-connector-java/)), such as mysql-connector-java-8.0.30.jar, and put it into HugeGraph- Server’s lib directory.

Modify hugegraph.properties, configure the database URL, username and password, store is the database name, if not, it will be created automatically.

  1. backend=mysql
  2. serializer=mysql
  3. store=hugegraph
  4. # mysql backend config
  5. jdbc.driver=com.mysql.cj.jdbc.Driver
  6. jdbc.url=jdbc:mysql://127.0.0.1:3306
  7. jdbc.username=
  8. jdbc.password=
  9. jdbc.reconnect_max_times=3
  10. jdbc.reconnect_interval=3
  11. jdbc.ssl_mode=false

Initialize the database (required on first startup or a new configuration was manually added under ‘conf/graphs/’)

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

Start server

  1. bin/start-hugegraph.sh
  2. Starting HugeGraphServer...
  3. Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK
5.1.7 Create an example graph when startup

Carry the -p true arguments when starting the script, which indicates preload, to create a sample graph.

  1. bin/start-hugegraph.sh -p true
  2. Starting HugeGraphServer in daemon mode...
  3. Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)......OK

And use the RESTful API to request HugeGraphServer and get the following result:

  1. > curl "http://localhost:8080/graphs/hugegraph/graph/vertices" | gunzip
  2. {"vertices":[{"id":"2:lop","label":"software","type":"vertex","properties":{"name":"lop","lang":"java","price":328}},{"id":"1:josh","label":"person","type":"vertex","properties":{"name":"josh","age":32,"city":"Beijing"}},{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":29,"city":"Beijing"}},{"id":"1:peter","label":"person","type":"vertex","properties":{"name":"peter","age":35,"city":"Shanghai"}},{"id":"1:vadas","label":"person","type":"vertex","properties":{"name":"vadas","age":27,"city":"Hongkong"}},{"id":"2:ripple","label":"software","type":"vertex","properties":{"name":"ripple","lang":"java","price":199}}]}

This indicates the successful creation of the sample graph.

5.2 Use Docker to startup

In 3.3 Use Docker container, we have introduced how to use docker to deploy hugegraph-server. server can also preload an example graph by setting the parameter.

5.2.1 Use Cassandra as the storage

Click to expand/collapse Cassandra configuration and startup methods

When using Docker, we can use Cassandra as the backend storage. We highly recommend using docker-compose directly to manage both the server and Cassandra.

The sample docker-compose.yml can be obtained on github, and you can start it with docker-compose up -d. (If using Cassandra 4.0 as the backend storage, it takes approximately two minutes to initialize. Please be patient.)

  1. version: "3"
  2. services:
  3. graph:
  4. image: hugegraph/hugegraph
  5. container_name: cas-graph
  6. ports:
  7. - 8080:8080
  8. environment:
  9. hugegraph.backend: cassandra
  10. hugegraph.serializer: cassandra
  11. hugegraph.cassandra.host: cas-cassandra
  12. hugegraph.cassandra.port: 9042
  13. networks:
  14. - ca-network
  15. depends_on:
  16. - cassandra
  17. healthcheck:
  18. test: ["CMD", "bin/gremlin-console.sh", "--" ,"-e", "scripts/remote-connect.groovy"]
  19. interval: 10s
  20. timeout: 30s
  21. retries: 3
  22. cassandra:
  23. image: cassandra:4
  24. container_name: cas-cassandra
  25. ports:
  26. - 7000:7000
  27. - 9042:9042
  28. security_opt:
  29. - seccomp:unconfined
  30. networks:
  31. - ca-network
  32. healthcheck:
  33. test: ["CMD", "cqlsh", "--execute", "describe keyspaces;"]
  34. interval: 10s
  35. timeout: 30s
  36. retries: 5
  37. networks:
  38. ca-network:
  39. volumes:
  40. hugegraph-data:

In this yaml file, configuration parameters related to Cassandra need to be passed as environment variables in the format of hugegraph.<parameter_name>.

Specifically, in the configuration file hugegraph.properties , there are settings like backend=xxx and cassandra.host=xxx. To configure these settings during the process of passing environment variables, we need to prepend hugegraph. to these configurations, like hugegraph.backend and hugegraph.cassandra.host.

The rest of the configurations can be referenced under 4 config

5.2.2 Create example graph when starting server

Set the environment variable PRELOAD=true when starting Docker in order to load data during the execution of the startup script.

  1. Use docker run

    Use docker run -itd --name=graph -p 8080:8080 -e PRELOAD=true hugegraph/hugegraph:latest

  2. Use docker-compose

    Create docker-compose.yml as following. We should set the environment variable PRELOAD=true. example.groovy is a predefined script to preload the sample data. If needed, we can mount a new example.groovy to change the preload data.

    1. version: '3'
    2. services:
    3. graph:
    4. image: hugegraph/hugegraph:latest
    5. container_name: graph
    6. environment:
    7. - PRELOAD=true
    8. ports:
    9. - 8080:8080

    Use docker-compose up -d to start the container

And use the RESTful API to request HugeGraphServer and get the following result:

  1. > curl "http://localhost:8080/graphs/hugegraph/graph/vertices" | gunzip
  2. {"vertices":[{"id":"2:lop","label":"software","type":"vertex","properties":{"name":"lop","lang":"java","price":328}},{"id":"1:josh","label":"person","type":"vertex","properties":{"name":"josh","age":32,"city":"Beijing"}},{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":29,"city":"Beijing"}},{"id":"1:peter","label":"person","type":"vertex","properties":{"name":"peter","age":35,"city":"Shanghai"}},{"id":"1:vadas","label":"person","type":"vertex","properties":{"name":"vadas","age":27,"city":"Hongkong"}},{"id":"2:ripple","label":"software","type":"vertex","properties":{"name":"ripple","lang":"java","price":199}}]}

This indicates the successful creation of the sample graph.

6 Access server

6.1 Service startup status check

Use jps to see service process

  1. jps
  2. 6475 HugeGraphServer

curl request RESTfulAPI

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

Return 200, which means the server starts normally.

6.2 Request Server

The RESTful API of HugeGraphServer includes various types of resources, typically including graph, schema, gremlin, traverser and task.

  • graph contains verticesedges
  • schema contains vertexlabelspropertykeysedgelabelsindexlabels
  • gremlin contains various Gremlin statements, such as g.v(), which can be executed synchronously or asynchronously
  • traverser contains various advanced queries including shortest paths, intersections, N-step reachable neighbors, etc.
  • task contains query and delete with asynchronous tasks
  1. curl http://localhost:8080/graphs/hugegraph/graph/vertices

explanation

  1. Since there are many vertices and edges in the graph, for list-type requests, such as getting all vertices, getting all edges, etc., the server will compress the data and return it, so when use curl, you get a bunch of garbled characters, you can redirect to gunzip for decompression. It is recommended to use Chrome browser + Restlet plugin to send HTTP requests for testing.

    1. curl "http://localhost:8080/graphs/hugegraph/graph/vertices" | gunzip
  2. The current default configuration of HugeGraphServer can only be accessed locally, and the configuration can be modified so that it can be accessed on other machines.

    1. vim conf/rest-server.properties
    2. restserver.url=http://0.0.0.0:8080

response body:

  1. {
  2. "vertices": [
  3. {
  4. "id": "2lop",
  5. "label": "software",
  6. "type": "vertex",
  7. "properties": {
  8. "price": [
  9. {
  10. "id": "price",
  11. "value": 328
  12. }
  13. ],
  14. "name": [
  15. {
  16. "id": "name",
  17. "value": "lop"
  18. }
  19. ],
  20. "lang": [
  21. {
  22. "id": "lang",
  23. "value": "java"
  24. }
  25. ]
  26. }
  27. },
  28. {
  29. "id": "1josh",
  30. "label": "person",
  31. "type": "vertex",
  32. "properties": {
  33. "name": [
  34. {
  35. "id": "name",
  36. "value": "josh"
  37. }
  38. ],
  39. "age": [
  40. {
  41. "id": "age",
  42. "value": 32
  43. }
  44. ]
  45. }
  46. },
  47. ...
  48. ]
  49. }

For detailed API, please refer to RESTful-API

You can also visit localhost:8080/swagger-ui/index.html to check the API.

image

When using Swagger UI to debug the API provided by HugeGraph, if HugeGraph Server turns on authentication mode, you can enter authentication information on the Swagger page.

image

Currently, HugeGraph supports setting authentication information in two forms: Basic and Bearer.

image

7 Stop Server

  1. $cd *hugegraph-${version}
  2. $bin/stop-hugegraph.sh

8 Debug Server with IntelliJ IDEA

Please refer to Setup Server in IDEA

Last modified January 22, 2024: fix: server quickstart swagger-ui image link (#325) (f4b65194)