JanusGraph Server

JanusGraph使用Gremlin Server引擎作为服务器组件来处理和回答客户机查询。当封装在JanusGraph中时,Gremlin服务器称为JanusGraph服务器。

JanusGraph服务器必须手动启动才能使用它。JanusGraph服务器提供了一种方法,可以针对其中托管的一个或多个JanusGraph实例远程执行Gremlin遍历。本节将描述如何使用WebSocket配置,以及如何配置JanusGraph服务器来处理客户端的HTTP请求。有关如何从不同语言连接到JanusGraph服务器的信息,请参阅连接到Connecting to JanusGraph。

入门

使用预打包发行版

注意:从0.5.1开始,它只是包含在完整包版本中。

JanusGraph预打包发行版预先配置为使用Cassandra和Elasticsearch配置来运行JanusGraph服务器。此配置默认为客户端应用程序,这些应用程序可以通过带有自定义子协议的WebSocket连接到JanusGraph服务器。有许多用不同语言开发的客户端可以帮助支持该子协议。使用Websocket界面最熟悉的客户端是Gremlin Console。快速入门版本包并不能代表生产安装,而是提供一种使用Janusgraph进行开发,运行测试以及查看组件如何连接在一起的方法。要使用此默认配置步骤如下:

  • 从Releases page下载最新的版本包文件janusgraph-$VERSION.zip。
  • 解压janusgraph-$VERSION,并进入解压文件夹中。
  • 运行bin/janusgraph.sh start这一步将启动Gremlin服务器,并将Cassandra/ES分成一个单独的进程。请注意:出于安全原因请使用非root用户启动ES和janusgraph.sh。
$ bin/janusgraph.sh start
Forking Cassandra...
Running `nodetool statusthrift`.. OK (returned exit status 0 and printed string "running").
Forking Elasticsearch...
Connecting to Elasticsearch (127.0.0.1:9300)... OK (connected to 127.0.0.1:9300).
Forking Gremlin-Server...
Connecting to Gremlin-Server (127.0.0.1:8182)... OK (connected to 127.0.0.1:8182).
Run gremlin.sh to connect.

连接到Gremlin服务器

运行janusgraph.sh之后,Gremlin服务器开始侦听WebSocket连接。测试连接的最简单方法是使用Gremlin Console。

运行bin/gremlin.sh启动Gremlin Console,使用:remote和:>命令向Gremlin服务器发出Gremlin请求。

$  bin/gremlin.sh\,,,/(o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.hadoop
plugin activated: tinkerpop.utilities
plugin activated: janusgraph.imports
plugin activated: tinkerpop.tinkergraph
gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Connected - localhost/127.0.0.1:8182
gremlin> :> graph.addVertex("name", "stephen")
==>v[256]
gremlin> :> g.V().values('name')
==>stephen

The :remote command tells the console to configure a remote connection to Gremlin Server using the conf/remote.yaml file to connect. That file points to a Gremlin Server instance running on localhost. The :> is the "submit" command which sends the Gremlin on that line to the currently active remote. Instead of prefixing every single script with :>, the command :remote console can be executed once to implicitly send all subsequent scripts to the current remote connection. By default remote connections are sessionless, meaning that each line sent in the console is interpreted as a single request. Multiple statements can be sent on a single line using a semicolon as the delimiter.

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> graph
==>standardjanusgraph[cql:[127.0.0.1]]
gremlin> g
==>graphtraversalsource[standardjanusgraph[cql:[127.0.0.1]], standard]
gremlin> g.V()
gremlin> user = "Chris"
==>Chris
gremlin> graph.addVertex("name", user)
No such property: user for class: Script21
Type ':help' or ':h' for help.
Display stack trace? [yN]

或者,您可以通过在创建连接时建立带Session的console。在同一个session里面的console建立的变量可以重用。如下所示:

gremlin> :remote connect tinkerpop.server conf/remote.yaml session
==>Configured localhost/127.0.0.1:8182-[9acf239e-a3ed-4301-b33f-55c911e04052]
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182]-[9acf239e-a3ed-4301-b33f-55c911e04052] - type ':remote console' to return to local mode
gremlin> g.V()
gremlin> user = "Chris"
==>Chris
gremlin> user
==>Chris
gremlin> graph.addVertex("name", user)
==>v[4344]
gremlin> g.V().values('name')
==>Chris

预包装配送后清理????

如果要重新启动并删除数据库和日志,可以使用./bin/janusgraph.sh clean命令。在运行清理操作之前,应停止服务器。

$ cd /Path/to/janusgraph/janusgraph-{project.version}/
$ ./bin/janusgraph.sh stop
Killing Gremlin-Server (pid 91505)...
Killing Elasticsearch (pid 91402)...
Killing Cassandra (pid 91219)...
$ ./bin/janusgraph.sh clean
Are you sure you want to delete all stored data and logs? [y/N] y
Deleted data in /Path/to/janusgraph/janusgraph-{project.version}/db
Deleted logs in /Path/to/janusgraph/janusgraph-{project.version}/log

JanusGraph Server提供WebSocket服务

入门中描述的默认配置已经是WebSocket配置。如果要更改默认配置以使用Cassandra或HBase环境,请执行以下步骤:

JanusGraph Server提供WebSocket服务配置

1. 首先测试本地到JanusGraph数据库的连接。可以通过Gremlin Console或者应用程序测试连接。对环境中./conf目录下的properties配置文件适当的修改。例如:编辑./conf/janusgraph-hbase.properties配置文件以确保storage.backend, storage.hostname and storage.hbase.table等配置参数的正确性。有关更多存储后端的配置,请参照Storage Backends。确保属性文件包含以下行:

gremlin.graph=org.janusgraph.core.JanusGraphFactory

2. 一旦本地配置文件测试通过后,将属性文件从路径./conf拷贝到路径./conf/gremlin-server

cp conf/janusgraph-hbase.properties
conf/gremlin-server/socket-janusgraph-hbase-server.properties

3. 拷贝./conf/gremlin-server/gremlin-server.yaml文件成为一个新文件socket-gremlin-server.yaml。如果需要引用文件的原始版本,请按照此操作执行。

cp conf/gremlin-server/gremlin-server.yaml
conf/gremlin-server/socket-gremlin-server.yaml

4. 按照如下示例对http-gremlin-server.yaml文件进行修改编辑。

a. 如果计划从本地主机以外的其他设备连接到JanusGraph服务器,将host更新为IP:

host: 10.10.10.100

b. 将channelizer更新为HttpChannelizer:

channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer

c. 更新graphs部分以指向新的属性文件,以便JanusGraph服务器可以找到并连接到JanusGraph实例:

    graphs: { graph:conf/gremlin-server/http-janusgraph-hbase-server.properties}

5. 启动Janusgraph并指定刚才配置的文件:

bin/gremlin-server.sh ./conf/gremlin-server/http-gremlin-server.yaml

