跳转到主要内容

文档 1.0 版本已不再积极维护,你当前浏览的是一份归档快照。 最新文档请参阅 最新版本。

HugeGraph 配置

1 概述

配置文件的目录为 hugegraph-release/conf,所有关于服务和图本身的配置都在此目录下。

主要的配置文件包括:gremlin-server.yaml、rest-server.properties 和 hugegraph.properties

HugeGraphServer 内部集成了 GremlinServer 和 RestServer,而 gremlin-server.yaml 和 rest-server.properties 就是用来配置这两个Server的。

  • GremlinServer:GremlinServer接受用户的gremlin语句,解析后转而调用Core的代码。
  • RestServer:提供RESTful API,根据不同的HTTP请求,调用对应的Core API,如果用户请求体是gremlin语句,则会转发给GremlinServer,实现对图数据的操作。

下面对这三个配置文件逐一介绍。

2 gremlin-server.yaml

gremlin-server.yaml 文件默认的内容如下:

 1# host and port of gremlin server, need to be consistent with host and port in rest-server.properties
 2#host: 127.0.0.1
 3#port: 8182
 4
 5# timeout in ms of gremlin query
 6scriptEvaluationTimeout: 30000
 7
 8channelizer: org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer
 9graphs: {
10  hugegraph: conf/hugegraph.properties
11}
12scriptEngines: {
13  gremlin-groovy: {
14    plugins: {
15      com.baidu.hugegraph.plugin.HugeGraphGremlinPlugin: {},
16      org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
17      org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {
18        classImports: [
19          java.lang.Math,
20          com.baidu.hugegraph.backend.id.IdGenerator,
21          com.baidu.hugegraph.type.define.Directions,
22          com.baidu.hugegraph.type.define.NodeRole,
23          com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser,
24          com.baidu.hugegraph.traversal.algorithm.CustomizedCrosspointsTraverser,
25          com.baidu.hugegraph.traversal.algorithm.FusiformSimilarityTraverser,
26          com.baidu.hugegraph.traversal.algorithm.HugeTraverser,
27          com.baidu.hugegraph.traversal.algorithm.NeighborRankTraverser,
28          com.baidu.hugegraph.traversal.algorithm.PathsTraverser,
29          com.baidu.hugegraph.traversal.algorithm.PersonalRankTraverser,
30          com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser,
31          com.baidu.hugegraph.traversal.algorithm.SubGraphTraverser,
32          com.baidu.hugegraph.traversal.optimize.Text,
33          com.baidu.hugegraph.traversal.optimize.TraversalUtil,
34          com.baidu.hugegraph.util.DateUtil
35        ],
36        methodImports: [java.lang.Math#*]
37      },
38      org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {
39        files: [scripts/empty-sample.groovy]
40      }
41    }
42  }
43}
44serializers:
45  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1,
46      config: {
47        serializeResultToString: false,
48        ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry]
49      }
50  }
51  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0,
52      config: {
53        serializeResultToString: false,
54        ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry]
55      }
56  }
57  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0,
58      config: {
59        serializeResultToString: false,
60        ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry]
61      }
62  }
63  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0,
64      config: {
65        serializeResultToString: false,
66        ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry]
67      }
68  }
69metrics: {
70  consoleReporter: {enabled: false, interval: 180000},
71  csvReporter: {enabled: false, interval: 180000, fileName: ./metrics/gremlin-server-metrics.csv},
72  jmxReporter: {enabled: false},
73  slf4jReporter: {enabled: false, interval: 180000},
74  gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST},
75  graphiteReporter: {enabled: false, interval: 180000}
76}
77maxInitialLineLength: 4096
78maxHeaderSize: 8192
79maxChunkSize: 8192
80maxContentLength: 65536
81maxAccumulationBufferComponents: 1024
82resultIterationBatchSize: 64
83writeBufferLowWaterMark: 32768
84writeBufferHighWaterMark: 65536
85ssl: {
86  enabled: false
87}

