準備執行Gremlin的圖形化環境
背景
Gremlin是Apache TinkerPop框架下實現的圖遍歷語言,支援OLTP與OLAP,是目前圖資料庫領域主流的查詢語言,可類比SQL語言之於關係型資料庫。
HugeGraph是國內的一款開源圖資料庫,完全支援Gremlin語言。本文將講述如何基於HugeGraph搭建一個執行Gremlin的圖形化環境。
HugeGraph的github倉庫下有很多子專案,我們這裡只需要使用其中的兩個:hugegraph
和hugegraph-studio
。
部署HugeGraphServer
準備安裝包
方式一:原始碼編譯打包
進入hugegraph專案,克隆程式碼庫
進入終端
$ git clone git@github.com:hugegraph/hugegraph.git
完成後會在當前目錄下多出來一個hugegraph
的子目錄,不過這個目錄裡面的檔案是原始碼,我們需要編譯打包才能生成可以執行包。
進入hugegraph
目錄,執行命令:
$ git checkout release-0.7
$ mvn package -DskipTests
注意:一定要先切換分支,hugegraph主分支上版本已經升級到
0.8.0
了,但是studio似乎還沒有升級,為避免踩坑我們還是使用已釋出版。
經過一長串的控制檯輸出後,最後如果能看到BUILD SUCCESS
表示打包成功。
這時會在當前目錄下多出來一個子目錄
hugegraph-0.7.4
hugegraph-0.7.4.tar.gz
,這就是我們即將要使用可以執行的包。
本人有輕微強迫症,不喜歡原始碼和二進位制包放在一起,容易混淆,所以把hugegraph-0.7.4
拷到上一層目錄,然後刪除原始碼目錄,這樣上層目錄又迴歸清爽了。
$ mv hugegraph-0.7.4 ../hugegraph-0.7.4
$ cd ..
$ rm -rf hugegraph
到這兒安裝包就準備好了。不過,這樣操作是需要你本地裝了jdk
、git
和maven
命令列工具的,如果你沒有安裝也沒關係,我們還可以直接下載hugegraph
官方的release
包。
方法二:直接下載release
包
點選github
程式碼的上面的導航releases
可以看到hugegraph目前有兩個release,點選hugegraph-0.7.4.tar.gz
就開始下載了。
下載完之後解壓即可
$ tar -zxvf hugegraph-0.7.4.tar.gz
解壓完之後能看到一個hugegraph-0.7.4
目錄,這個目錄和用原始碼包打包生成的是一樣的。
下面講解如何配置引數。
配置引數
雖然標題叫配置引數,但其實hugegraph
的預設配置就已經能在大部分環境下直接使用了,不過還是說明一下幾個重要的配置項。
進入hugegraph-0.7.4
目錄,修改HugeGraphServer
提供服務的url (host + port)
$ vim conf/rest-server.properties
# bind url
restserver.url=http://127.0.0.1:8080
# gremlin url to connect
gremlinserver.url=http://127.0.0.1:8182
# graphs list with pair NAME:CONF_PATH
graphs=[hugegraph:conf/hugegraph.properties]
# authentication
#auth.require_authentication=
#auth.admin_token=
#auth.user_tokens=[]
restserver.url
就是HugeGraphServer
對外提供RESTful API
服務的地址,host
為127.0.0.1
時只能在本機訪問的,按需要修改其中的host
和port
部分即可。我這裡由於studio
也是準備在本地啟動,8080
埠也沒有其他服務佔用,所以不修改它。
graphs
是可供連線的圖名與配置項的鍵值對列表,hugegraph:conf/hugegraph.properties
表示通過HugeGraphServer
可以訪問到一個名為hugegraph
的圖例項,該圖的配置檔案路徑為conf/hugegraph.properties
。我們可以不用去管圖的配置檔案,按需要修改圖的名字即可。我這裡仍然沒有修改它。
初始化後端
hugegraph
啟動服務之前是需要手動初始化後端的,不過大家也不要看到“手動”兩個字就害怕,其實就是調一個命令的事。
$ bin/init-store.sh
Initing HugeGraph Store...
2018-09-07 16:02:12 1082 [main] [INFO ] com.baidu.hugegraph.cmd.InitStore [] - Init graph with config file: conf/hugegraph.properties
2018-09-07 16:02:12 1201 [main] [INFO ] com.baidu.hugegraph.HugeGraph [] - Opening backend store 'rocksdb' for graph 'hugegraph'
2018-09-07 16:02:12 1258 [main] [INFO ] com.baidu.hugegraph.backend.store.rocksdb.RocksDBStore [] - Opening RocksDB with data path: rocksdb-data/schema
2018-09-07 16:02:12 1417 [main] [INFO ] com.baidu.hugegraph.backend.store.rocksdb.RocksDBStore [] - Failed to open RocksDB 'rocksdb-data/schema' with database 'hugegraph', try to init CF later
2018-09-07 16:02:12 1445 [main] [INFO ] com.baidu.hugegraph.backend.store.rocksdb.RocksDBStore [] - Opening RocksDB with data path: rocksdb-data/system
2018-09-07 16:02:12 1450 [main] [INFO ] com.baidu.hugegraph.backend.store.rocksdb.RocksDBStore [] - Failed to open RocksDB 'rocksdb-data/system' with database 'hugegraph', try to init CF later
2018-09-07 16:02:12 1456 [main] [INFO ] com.baidu.hugegraph.backend.store.rocksdb.RocksDBStore [] - Opening RocksDB with data path: rocksdb-data/graph
2018-09-07 16:02:12 1461 [main] [INFO ] com.baidu.hugegraph.backend.store.rocksdb.RocksDBStore [] - Failed to open RocksDB 'rocksdb-data/graph' with database 'hugegraph', try to init CF later
2018-09-07 16: