镜缘浮影 小人本住在 苏州的城外 家里有屋又有田 生活乐无边

Neo4j 基础

2016-04-20
wilmosfang
原文地址 http://soft.dog/2016/04/20/neo4j-basic/

前言

neo4j 是一个基于 Java 的可扩展图数据库

属于 Nosql 的一种,用于记录点和点之间关系,可以形成网状结构,比如好友关系,拓扑关系等等

以下为四种最常见的 Nosql 类型:

类型 代表 特点
列存储 Hbase、Cassandra、Hypertable 按列存储数据的,最大的特点是方便存储结构化和半结构化数据,方便做数据压缩,对针对某一列或者某几列的查询有非常大的IO优势
文档存储 MongoDB、Elasticsearch、CouchDB 一般用类似json的格式存储,存储的内容是文档型的,这样也就有有机会对某些字段建立索引,实现关系数据库的某些功能
key-value存储 Berkeley DB、SSDB、MemcacheDB、Redis 通过key快速查询到其value,一般来说,存储不管value的格式,照单全收
图存储 Neo4J、FlockDB 图形关系的最佳存储,记录点和点之间关系,可以轻易形成网状结构

neo4j 分社区版和企业版,它们的区别可以参考 Compare Neo4j Editions

这里分享一下 neo4j 的相关基础,详细可以参考 官方文档Github

Tip: 当前的最新版本为 neo4j 3.0.0 RC1


概要


环境

[root@h102 neo4j]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m

[root@h102 neo4j]# uname  -a 
Linux h102.temp 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@h102 neo4j]# java -version
openjdk version "1.8.0_77"
OpenJDK Runtime Environment (build 1.8.0_77-b03)
OpenJDK 64-Bit Server VM (build 25.77-b03, mixed mode)
[root@h102 neo4j]# 

下载安装

neo4j 是开源软件,可以通过 下载地址 ,也可以直接在 Github 里下载

neo4j 的系统要求可以参考 环境依赖

Neo4j requires a Java Virtual Machine to operate. Community Edition installers for Windows and Mac include a JVM for convenience. Other distributions, including all distributions of Neo4j Enterprise Edition, require that the JVM be provided.

Java

OpenJDK 8 (preferred) or 7 or Oracle Java 8 (preferred) or 7

IBM Java 8 (preferred) or 7 (POWER8 only)

Operating Systems

Linux, HP-UX, Windows Server 2012 for production

Additionally, Windows XP and Mac OS X for development

Architectures

x86

OpenPOWER (POWER8, requires IBM Java or OpenJDK, version 7 or 8)

