Cassandra与HugeGraph的安装配置

环境要求

1、虚拟机(CentOS7.3)
2、关闭防火墙和SELinux
3、配置好JDK

Cassandra的安装启动

1、下载Cassandra安装包(使用3.0以上的,为兼容hugegraph)

  • Downloading Cassandra 下载最新稳定发行版
  • 解压:tar -zxvf apache-cassandra-3.11.3-bin.tar.gz -C /usr/local/

2、新建数据存储路径

  • 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  // 数据文件存放路径。打开这个注释,注意不要合并成一行,合并成一行好像会出问题,这里要与前面新建的文件夹对应。
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)
  • 供外部工具连接CassandraManager访问
rpc_address: 0.0.0.0 // 用于监听客户端连接的地址,默认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"  // 集群种子节点ip,新加入集群的节点从种子节点中同步数据。可配置多个,中间用逗号隔开。
listen_address: 127.0.0.1  // 需要监听的IP或主机名。改成本机IP

4、启动服务(启动后默认端口为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数据库为例)
# 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

初始化数据库${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

  • 下载 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服务的地址
graph.server.port=8080       // hugegraph服务的端口
graph.name=hugegraph       // 服务的名字,不更改,否则页面Gremlin执行命令时报错

# 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、创建数据

// 创建属性类型(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()

// 创建顶点类型(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()

//创建边类型(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()

// 创建顶点(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)]
一碗豆浆【Cassandra安装配置】
simplelovecs【Cassandra安装使用简介】
hugegraph官方文档
苏黎世黄昏【准备执行Gremlin的图形化环境】

你可能感兴趣的:(Cassandra与HugeGraph的安装配置)