環(huán)境要求
1稀火、虛擬機(jī)(CentOS7.3)
2坏晦、關(guān)閉防火墻和SELinux
3雌澄、配置好JDK
Cassandra的安裝啟動
1倚喂、下載Cassandra安裝包(使用3.0以上的每篷,為兼容hugegraph)
- Downloading Cassandra 下載最新穩(wěn)定發(fā)行版
- 解壓:tar -zxvf apache-cassandra-3.11.3-bin.tar.gz -C /usr/local/
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ù)文件存放路徑焦读。打開這個注釋,注意不要合并成一行舱权,合并成一行好像會出問題矗晃,這里要與前面新建的文件夾對應(yīng)。
commitlog_directory: /var/lib/cassandra/commitlog // 操作日志文件存放路徑宴倍。打開注釋张症,與前面新建的文件夾對應(yīng)。
saved_caches_directory: /var/lib/cassandra/saved_caches // 緩存文件存放路徑鸵贬。打開注釋俗他,與前面新建的文件夾對應(yīng)。
- 開啟默認(rèn)密碼
authenticator: PasswordAuthenticator // 默認(rèn)AllowAllAuthenticator
authorizer: CassandraAuthorizer // 默認(rèn)AllowAllAuthorizer
啟動后使用:./cqlsh -u cassandra -p cassandra ip port
- CREATE USER myusername WITH PASSWORD 'mypassword' SUPERUSER;(這里用戶有兩種阔逼,一個是superuser兆衅,一種是nosuperuser)
- 供外部工具連接CassandraManager訪問
rpc_address: 0.0.0.0 // 用于監(jiān)聽客戶端連接的地址,默認(rèn)127.0.0.1
broadcast_rpc_address: 1.2.3.4 // 若rpc_address設(shè)置0.0.0.0嗜浮,則要放開此注釋
- 集群模式
cluster_name: 'xxx' // 集群名稱羡亩。同一個集群要使用同一名稱
- seeds: "192.168.x.x" // 集群種子節(jié)點(diǎn)ip,新加入集群的節(jié)點(diǎn)從種子節(jié)點(diǎn)中同步數(shù)據(jù)∥H冢可配置多個畏铆,中間用逗號隔開。
listen_address: 127.0.0.1 // 需要監(jiān)聽的IP或主機(jī)名吉殃。改成本機(jī)IP
4辞居、啟動服務(wù)(啟動后默認(rèn)端口為9042)
cd ${CASSANDRA_HOME}/bin
./cassandra -R # root用戶啟動
部署 HugeGraph
1片排、先安裝 hugegraph-0.7.4
- 下載 hugegraph-0.7.4.tar.gz
- 解壓:tar -zxvf hugegraph-0.7.4.tar.gz -C /home/hugegraph
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,相當(dāng)于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安裝主機(jī)的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'
啟動服務(wù)${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
- 下載 hugegraph-studio-0.6.1.tar.gz
- 解壓:tar -zxvf hugegraph-studio-0.6.1.tar.gz -C /home/hugegraph
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服務(wù)的地址
graph.server.port=8080 // hugegraph服務(wù)的端口
graph.name=hugegraph // 服務(wù)的名字,不更改每界,否則頁面Gremlin執(zhí)行命令時報(bào)錯
# 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捅僵、啟動服務(wù) ${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/
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)建頂點(diǎn)類型(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)建頂點(diǎn)(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】
[大巖不燦【如何設(shè)置cassandra用戶名和密碼】(https://zhaoyanblog.com/archives/307.html)]
一碗豆?jié){【Cassandra安裝配置】
simplelovecs【Cassandra安裝使用簡介】
hugegraph官方文檔
蘇黎世黃昏【準(zhǔn)備執(zhí)行Gremlin的圖形化環(huán)境】