环境:
- Centos 7
- Java 8
- HBase 2.2.4
- ElasticSearch 7.6.1
一、下载JanusGraph
https://github.com/JanusGraph/janusgraph/releases
wget https://github.com/JanusGraph/janusgraph/releases/download/v0.5.2/janusgraph-0.5.2.zip
二、解压
unzip janusgraph-0.5.2.zip
三、修改配置
cd janusgraph-0.5.2
vi conf/janusgraph-hbase-es.properties
修改
# 注意:这里填的是zookeeper IP, 如果zk和hbase是分开部署的,千万别搞错了,只填IP不用写端口
storage.backend=127.0.0.1
#如果zk的端口默认2181,否则修改storage.port的值
storage.port=2181
# elasticsearch 配置列子
index.search.backend=elasticsearch
index.search.hostname=10.0.1.1:9200,10.0.1.2:9200,10.0.1.3:9200
# 需要鉴权的配置,根据鉴权方式查询官网,以下是用户名/密码鉴权的配置例子
index.search.elasticsearch.http.auth.type=basic
index.search.elasticsearch.http.auth.basic.username=admin
index.search.elasticsearch.http.auth.basic.password=admin
四、运行官网例子
sh bin/gremlin.sh
graph = JanusGraphFactory.open('conf/janusgraph-hbase-es.properties')
GraphOfTheGodsFactory.load(graph)
注意:这个地方在我的环境中会出现错误,出现如下错误:
ERROR org.janusgraph.graphdb.database.StandardJanusGraph - Could not commit transaction [1] due to storage exception in system-commit
出现这个原因主要是时间格式没有配上,修改配置文件conf/janusgraph-hbase-es.properties,增加配置项如下
graph.timestamps=MICRO # 默认是MILLI
重新运行即可。
五、完整例子
graph = JanusGraphFactory.open('conf/janusgraph-hbase-es.properties')
GraphOfTheGodsFactory.load(graph) # 下次重新打开不需要执行此行
g = graph.traversal()
saturn = g.V().has('name', 'saturn').next() # 输出的日志和官网可能不一致,但是不影响使用
g.V(saturn).valueMap()
g.V(saturn).in('father').in('father').values('name')
六、参考资料
https://github.com/JanusGraph/janusgraph/releases
https://github.com/JanusGraph/janusgraph/blob/master/docs/getting-started/basic-usage.md