上面的配置项很多,但目前只需要关注如下几个配置项:channelizer 和 graphs。

  • graphs:GremlinServer 启动时需要打开的图,该项是一个 map 结构,key 是图的名字,value 是该图的配置文件路径;
  • channelizer:GremlinServer 与客户端有两种通信方式,分别是 WebSocket 和 HTTP(默认)。如果选择 WebSocket, 用户可以通过 Gremlin-Console 快速体验 HugeGraph 的特性,但是不支持大规模数据导入, 推荐使用 HTTP 的通信方式,HugeGraph 的外围组件都是基于 HTTP 实现的;

默认GremlinServer是服务在 localhost:8182,如果需要修改,配置 host、port 即可

  • host:部署 GremlinServer 机器的机器名或 IP,目前 HugeGraphServer 不支持分布式部署,且GremlinServer不直接暴露给用户;
  • port:部署 GremlinServer 机器的端口;

同时需要在 rest-server.properties 中增加对应的配置项 gremlinserver.url=http://host:port

3 rest-server.properties

rest-server.properties 文件的默认内容如下:

 1# bind url
 2restserver.url=http://127.0.0.1:8080
 3# gremlin server url, need to be consistent with host and port in gremlin-server.yaml
 4#gremlinserver.url=http://127.0.0.1:8182
 5
 6# graphs list with pair NAME:CONF_PATH
 7graphs=[hugegraph:conf/hugegraph.properties]
 8
 9# authentication
10#auth.authenticator=
11#auth.admin_token=
12#auth.user_tokens=[]
13
14server.id=server-1
15server.role=master
  • restserver.url:RestServer 提供服务的 url,根据实际环境修改;
  • graphs:RestServer 启动时也需要打开图,该项为 map 结构,key 是图的名字,value 是该图的配置文件路径;

注意:gremlin-server.yaml 和 rest-server.properties 都包含 graphs 配置项,而 init-store 命令是根据 gremlin-server.yaml 的 graphs 下的图进行初始化的。

配置项 gremlinserver.url 是 GremlinServer 为 RestServer 提供服务的 url,该配置项默认为 http://localhost:8182,如需修改,需要和 gremlin-server.yaml 中的 host 和 port 相匹配;

4 hugegraph.properties

hugegraph.properties 是一类文件,因为如果系统存在多个图,则会有多个相似的文件。该文件用来配置与图存储和查询相关的参数,文件的默认内容如下:

 1# gremlin entrence to create graph
 2gremlin.graph=com.baidu.hugegraph.HugeFactory
 3
 4# cache config
 5#schema.cache_capacity=100000
 6# vertex-cache default is 1000w, 10min expired
 7#vertex.cache_capacity=10000000
 8#vertex.cache_expire=600
 9# edge-cache default is 100w, 10min expired
