Cassandra與HugeGraph的安裝配置

環(huán)境要求

1、虛擬機(CentOS7.3)
2、關閉防火墻和SELinux
3、配置好JDK

Cassandra的安裝啟動

1、下載Cassandra安裝包(使用3.0以上的,為兼容hugegraph)

2、新建數(shù)據(jù)存儲路徑

  • mkdir /var/lib/cassandra/data
  • mkdir /var/lib/cassandra/commitlog
  • mkdir /var/lib/cassandra/saved_caches

3、配置${CASSANDRA_HOME}/conf/cassandra.yaml

(${CASSANDRA_HOME}為Cassandra安裝路徑)

  • 基本配置
data_file_directories:
    - /var/lib/cassandra/data  // 數(shù)據(jù)文件存放路徑。打開這個注釋,注意不要合并成一行,合并成一行好像會出問題,這里要與前面新建的文件夾對應。
commitlog_directory: /var/lib/cassandra/commitlog // 操作日志文件存放路徑。打開注釋,與前面新建的文件夾對應。
saved_caches_directory: /var/lib/cassandra/saved_caches  // 緩存文件存放路徑。打開注釋,與前面新建的文件夾對應。
  • 開啟默認密碼
authenticator: PasswordAuthenticator  // 默認AllowAllAuthenticator
authorizer: CassandraAuthorizer // 默認AllowAllAuthorizer 

啟動后使用:./cqlsh -u cassandra -p cassandra ip port

  • CREATE USER myusername WITH PASSWORD 'mypassword' SUPERUSER;(這里用戶有兩種,一個是superuser,一種是nosuperuser)
rpc_address: 0.0.0.0 // 用于監(jiān)聽客戶端連接的地址,默認127.0.0.1
broadcast_rpc_address: 1.2.3.4 // 若rpc_address設置0.0.0.0,則要放開此注釋
  • 集群模式
cluster_name: 'xxx'  // 集群名稱。同一個集群要使用同一名稱
- seeds: "192.168.x.x"  // 集群種子節(jié)點ip,新加入集群的節(jié)點從種子節(jié)點中同步數(shù)據(jù)??膳渲枚鄠€,中間用逗號隔開。
listen_address: 127.0.0.1  // 需要監(jiān)聽的IP或主機名。改成本機IP

4、啟動服務(啟動后默認端口為9042)

cd ${CASSANDRA_HOME}/bin
./cassandra -R   # root用戶啟動

部署 HugeGraph

1、先安裝 hugegraph-0.7.4

2、配置${hugegraph_home}/conf:rest-server.properties和hugegraph.properties

  • rest-server.properties
# bind url
restserver.url=http://127.0.0.1:8080    // 如果被占用,可改為其他端口,等會配置hugegraph-studio用到

# 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=[]
  • hugegraph.properties(以Cassandra數(shù)據(jù)庫為例)
# gremlin entrence to create graph
gremlin.graph=com.baidu.hugegraph.HugeFactory

# cache config
#schema.cache_capacity=1048576
#graph.cache_capacity=10485760
#graph.cache_expire=600

# schema illegal name template
#schema.illegal_name_regex=\s+|~.*

#vertex.default_label=vertex

backend=cassandra
serializer=cassandra
store=cassandra   // 為需要連得Cassandra的keyspace,相當于Mysql的庫

# rocksdb backend config
#backend=rocksdb
#serializer=binary
#rocksdb.data_path=/path/to/disk
#rocksdb.wal_path=/path/to/disk

# cassandra backend config
cassandra.host=localhost    // Cassandra安裝主機的IP
cassandra.port=9042           // hugegraph支持的端口目前限制在[1024-10000]
cassandra.username=
cassandra.password=
#cassandra.connect_timeout=5
#cassandra.read_timeout=20
#cassandra.keyspace.strategy=SimpleStrategy
#cassandra.keyspace.replication=3

# mysql backend config
#jdbc.url=jdbc:mysql://127.0.0.1:3306
#jdbc.username=root
#jdbc.password=
#jdbc.reconnect_max_times=3
#jdbc.reconnect_interval=3

# palo backend config
#palo.host=127.0.0.1
#palo.poll_interval=10
#palo.temp_dir=./palo-data
#palo.file_limit_size=32

初始化數(shù)據(jù)庫${hugegraph_home}/bin/init-store.sh

$ bin/init-store.sh
Initing HugeGraph Store...
2018-12-06 11:26:51 1424  [main] [INFO ] com.baidu.hugegraph.HugeGraph [] - Opening backend store: 'cassandra'
2018-12-06 11:26:52 2389  [main] [INFO ] com.baidu.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph, try init keyspace later
2018-12-06 11:26:52 2472  [main] [INFO ] com.baidu.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph, try init keyspace later
2018-12-06 11:26:52 2557  [main] [INFO ] com.baidu.hugegraph.backend.store.cassandra.CassandraStore [] - Failed to connect keyspace: hugegraph, try init keyspace later
2018-12-06 11:26:53 2797  [main] [INFO ] com.baidu.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: graph
2018-12-06 11:26:53 2945  [main] [INFO ] com.baidu.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: schema
2018-12-06 11:26:53 3044  [main] [INFO ] com.baidu.hugegraph.backend.store.cassandra.CassandraStore [] - Store initialized: graph
2018-12-06 11:26:53 3046  [pool-3-thread-1] [INFO ] com.baidu.hugegraph.backend.Transaction [] - Clear cache on event 'store.init'

