2019独角兽企业重金招聘Python工程师标准>>>
Neo4J介绍
图数据库的需求
能以明显直观的方式存放图数据,而不是扭曲变化为别的替代方式
能简单地进行图操作,例如寻路,遍历等
图数据库的基本思想
图(Graph)由节点(node,顶点)和关系(relationship,边)组成
图在节点上记录数据(节点的属性,property)
节点由关系组织成图,关系也具有属性
寻路(Traversal,另一意思是遍历)在图上定位由节点组成的路径
索引(index)将属性映射到节点或关系
图数据库管理系统 管理 图 及其上的 索引
Neo4J是当前主流的图数据库产品
Neo4J
由Neo Technology开发的开源图数据库,该公司从2000年起就开始研发图数据库,目前neo4j已经成为领先的图数据库产品,思科,惠普,德意志电信等跨国企业均成为客户
特点:
直观的图模型存储
完全支持ACID事务
基于磁盘的持久存储
支持海量数据,比如数十亿节点/关系/属性级别的数据
高可用的分布式集群
高度优化,迅速的图查询(Cypher图查询语言)
可以嵌入(只需几个小jar文件),支持REST API
Neo4J的安装
官网: http://www.neo4j.org/
Neo4j的部署模式
独立模式:独立的服务器,可以通过REST API、或基于语言的驱动等访问
嵌入模式:提供若干库,嵌入到Java程序运行
##安装linux版本
http://dist.neo4j.org/neo4j-community-1.9.4-unix.tar.gz
下载后解包 (这里下载的是社区版)
切换root,运行./bin/neo4j install
##安装neo4j需要首先安装JDK
# tar zxf neo4j-community-1.9.4-unix.tar.gz
# mv neo4j-community-1.9.4 neo4j
# cd neo4j/bin
[root @linux bin]# ./neo4j install
Graph-like power should be handled carefully. What user should run Neo4j? [oracle] root
##修改配置文件
./conf/neo4j-server.properties
org.neo4j.server.webserver.address=0.0.0.0
##启动
[root @linux bin]# ./neo4j status
Neo4j Server is not running
[root @linux bin]# ./neo4j start
WARNING: Max 1024 open files allowed, minimum of 40 000 recommended. See the Neo4j manual.
Using additional JVM arguments: -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
Starting Neo4j Server...process [1128]... waiting for server to be ready....... OK.
Go to http://localhost:7474/webadmin/ for administration interface.
[root @linux bin]# ./neo4j status
Neo4j Server is running at pid 1128
##远程web UI
http://10.10.10.8:7474/webadmin/#
##Web UI: Console
http://10.10.10.8:7474/webadmin/#/console/
##用简单的语句测试
- neo4j-sh (0)$ CREATE (ee { name: "Emil", from: "Sweden" }) RETURN ee.name;
- ==> +---------+
- ==> | ee.name |
- ==> +---------+
- ==> | "Emil" |
- ==> +---------+
- ==> 1 row
- ==> Nodes created: 1
- ==> Properties set: 2
- ==>
- ==> 1100 ms
- neo4j-sh (0)$ START ee=node(*) WHERE ee.name! = "Emil" RETURN ee;
- ==> +------------------------------------+
- ==> | ee |
- ==> +------------------------------------+
- ==> | Node[1]{name:"Emil",from:"Sweden"} |
- ==> +------------------------------------+
- ==> 1 row
- ==>
- ==> 502 ms
- neo4j-sh (0)$
##Shell命令参考
http://docs.neo4j.org/chunked/1.9.4/shell-commands.html
Neo4J集群
模拟测试Neo4j高可用
下载Neo4j企业版
解压为多个不同目录
分别修改配置文件,使监听不同的端口
启动多个Neo4j服务器进程
Neo4j手册第26.6节
类似Mysql的高可用集群,可以实现读写分离,写数据被引导到Master节点,再从多个slave读数据
##下载企业版并解压缩到三个目录
http://dist.neo4j.org/neo4j-enterprise-1.9.4-unix.tar.gz
# tar zxf neo4j-enterprise-1.9.4-unix.tar
# mv neo4j-enterprise-1.9.4 neo4j01
[root @linux neo4j]# cp -R neo4j01 neo4j02
[root@linux neo4j]# cp -R neo4j01 neo4j03
##1号节点的配置文件 neo4j.properties
online_backup_server=127.0.0.1:6362
ha.server_id=1
ha.initial_hosts=127.0.0.1:5001,127.0.0.1:5002,127.0.0.1:5003
ha.server=127.0.0.1:6001
ha.cluster_server=127.0.0.1:5001
##1号节点的配置文件 Neo4j-server.properties
org.neo4j.server.webserver.address=0.0.0.0
org.neo4j.server.manage.console_engines=gremlin, shell
org.neo4j.server.database.mode=HA
org.neo4j.server.webserver.port=7474
org.neo4j.server.webserver.https.port=7473
##2号节点的配置文件 neo4j.properties
online_backup_server=127.0.0.1:6363
ha.server_id=2
ha.initial_hosts=127.0.0.1:5001,127.0.0.1:5002,127.0.0.1:5003
ha.server=127.0.0.1:6002
ha.cluster_server=127.0.0.1:5002
##2号节点的配置文件 Neo4j-server.properties
org.neo4j.server.webserver.address=0.0.0.0
org.neo4j.server.manage.console_engines=gremlin, shell
org.neo4j.server.database.mode=HA
org.neo4j.server.webserver.port=7484
org.neo4j.server.webserver.https.port=7483
##3号节点的配置文件 neo4j.properties
online_backup_server=127.0.0.1:6364
ha.server_id=3
ha.initial_hosts=127.0.0.1:5001,127.0.0.1:5002,127.0.0.1:5003
ha.server=127.0.0.1:6003
ha.cluster_server=127.0.0.1:5003
##3号节点的配置文件 Neo4j-server.properties
org.neo4j.server.webserver.address=0.0.0.0
org.neo4j.server.manage.console_engines=gremlin, shell
org.neo4j.server.database.mode=HA
org.neo4j.server.webserver.port=7494
org.neo4j.server.webserver.https.port=7493
##启动三个neo4j实例
[root@linux bin]# ./neo4j start
WARNING: Max 1024 open files allowed, minimum of 40 000 recommended. See the Neo4j manual.
Using additional JVM arguments: -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
Starting Neo4j Server...HA instance started in process [2244]. Will be operational once connected to peers. See /nosql/neo4j/neo4j01/data/log/console.log for current status.
[root@linux bin]#
[root@linux bin]# cd /nosql/neo4j/neo4j02/bin/
[root@linux bin]# ./neo4j start
WARNING: Max 1024 open files allowed, minimum of 40 000 recommended. See the Neo4j manual.
Using additional JVM arguments: -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
Starting Neo4j Server...HA instance started in process [2417]. Will be operational once connected to peers. See /nosql/neo4j/neo4j02/data/log/console.log for current status.
[root@linux bin]#
[root@linux bin]# cd /nosql/neo4j/neo4j03/bin/
[root@linux bin]# ./neo4j start
WARNING: Max 1024 open files allowed, minimum of 40 000 recommended. See the Neo4j manual.
Using additional JVM arguments: -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
Starting Neo4j Server...HA instance started in process [2690]. Will be operational once connected to peers. See /nosql/neo4j/neo4j03/data/log/console.log for current status.
[root@linux bin]#
[root@linux bin]# jps
2417 Bootstrapper
2796 Jps
2244 Bootstrapper
2690 Bootstrapper
[root@linux bin]#
##Web UI上观看高可用集群状态
http://10.10.10.8:7474/webadmin/#/info/org.neo4j/High%20Availability/
http://blog.csdn.net/zq9017197/article/details/17717815