[root@h102 neo4j]# ls
neo4j-enterprise-3.0.0-RC1-unix.tar.gz
[root@h102 neo4j]# tar -zxvf neo4j-enterprise-3.0.0-RC1-unix.tar.gz 
neo4j-enterprise-3.0.0-RC1/
neo4j-enterprise-3.0.0-RC1/plugins/
neo4j-enterprise-3.0.0-RC1/run/
neo4j-enterprise-3.0.0-RC1/logs/
neo4j-enterprise-3.0.0-RC1/import/
neo4j-enterprise-3.0.0-RC1/data/
neo4j-enterprise-3.0.0-RC1/data/databases/
neo4j-enterprise-3.0.0-RC1/conf/
neo4j-enterprise-3.0.0-RC1/bin/
neo4j-enterprise-3.0.0-RC1/README.txt
neo4j-enterprise-3.0.0-RC1/NOTICE.txt
neo4j-enterprise-3.0.0-RC1/LICENSES.txt
neo4j-enterprise-3.0.0-RC1/LICENSE.txt
neo4j-enterprise-3.0.0-RC1/conf/neo4j.conf
neo4j-enterprise-3.0.0-RC1/conf/neo4j-wrapper.conf
neo4j-enterprise-3.0.0-RC1/conf/jmx.access
neo4j-enterprise-3.0.0-RC1/conf/jmx.password
neo4j-enterprise-3.0.0-RC1/bin/neo4j-shell
neo4j-enterprise-3.0.0-RC1/bin/neo4j-import
neo4j-enterprise-3.0.0-RC1/bin/neo4j-backup
neo4j-enterprise-3.0.0-RC1/bin/neo4j-shared.sh
neo4j-enterprise-3.0.0-RC1/bin/neo4j
neo4j-enterprise-3.0.0-RC1/bin/neo4j-admin
neo4j-enterprise-3.0.0-RC1/UPGRADE.txt
neo4j-enterprise-3.0.0-RC1/lib/neo4j-kernel-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-graphdb-api-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-common-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-resource-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-collections-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-primitive-collections-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-unsafe-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-io-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/commons-lang3-3.3.2.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-csv-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-logging-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-security-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-lucene-upgrade-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/lucene-core-5.5.0.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-lucene-index-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/lucene-analyzers-common-5.5.0.jar
neo4j-enterprise-3.0.0-RC1/lib/lucene-queryparser-5.5.0.jar
neo4j-enterprise-3.0.0-RC1/lib/lucene-codecs-5.5.0.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-graph-algo-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-udc-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-graph-matching-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-cypher-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/scala-library-2.11.8.jar
neo4j-enterprise-3.0.0-RC1/lib/scala-reflect-2.11.8.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-codegen-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-cypher-compiler-2.3-2.3.3.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-cypher-frontend-2.3-2.3.3.jar
neo4j-enterprise-3.0.0-RC1/lib/parboiled-scala_2.11-1.1.7.jar
neo4j-enterprise-3.0.0-RC1/lib/parboiled-core-1.1.7.jar
neo4j-enterprise-3.0.0-RC1/lib/concurrentlinkedhashmap-lru-1.4.2.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-cypher-compiler-3.0-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-cypher-frontend-3.0-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/opencsv-2.3.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-jmx-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-consistency-check-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-query-logging-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-com-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-enterprise-kernel-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/netty-3.6.3.Final.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-backup-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-cluster-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-ha-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-metrics-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/metrics-core-3.1.2.jar
neo4j-enterprise-3.0.0-RC1/lib/slf4j-api-1.7.7.jar
neo4j-enterprise-3.0.0-RC1/lib/metrics-graphite-3.1.2.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-management-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-dbms-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/server-api-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-bolt-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-shell-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/jline-2.12.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-import-tool-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/asm-5.0.2.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-server-enterprise-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-server-3.0.0-RC1.jar
neo4j-enterprise-3.0.0-RC1/lib/jsr311-api-1.1.2.r612.jar
neo4j-enterprise-3.0.0-RC1/lib/commons-configuration-1.10.jar
neo4j-enterprise-3.0.0-RC1/lib/commons-lang-2.6.jar
neo4j-enterprise-3.0.0-RC1/lib/commons-logging-1.1.1.jar
neo4j-enterprise-3.0.0-RC1/lib/commons-digester-2.1.jar
neo4j-enterprise-3.0.0-RC1/lib/commons-beanutils-1.8.3.jar
neo4j-enterprise-3.0.0-RC1/lib/netty-all-4.0.28.Final.jar
neo4j-enterprise-3.0.0-RC1/lib/bcpkix-jdk15on-1.53.jar
neo4j-enterprise-3.0.0-RC1/lib/bcprov-jdk15on-1.53.jar
neo4j-enterprise-3.0.0-RC1/lib/neo4j-browser-1.1.0-RC2.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-server-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/javax.servlet-api-3.1.0.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-http-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-util-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-io-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-webapp-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-xml-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-servlet-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/jetty-security-9.2.9.v20150224.jar
neo4j-enterprise-3.0.0-RC1/lib/jersey-server-1.19.jar
neo4j-enterprise-3.0.0-RC1/lib/jersey-core-1.19.jar
neo4j-enterprise-3.0.0-RC1/lib/jersey-servlet-1.19.jar
neo4j-enterprise-3.0.0-RC1/lib/commons-io-2.4.jar
neo4j-enterprise-3.0.0-RC1/lib/jackson-jaxrs-1.9.13.jar
neo4j-enterprise-3.0.0-RC1/lib/jackson-core-asl-1.9.13.jar
neo4j-enterprise-3.0.0-RC1/lib/jackson-mapper-asl-1.9.13.jar
neo4j-enterprise-3.0.0-RC1/lib/rhino-1.7R4.jar
neo4j-enterprise-3.0.0-RC1/lib/jersey-multipart-1.19.jar
neo4j-enterprise-3.0.0-RC1/lib/mimepull-1.9.3.jar
[root@h102 neo4j]# ls
neo4j-enterprise-3.0.0-RC1  neo4j-enterprise-3.0.0-RC1-unix.tar.gz
[root@h102 neo4j]# cd neo4j-enterprise-3.0.0-RC1
[root@h102 neo4j-enterprise-3.0.0-RC1]# ls
bin  conf  data  import  lib  LICENSES.txt  LICENSE.txt  logs  NOTICE.txt  plugins  README.txt  run  UPGRADE.txt
[root@h102 neo4j-enterprise-3.0.0-RC1]# 

运行

[root@h102 neo4j-enterprise-3.0.0-RC1]# ./bin/neo4j console
Starting Neo4j.
WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.
2016-04-20 14:25:09.166+0000 INFO  No SSL certificate found, generating a self-signed certificate..
2016-04-20 14:25:10.181+0000 INFO  Starting...
2016-04-20 14:25:11.348+0000 INFO  Initiating metrics...
2016-04-20 14:25:16.546+0000 INFO  Started.
2016-04-20 14:25:22.701+0000 INFO  Mounted REST API at: /db/manage
2016-04-20 14:26:09.977+0000 INFO  Remote interface available at http://localhost:7474/
...
...
...

访问

服务运行后,本地会开启 7474 端口,并且只监听在 127.0.0.1,于是只能在本地进行访问

[root@h102 neo4j-enterprise-3.0.0-RC1]# netstat  -ant | grep 7474
tcp        0      0 ::ffff:127.0.0.1:7474       :::*                        LISTEN      
[root@h102 neo4j-enterprise-3.0.0-RC1]# 

使用本地的浏览器进行访问

neo4j_1.png

提示要在命令行输入 :server connect 建立连接

输入后切换成如下画面,默认密码为 neo4j/neo4j

neo4j_2.png

然后提示输入新密码,再然后就可以访问了

neo4j_3.png


命令汇总

  • java -version
  • tar -zxvf neo4j-enterprise-3.0.0-RC1-unix.tar.gz
  • cd neo4j-enterprise-3.0.0-RC1
  • ./bin/neo4j console
  • netstat -ant | grep 7474

原文地址 http://soft.dog/2016/04/20/neo4j-basic/

评论