啟動服務${hugegraph_home}/bin/start-hugegraph.sh

$ bin/start-hugegraph.sh
Starting HugeGraphServer...
Connecting to HugeGraphServer (http://127.0.0.1:8080/graphs)....OK

部署 HugeGraphStudio

1、下載安裝 hugegraph-studio

2、配置${hugegraph-studio_home}/conf/hugegraph-studio.properties

studio.server.port=8088  // 頁面訪問端口
studio.server.host=localhost   // 允許訪問地址,建議改為 0.0.0.0

graph.server.host=localhost  // hugegraph服務的地址
graph.server.port=8080       // hugegraph服務的端口
graph.name=hugegraph       // 服務的名字,不更改,否則頁面Gremlin執(zhí)行命令時報錯

# the directory name released by react
studio.server.ui=ui
# the file location of studio-api.war
studio.server.api.war=war/studio-api.war
# default folder in your home directory, set to a non-empty value to override
data.base_directory=~/.hugegraph-studio

show.limit.data=250
show.limit.edge.total=1000
show.limit.edge.increment=20

# separator ','
gremlin.limit_suffix=[.V(),.E(),.hasLabel(STR),.hasLabel(NUM),.path()]

# ui graph style
vertex.vis.font.color=#343434
vertex.vis.font.size=12
vertex.vis.size=25
vertex.vis.scaling.min=25
vertex.vis.scaling.max=30
vertex.vis.shape=dot
vertex.vis.color=[\
  {"default":"#ED5736","hover":"#312520","highlight":"#ED5736"},\
  {"default":"#48C0A3","hover":"#312520","highlight":"#48C0A3"},\
  {"default":"#F47983","hover":"#312520","highlight":"#F47983"},\
  {"default":"#4C8DAE","hover":"#312520","highlight":"#4C8DAE"},\
  {"default":"#FF8C31","hover":"#312520","highlight":"#FF8C31"},\
  {"default":"#3B2E7E","hover":"#312520","highlight":"#3B2E7E"},\
  {"default":"#60281E","hover":"#312520","highlight":"#60281E"},\
  {"default":"#B36D61","hover":"#312520","highlight":"#B36D61"},\
  {"default":"#C89B40","hover":"#312520","highlight":"#C89B40"},\
  {"default":"#8D4BBB","hover":"#312520","highlight":"#8D4BBB"},\
  {"default":"#6E511E","hover":"#312520","highlight":"#6E511E"},\
  {"default":"#789262","hover":"#312520","highlight":"#789262"},\
  {"default":"#177CB0","hover":"#312520","highlight":"#177CB0"},\
  {"default":"#8C4356","hover":"#312520","highlight":"#8C4356"}\
]

edge.vis.color.default=#A0A0A0
edge.vis.color.hover=#808080
edge.vis.color.highlight=#606060
edge.vis.font.color=#77777
edge.vis.font.size=11

3、啟動服務 ${hugegraph-studio_home}/bin/hugegraph-studio.sh

$ bin/hugegraph-studio.sh
...
信息: Starting ProtocolHandler [http-nio-127.0.0.1-8088]
 11:26:53.297 [main] INFO  com.baidu.hugegraph.studio.HugeGraphStudio ID:  TS: - HugeGraphStudio is now running on: http://localhost:8088

4、訪問 http://${hugegraph-studio_IP}:8088/

HugeGraph UI

5、創(chuàng)建數(shù)據(jù)

// 創(chuàng)建屬性類型(PropertyKey)
graph.schema().propertyKey("name").asText().ifNotExist().create()
graph.schema().propertyKey("age").asInt().ifNotExist().create()
graph.schema().propertyKey("city").asText().ifNotExist().create()
graph.schema().propertyKey("lang").asText().ifNotExist().create()
graph.schema().propertyKey("date").asText().ifNotExist().create()
graph.schema().propertyKey("price").asInt().ifNotExist().create()

// 創(chuàng)建頂點類型(VertexLabel)
person = graph.schema().vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create()
software = graph.schema().vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").ifNotExist().create()

//創(chuàng)建邊類型(EdgeLabel)
knows = graph.schema().edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date").ifNotExist().create()
created = graph.schema().edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "city").ifNotExist().create()

// 創(chuàng)建頂點(Vertex)和邊(Edge)
marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing")
vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong")
marko.addEdge("knows", vadas, "date", "20160110")
簡單的圖結構

參考


mrzhqiang【在 Linux 中安裝 Cassandra】
[大巖不燦【如何設置cassandra用戶名和密碼】(https://zhaoyanblog.com/archives/307.html)]
一碗豆?jié){【Cassandra安裝配置】
simplelovecs【Cassandra安裝使用簡介】
hugegraph官方文檔
蘇黎世黃昏【準備執(zhí)行Gremlin的圖形化環(huán)境】

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容