圖數據庫cayley+mongo的起航之旅


圖數據庫,目前比較主流的可能是Neo4j以及cayley了。但是,由於Neo4j只有社區版是免費的,所以,選擇cayley作為項目的最終選擇!

 

今天就簡單的介紹下,我的起航之旅。

 

1.安裝go語言環境

去官方地址https://golang.org/dl/,下載穩定版本https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz
解壓,並將其配置到環境變量。

[root@localhost tkrobot]# tar -C /usr/local -xvf go1.8.1.linux-amd64.tar.gz

配置環境變量:

vim /etc/profile
export PATH=$JAVA_HOME/bin:$MONGODB_PATH/bin:/usr/local/go/bin:$PATH
export GOPATH=/usr/local/go

 

2.下載cayley的binary安裝程序

去官方的下載網址https://github.com/cayleygraph/cayley/releases,選擇下載穩定版的最新版本,我的環境是Redhat7,64位的linux環境。下載v.0.6.1的AMD64位linux版本。

https://github.com/cayleygraph/cayley/releases/download/v0.6.1/cayley_v0.6.1_linux_amd64.tar.gz

這個地址,若下載有問題,可以去這個地址下載.

cayley這個是二進制程序,解壓后直接可以使用。

 

3.配置cayley

解壓下載的cayley文件gz包,將里面的cayley.cfg.example拷貝到/etc/下,重命名為cayley.cfg

[root@localhost cayley_v0.6.1_linux_amd64]# cp cayley.cfg.example /etc/cayley.cfg

將/etc/cayley.cfg的內容修改為如下:

{
"database": "mongo",
"db_path": "10.90.7.10:27017",
"read_only": false,
"listen_host":"0.0.0.0",
"listen_port":"64100"
}

mongo數據庫的安裝過程,請參照我前面的博客spring4與mongodb的集成,還是很簡單的。

 

4.加載數據到cayley,這個過程,cayley用到了cayley.cfg這個配置文件

[root@localhost cayley_v0.6.1_linux_amd64]# ./cayley load -quads data/testdata.nq --alsologtostderr=true
I0516 12:58:06.691039   30116 cayley.go:190] Cayley v0.6.1 built 2017-04-12T11:41:20-07:00
I0516 12:58:06.691323   30116 cayley.go:197] Setting GOMAXPROCS to 24
I0516 12:58:06.691337   30116 db.go:51] Opening quad store "mongo" at 10.90.7.10:27017
I0516 12:58:06.711636   30116 db.go:67] Opening replication method "single"

此時,連接到mongo數據庫,可以看到,多了一個cayley的db。里面有3個collection。

> show dbs;
admin     0.000GB
cayley    0.000GB
local     0.000GB
robotkdb  0.000GB
> use cayley
switched to db cayley
> show collections
log
nodes
quads
> 

 

5.測試

命令行的方式操作cayley:

[root@localhost cayley_v0.6.1_linux_amd64]# ./cayley repl
creating new history file: ".cayley_history"
cayley> :a
Error: not a valid quad: incomplete N-Quad
cayley> 2+2

=> 4
-----------
1 Result
Elapsed time: 0.108118 ms

cayley> 2*9

=> 18
-----------
1 Result
Elapsed time: 0.106414 ms

cayley> graph.Vertex("<dani>").All()

****
id : <dani>
=> <nil>
-----------
2 Results
Elapsed time: 0.693895 ms

cayley> 

 

http的方式操作cayley:

[root@localhost cayley_v0.6.1_linux_amd64]# ./cayley http
Serving Gephi GraphStream at http://localhost:64100/gephi/gs
Cayley now listening on 0.0.0.0:64100[root@localhost cayley_v0.6.1_linux_amd64]# ./cayley http
Serving Gephi GraphStream at http://localhost:64100/gephi/gs
Cayley now listening on 0.0.0.0:64100

這個時候,會出現html的操作界面。我這里有截圖,以示安裝效果!

 

下面這個圖,是寫四元組的示例:

 

到此,cayley基於mongo的環境就算完成。至於cayley的具體如何使用,比如增刪改查之類的,下一個博文進行介紹!

周末愉快!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM