JanusGraph安装和使用入门:JanuxGraph+Hbase方式

概述

本文讲述如何在单机上安装和使用JanusGraph。

JanusGraph安装说明

通过JanusGraph的架构可知,JanusGraph由4大部分组成,(后台存储系统,后台索引系统,Gremlin+JanusGraph组件,后台Cache系统)。而这几大部分可以分开安装,且支持灵活的配置。

本文讲说JanusGraph+Hbase+Cache的安装方式,这里Cache使用的是JanusGraph自己实现的服务。

另外,还要注意,这里的安装都在同一台机器上进行。本安装教程主要为了体验和测试JanusGraph的基本功能。

下载并安装

这里的安装分为两个部分,一个是安装hbase,一个是安装JanusGraph。

安装Hbase

在这里下载hbase:http://www.apache.org/dyn/closer.cgi/hbase/stable/

下载一个稳定版本,然后解压,并运行:

$ cd hbase-1.4.9
$ ./bin/start-hbase.sh
starting master, logging to ../logs/hbase-master-machine-name.local.out

安装JanusGraph

要注意:在安装JanusGraph时也有几种方式。这里启动Gremlin Console是一种交互式方式,而这种方式启动,预先把JanusGraph包内置在其中了,所以不需要单独再启动janusgraph服务。

wget https://github.com/JanusGraph/janusgraph/releases/download/v0.3.1/janusgraph-0.3.1-hadoop2.zip

unzip -x janusgraph-0.3.1-hadoop2.zip
cd janusgraph-0.3.1-hadoop2
./bin/gremlin.sh 

可以看一下janusgraph-hbase的配置文件的内容:

# JanusGraph configuration sample: HBase
#
# This file connects to HBase using a Zookeeper quorum
# (storage.hostname) consisting solely of localhost.  Zookeeper and
# the HBase services must already be running and available before
# starting JanusGraph with this file.
gremlin.graph=org.janusgraph.core.JanusGraphFactory

# The primary persistence provider used by JanusGraph.  This is required. 
# It should be set one of JanusGraph's built-in shorthand names for its
# standard storage backends (shorthands: berkeleyje, cassandrathrift,
# cassandra, astyanax, embeddedcassandra, cql, hbase, inmemory) or to the
# full package and classname of a custom/third-party StoreManager
# implementation.
#
# Default:    (no default value)
# Data Type:  String
# Mutability: LOCAL
storage.backend=hbase

# The hostname or comma-separated list of hostnames of storage backend
# servers.  This is only applicable to some storage backends, such as
# cassandra and hbase.
#
# Default:    127.0.0.1
# Data Type:  class java.lang.String[]
# Mutability: LOCAL
storage.hostname=127.0.0.1

# Whether to enable JanusGraph's database-level cache, which is shared
# across all transactions. Enabling this option speeds up traversals by
# holding hot graph elements in memory, but also increases the likelihood
# of reading stale data.  Disabling it forces each transaction to
# independently fetch graph elements from storage before reading/writing
# them.
#
# Default:    false
# Data Type:  Boolean
# Mutability: MASKABLE
cache.db-cache = true

# How long, in milliseconds, database-level cache will keep entries after
# flushing them.  This option is only useful on distributed storage
# backends that are capable of acknowledging writes without necessarily
# making them immediately visible.
#
# Default:    50
# Data Type:  Integer
# Mutability: GLOBAL_OFFLINE
#
# Settings with mutability GLOBAL_OFFLINE are centrally managed in
# JanusGraph's storage backend.  After starting the database for the first
# time, this file's copy of this setting is ignored.  Use JanusGraph's
# Management System to read or modify this value after bootstrapping.
cache.db-cache-clean-wait = 20

# Default expiration time, in milliseconds, for entries in the
# database-level cache. Entries are evicted when they reach this age even
# if the cache has room to spare. Set to 0 to disable expiration (cache
# entries live forever or until memory pressure triggers eviction when set
# to 0).
#
# Default:    10000
# Data Type:  Long
# Mutability: GLOBAL_OFFLINE
#
# Settings with mutability GLOBAL_OFFLINE are centrally managed in
# JanusGraph's storage backend.  After starting the database for the first
# time, this file's copy of this setting is ignored.  Use JanusGraph's
# Management System to read or modify this value after bootstrapping.
cache.db-cache-time = 180000

# Size of JanusGraph's database level cache.  Values between 0 and 1 are
# interpreted as a percentage of VM heap, while larger values are
# interpreted as an absolute size in bytes.
#
# Default:    0.3
# Data Type:  Double
# Mutability: MASKABLE
cache.db-cache-size = 0.5

使用JanusGraph

  • 基于hbase创建一个图
JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "hbase").open();

// 加载一个图
graph = JanusGraphFactory.open('conf/janusgraph-hbase.properties')

 g = graph.traversal();
 
// 查找一个图的边
saturn = g.V().has('name', 'saturn').next()

// 打印该边的值
g.V(saturn).valueMap()

参考文献

  • https://docs.janusgraph.org/latest/getting-started.html

你可能感兴趣的:(图计算)