10#edge.cache_capacity=1000000
11#edge.cache_expire=600
12
13# schema illegal name template
14#schema.illegal_name_regex=\s+|~.*
15
16#vertex.default_label=vertex
17
18backend=rocksdb
19serializer=binary
20
21store=hugegraph
22
23raft.mode=false
24raft.safe_read=false
25raft.use_snapshot=false
26raft.endpoint=127.0.0.1:8281
27raft.group_peers=127.0.0.1:8281,127.0.0.1:8282,127.0.0.1:8283
28raft.path=./raft-log
29raft.use_replicator_pipeline=true
30raft.election_timeout=10000
31raft.snapshot_interval=3600
32raft.backend_threads=48
33raft.read_index_threads=8
34raft.queue_size=16384
35raft.queue_publish_timeout=60
36raft.apply_batch=1
37raft.rpc_threads=80
38raft.rpc_connect_timeout=5000
39raft.rpc_timeout=60000
40
41search.text_analyzer=jieba
42search.text_analyzer_mode=INDEX
43
44# rocksdb backend config
45#rocksdb.data_path=/path/to/disk
46#rocksdb.wal_path=/path/to/disk
47
48# cassandra backend config
49cassandra.host=localhost
50cassandra.port=9042
51cassandra.username=
52cassandra.password=
53#cassandra.connect_timeout=5
54#cassandra.read_timeout=20
55#cassandra.keyspace.strategy=SimpleStrategy
56#cassandra.keyspace.replication=3
57
58# hbase backend config
59#hbase.hosts=localhost
60#hbase.port=2181
61#hbase.znode_parent=/hbase
62#hbase.threads_max=64
63
64# mysql backend config
65#jdbc.driver=com.mysql.jdbc.Driver
66#jdbc.url=jdbc:mysql://127.0.0.1:3306
67#jdbc.username=root
68#jdbc.password=
69#jdbc.reconnect_max_times=3
70#jdbc.reconnect_interval=3
71#jdbc.sslmode=false
72
73# postgresql & cockroachdb backend config
74#jdbc.driver=org.postgresql.Driver
75#jdbc.url=jdbc:postgresql://localhost:5432/
76#jdbc.username=postgres
77#jdbc.password=
78
79# palo backend config
80#palo.host=127.0.0.1
81#palo.poll_interval=10
82#palo.temp_dir=./palo-data
83#palo.file_limit_size=32

重点关注未注释的几项:

  • gremlin.graph:GremlinServer 的启动入口,用户不要修改此项;
  • backend:使用的后端存储,可选值有 memory、cassandra、scylladb 和 rocksdb;
  • serializer:主要为内部使用,用于将 schema、vertex 和 edge 序列化到后端,对应的可选值为 text、cassandra、scylladb 和 binary;(注:rocksdb后端值需是binary,其他后端backend与serializer值需保持一致,如hbase后端该值为hbase)
  • store:图存储到后端使用的数据库名,在 cassandra 和 scylladb 中就是 keyspace 名,此项的值与 GremlinServer 和 RestServer 中的图名并无关系,但是出于直观考虑,建议仍然使用相同的名字;
  • cassandra.host:backend 为 cassandra 或 scylladb 时此项才有意义,cassandra/scylladb 集群的 seeds;
  • cassandra.port:backend 为 cassandra 或 scylladb 时此项才有意义,cassandra/scylladb 集群的 native port;
  • rocksdb.data_path:backend 为 rocksdb 时此项才有意义,rocksdb 的数据目录
  • rocksdb.wal_path:backend 为 rocksdb 时此项才有意义,rocksdb 的日志目录
  • admin.token: 通过一个token来获取服务器的配置信息,例如:http://localhost:8080/graphs/hugegraph/conf?token=162f7848-0b6d-4faf-b557-3a0797869c55

5 多图配置

我们的系统是可以存在多个图的,并且各个图的后端可以不一样,比如图 hugegraph 和 hugegraph1,其中 hugegraph 以 cassandra 作为后端,hugegraph1 以 rocksdb作为后端。

配置方法也很简单:

修改 gremlin-server.yaml

在 gremlin-server.yaml 的 graphs 域中添加一个键值对,键为图的名字,值为图的配置文件路径,比如:

1graphs: {
2  hugegraph: conf/hugegraph.properties,
3  hugegraph1: conf/hugegraph1.properties
4}

修改 rest-server.properties

在 rest-server.properties 的 graphs 域中添加一个键值对,键为图的名字,值为图的配置文件路径,比如:

1graphs=[hugegraph:conf/hugegraph.properties, hugegraph1:conf/hugegraph1.properties]

添加 hugegraph1.properties

拷贝 hugegraph.properties,命名为 hugegraph1.properties,修改图对应的数据库名以及关于后端部分的参数,比如:

1store=hugegraph1
2
3...
4
5backend=rocksdb
6serializer=binary

停止 Server,初始化执行 init-store.sh(为新的图创建数据库),重新启动 Server

1$ bin/stop-hugegraph.sh
2$ bin/init-store.sh
3$ bin/start-hugegraph.sh