6. JanusGraph服务器现在应该在HTTP模式下运行,并且可以进行测试。curl可用于验证服务器是否正常工作:

      curl -XPOST -Hcontent-type:application/json -d *{"gremlin":"g.V().count()"}* [IP for JanusGraph server host](http://):8182 

JanusGraph Server同时提供WebSocket和HTTP服务配置

0.2.0版本开始JanusGraph支持在同一个端口同时接收WebSocket和HTTP两种服务。通过在gremlin-server.yaml配置文件中修改如下配置:

channelizer: org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer

JanusGraph Server高级配置

对HTTP服务配置身份认证

重要:在以下的所有示例中,身份验证的用户名和密码数据存储的DB与操作的graph所在DB是分开的。

HTTP Basic 认证配置

如下所示对gremlin-server.yaml文件进行配置修改从而开启HTTP Basic 认证:

authentication: {authenticator: org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.JanusGraphSimpleAuthenticator,authenticationHandler: org.apache.tinkerpop.gremlin.server.handler.HttpBasicAuthenticationHandler,config: {defaultUsername: user,defaultPassword: password,credentialsDb: conf/janusgraph-credentials-server.properties}}

首先通过以下不带身份认证信息的命令去请求:

curl -v -XPOST http://localhost:8182 -d '{"gremlin": "g.V().count()"}'

执行结果返回认证未通过的401错误状态码,下面我们再使用带有正确认证信息的命令去请求:

curl -v -XPOST http://localhost:8182 -d '{"gremlin": "g.V().count()"}' -u user:password

执行结果返回正确的200状态码和返回结果4。

对WebSocket服务配置身份认证

通过对gremlin-server.yaml配置文件进行如下修改来对WebSocket服务开启SASL认证:

authentication: {authenticator: org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.JanusGraphSimpleAuthenticator,authenticationHandler: org.apache.tinkerpop.gremlin.server.handler.SaslAuthenticationHandler,config: {defaultUsername: user,defaultPassword: password,credentialsDb: conf/janusgraph-credentials-server.properties}
}

如果你直接通过Gremlin Console去访问带有SASL认证的Janusgraph Server,在yaml配置文件里面配上正确的username和password,如下所示:

username: user
password: password

对WebSocket和HTTP服务同时配置身份认证

通过对channelizer绑定SaslAndHMACAuthenticator配置,就可以同时为Websocket开启SASL认证和HTTP开启basic以及HMAC两种方式的认证。具体gremlin-server.yaml配置文件修改如下:

authentication: {authenticator: org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator,authenticationHandler: org.janusgraph.graphdb.tinkerpop.gremlin.server.handler.SaslAndHMACAuthenticationHandler,config: {defaultUsername: user,defaultPassword: password,hmacSecret: secret,credentialsDb: conf/janusgraph-credentials-server.properties}
}

下面示例利用HMAC认证和HTTP协议请求Janusgraph Server,首先利用username访问/session

获取一个有限时间内(有效时常通过authentication.config中的tokenTimeout参数来设定)有效的token,如下所示

curl http://localhost:8182/session -XGET -u user:password{"token": "dXNlcjoxNTA5NTQ2NjI0NDUzOkhrclhYaGhRVG9KTnVSRXJ5U2VpdndhalJRcVBtWEpSMzh5WldqRTM4MW89"}

然后携带这个token去请求Janusgraph Server,如下所示:

curl -v http://localhost:8182/session -XPOST -d '{"gremlin": "g.V().count()"}' -H "Authorization: Token dXNlcjoxNTA5NTQ2NjI0NDUzOkhrclhYaGhRVG9KTnVSRXJ5U2VpdndhalJRcVBtWEpSMzh5WldqRTM4MW89"

使用TinkerPop Gremlin Server来配置和实例化JanusGraph Server

建议使用Janusgraph版本包启动JanusGraph Server,对此部分这里不做翻译。

JanusGraph Server相关推荐

  1. 图数据库JanusGraph实战[6]: JanusGraph+HBase+ElasticSearch的环境搭建

    图数据库JanusGraph实战[6]: JanusGraph+HBase+ElasticSearch的环境搭建 作者:胡佳辉(家辉)  日期:2019年01月14日 CSDN博客:https://b ...

  2. JanusGraph服务器

    JanusGraph 服务器 JanusGraph使用Gremlin服务器引擎作为服务器组件来处理和回答客户机查询.当封装在JanusGraph中时,Gremlin服务器称为JanusGraph服务器 ...

  3. 「JanusGraph」图形数据库 - 技术选型调研

    JanusGraph各组件版本兼容性匹配表 JanusGraph JanusGraph提供多种后端存储和后端索引,使其能够更灵活的部署.本章介绍了几种可能的部署场景,以帮助解决这种灵活性带来的复杂性. ...

  4. 8. JanusGraph部署方案

    JanusGraph提供了多种存储和索引后端选项,可以灵活地部署它们.本章介绍了一些可能的部署方案,以帮助解决这种灵活性带来的复杂性. 在讨论不同的部署方案之前,了解JanusGraph本身和后端存储 ...

  5. 【JanusGraph】第七章:JanusGraph服务

    JanusGraph使用Gremlin Server作为服务组件对客户端请求进行请求处理响应.当JanusGraph打包的时候,Gremlin Server就被称为JanusGraph服务. Janu ...

  6. 图数据库JanusGraph实战[5]: JanusGraph可视化之Gephi

    图数据库JanusGraph实战[5]: JanusGraph可视化之Gephi 作者:胡佳辉(家辉)  日期:2018年12月29日 CSDN博客:https://blog.csdn.net/gob ...

  7. 连接Janusgraph时报Unable to determine Elasticsearch server version. Default to FIVE.异常

    连接Janusgraph时报Unable to determine Elasticsearch server version. Default to FIVE.异常 采用的 janusgraph + ...

  8. 开启JanusGraph中的监控功能

    开启JanusGraph中的metrics功能进行监控: 1.在配置文件中指定配置项 # Copyright 2019 JanusGraph Authors # # Licensed under th ...

  9. java 连接janusgraph_基于JanusGraph的大数据图数据库

    导读 知识图谱是近来很火的概念,很多领域都希望能用知识图谱解决一些问题.在零售领域其实也有使用知识图谱的场景,比如阿里使用知识图谱进行商品智能导购以及商品"巡检",而我想试验着把知 ...

  10. JanusGraph 安装

    下载地址:https://github.com/JanusGraph/janusgraph/releases/ 版本:Version 0.3.2 (June 16, 2019) 安装 解压 janus ...

最新文章

  1. Python七大原则,24种设计模式
  2. scheduled只执行一次_升级@Scheduled-分布式定时任务
  3. java自定义注解实现日志功能
  4. wamp 配置 mysql_PHPWAMP配置应该如何修改,Web服务器、php、mysql的具体配置修改
  5. linux 省内存的桌面,Linux_在Linux中可视化显示内存占用情况的方法,物理内存不足对Linux桌面系统 - phpStudy...
  6. python 相对路径报错_小白学 Python(18):基础文件操作
  7. LeetCode(1002)——查找常用字符(JavaScript)
  8. Shell脚本学习-阶段七-信息过滤磁盘分区
  9. do{} while(0)
  10. 协方差检验用在什么地方_胶带还有什么隐藏功能,看看这几个,家里很多地方用得到...
  11. OS - 计算机组成原理及CPU主频揭秘
  12. 网上抢购茅台催生黄牛党:必须严打各类抢购软件
  13. 页面里引入电子表字体
  14. 哪个相机可以拍gif动图_摄制 GIF 动图的相机软件
  15. 【Unity】Obi插件系列(七)—— Obi Emitters
  16. 鏡頭上的 F 與 f 之區別
  17. 桌面壁纸 Lively wallpape
  18. [林达华]介绍几本数学书
  19. 我的markdown编辑器
  20. python换零钱_python动态规划-零钱兑换

热门文章

  1. python矩阵乘法分治算法_详解矩阵乘法中的Strassen算法
  2. 双向链表排序 c++
  3. mysql中查询编辑器_万能数据库查看器|Universal SQL Editor(万能SQL编辑器)下载 v1.8 官方版 - 比克尔下载...
  4. 汉诺塔(Hanoi)图解递归算法
  5. 【基于obs插件-5】-屏幕截图
  6. 如何设计最惊艳的PPT
  7. Behavior Designer 行为树中文版教程
  8. mina简单实用_Mina框架的简单例子
  9. word2vec中的数学原理详解
  10. Python渗透测试之流量分析:流量嗅探工具编程