Ubuntu/Windows安装图数据库Neo4j 3.4存储三元组语义网知识图谱

Neo4j数据库开发文档

 

Neo4j分社区版(Community Edition)和企业版(Enterprise Edition),社区版本为免费版本。目前的最新版本为Neo4j 3.1。官方网址为https://neo4j.com/ Neo4j的相关文档URL地址如下

https://neo4j.com/docs/developer-manual/3.1/

https://neo4j.com/docs/operations-manual/3.1/

https://neo4j.com/docs/developer-manual/3.1/cypher/

 

官方文档中文版             目前编撰到第N章。


memory调优之Page Cache Sizing和 Heap Space调优.https://neo4j.com/developer/guide-performance-tuning/

详细的heap调优说明.http://neo4j.com/docs/operations-manual/current/performance/memory-configuration/#heap-sizing

Chapter 9. Performance tune.https://neo4j.com/docs/operations-manual/current/performance


System requirements

Disk

除了Disk的容量,Disk的性能对Neoj4的影响非常大,Neo4j的工作负载倾向于随机读。选择平均寻址时间低的存储,例如SSD

最低要求 10GB SATA

推荐配置 SSD w/SATA

 

FileSystem

最低要求 ext4(或类似的)

推荐配置 ext4、ZFS

 

Software

Java

必须安装OpenJDK 8 或 Oracle Java 8

 

Operation Sytem

Linux(Ubuntu, Debian) ,但是我的测试环境为Red Hat Enterprise Linux Server release 6.6,暂时还没有发现什么问题。

Architectures

X86 或 OpenPower(POWER8)

Windows下安装


1.安装Java JDK

Neo4j是基于Java的图形数据库,运行Neo4j需要启动JVM进程,因此需要安装JDK,此过程不再赘述,仅做提醒。

2.下载Neo4j安装包

楼主提供两种方式:1.官网 2.CSDN已上传资源

3.解压Neo4j安装包

根据需要解压到指定的文件夹,主要目录如下:

  • bin目录:用于存储Neo4j的可执行程序;
  • conf目录:用于控制Neo4j启动的配置文件;
  • data目录:用于存储核心数据库文件;
  • plugins目录:用于存储Neo4j的插件;

其中conf目录和data目录不在解压的目录下面,data数据库文件在启动时用户指定目录

4.设置环境变量

变量名:NEO4J_HOME

变量值:安装路径

变量名:path

变量值:%NEO4J_HOME%\bin

5.配置Neo4j

配置文档存储在conf目录下,Neo4j通过配置文件neo4j.conf控制服务器的工作。默认情况下,不需要进行任意配置,就可以启动服务器。

lpp8S.png

lp44H.png

  • 安全验证,默认是启用的
# Whether requests to Neo4j are authenticated.
# To disable authentication, uncomment this line
#dbms.security.auth_enabled=false
  • 1
  • 2
  • 3

默认的账户名和密码均为 neo4j,如果觉得麻烦,可以将验证改为false。

6.启动neo4j

在开始菜单点击neo4j的图标,弹出如下界面,首先选择数据库存放位置,然后点击启动即可。

lpU6Y.png




 

Neo4j安装步骤:

 

下面简单介绍Linux下Neo4j 3.1的安装步骤,安装测试环境为Red Hat Enterprise Linux Server release 6.6, Debian下安装具体参考文档,这里不做介绍。

1:下载Neo4j 3.1的安装包,去官方网址注册下载即可。选择特定的版本。下载地址 https://neo4j.com/download/

2:检查上面System Requirement,安装JDK 8

[root@gettestlnx03 ~]# rpm -qa | grep gcj
libgcj-devel-4.4.7-11.el6.x86_64
libgcj-4.4.7-11.el6.x86_64
java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
[root@gettestlnx03 ~]# rpm -ivh /tmp/jdk-8u121-linux-x64.rpm 
Preparing...                ########################################### [100%]
   1:jdk1.8.0_121           ########################################### [100%]
Unpacking JAR files...
        tools.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...
 
[root@gettestlnx03 ~]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
[root@gettestlnx03 ~]# 

编辑/etc/profile文件,添加下面配置信息,然后执行source /etc/profile命令使之生效。

export JAVA_HOME=/usr/java/jdk1.8.0_121/
 
export CLASSPATH=/usr/java/jdk1.8.0_121/lib
 
export PATH=$AVA_HOME/bin:$PATH

 

3:创建一个用户neo4j,用来管理Neo4j 。当然这不是必须的。也可以是其它账号或root账号。

[root@gettestlnx03 ~]# /usr/sbin/groupadd nosql
 
[root@gettestlnx03 ~]# /usr/sbin/useradd -G nosql neo4j

 

4:然后切换到neo4j账户下,解压neo4j-community-3.1.1-unix.tar.gz包

[root@gettestlnx03 ~]# su - neo4j
 
[neo4j@gettestlnx03 ~]$ tar -zxvf /tmp/neo4j-community-3.1.1-unix.tar.gz -C /home/neo4j/

 

配置.bash_profile文件,增加下面一行,并使之生效。

[root@gettestlnx03 neo4j]# su - neo4j
 
[neo4j@gettestlnx03 ~]$ vi .bash_profile 
 
export PATH=/home/neo4j/neo4j-community-3.1.1/bin:$PATH #新增一行
 
[neo4j@gettestlnx03 ~]$ source .bash_profile 

另外,修改配置文件/etc/security/limits.conf ,增加下面配置。

 
neo4j  soft   nofile  40000
neo4j  hard   nofile  40000

The usual default of 1024 is often not enough. This is especially true when many indexes are used or a

server installation sees too many connections. Network sockets count against the limit as well. Users

are therefore encouraged to increase the limit to a healthy value of 40 000 or more, depending on

usage patterns. It is possible to set the limit with the ulimit command, but only for the root user, and

it only affects the current session. To set the value system wide, follow the instructions for your

platform.

编辑/etc/pam.d/su 在配置文件里面增加选项。

session optional pam_xauth.so

 

Neo4j服务关闭启动

使用service neo4j { console | start | stop | restart | status | version } 而非neo4j { console | start | stop | restart | status | version }


使用neo4j { console | start | stop | restart | status | version }的问题

# neo4j

Usage: neo4j { console | start | stop | restart | status | version }
# neo4j status
Neo4j is not running 


Neo4j服务的启动、关闭如下所示


~$ neo4j start
Active database: graph.db
Directories in use:
  home:         /var/lib/neo4j
  config:       /etc/neo4j
  logs:         /var/log/neo4j
  plugins:      /var/lib/neo4j/plugins
  import:       /var/lib/neo4j/import
  data:         /var/lib/neo4j/data
  certificates: /var/lib/neo4j/certificates
  run:          /var/run/neo4j
Starting Neo4j.
WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.
/usr/share/neo4j/bin/neo4j: line 418: /var/run/neo4j/neo4j.pid: No such file or directory
/usr/share/neo4j/bin/neo4j: line 417: /var/log/neo4j/neo4j.log: Permission denied

以上日志表示没有成功启动。 

问题1:

/var/run/neo4j/neo4j.pid: No such file or directory

解决方法: 

https://stackoverflow.com/questions/44988218/neo4j-start-error-var-run-neo4j-neo4j-pid-no-such-file-or-directory

问题1:

WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.


解决1:

https://neo4j.com/docs/1.6.2/configuration-linux-notes.htm


解决2:

root@yumh:/etc/neo4j# ulimit  -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 386518
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 386518
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


临时修改

ulimit  -n 65536


永久生效

vim /ete/security/limits.conf 写入

* - nofile 633565

* - nproc 65536




# neo4j stop
Neo4j not running


开放远程访问Neo4J的web控制台等端口

Configure Neo4j connectors.https://neo4j.com/docs/operations-manual/current/configuration/connectors/


如果不设置Neo4j的配置文件,只能从本机访问Neo4J的web控制台(http://localhost:7474/) Neo4j的控制文件一般位于config:       /etc/neo4j下的neo4j.conf

Neo4j的配置文件将单独再做详细介绍。如果我们需要远程访问Neo4j的Web控制台,我们需要修改neo4j.conf配置文件的参数,如下截图所示:

clip_image002

当然,还需要配置iptables,开放7474端口号,否则你还是无法远程访问Web控制台。

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 7474 -j ACCEPT




neo4j为了安全考虑,默认情况下只能被localhost访问,需要修改neo4j-server.properties中的配置

如下图所示:

找到对应的项目org.neo4j.server.webserver.address=0.0.0.0,然后移除前面的注释即可


1、配置Neo4j外部网络可以访问
进入neo4j程序目录/conf 修改neo4j-server.properties文件
#org.neo4j.server.webserver.address=0.0.0.0
注释去掉即可


2、配置Neo4j开机启动
我的debian系统 Linux version 3.13 Debian 4.7
进入 /etc/init.d目录 打开rc.local文件
加入 neo4j目录/bin/neo4j  start即可


然后你就可以从远程http://xxx.xxx.xxx.xxx:7474 访问Neo4j的Web控制台了, 第一次登陆会提示你输入初始化密码并提醒你修改密码。默认的密码为neo4j,必须修改密码,否则之后会无法使用。

clip_image003

clip_image004

 

简单的测试案例

我们先创建一个简单的父子关系图。用来简单演示一下图形数据库的使用。如下所示。

[neo4j@gettestlnx03 bin]$ ./cypher-shell 
username: neo4j
password: **********
Connected to Neo4j 3.1.1 at bolt://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.
neo4j> CREATE (A {id:1,name:'张飞'}), (B {id:2,name:'张小二'}), (C {id:3,name:'张三'}), (D {id:4,name:'张凯'}),(E {id:5,name:'张雨'}),(A)-[:Son]->(B),(A)-[:Son]->(C),(B)-[:Son]->(D),(C)-[:Son]->(E); 
Added 5 nodes, Created 4 relationships, Set 10 properties
neo4j> START n=node(*) RETURN n;
n
({name: "张飞", id: 1})
({name: "张小二", id: 2})
({name: "张三", id: 3})
({name: "张凯", id: 4})
({name: "张雨", id: 5})
neo4j> 
image

 

如果你在Web控制台执行命令,就能得到如下一个图形关系。如下所示。

clip_image006


配置heap size

The heap memory size is determined by the parameters in $NEO4J_HOME/conf/neo4j.conf, namely dbms.memory.heap.initial_size and dbms.memory.heap.max_size providing the heap size as a number and a unit, for example 16G 512m. It is recommended to set these two parameters to the same size.

For a more thorough discussion on this topic, refer to the heap memory configuration section in the Neo4j Operations Manual. That section also contains information about heap memory distribution and gabarge collection tuning.

报错1:

看上图,

 neo4j console的使用

# cd C:\Users\t-lichen\Downloads\neo4j-community-3.4.1-windows\neo4j-community-3.4.1

# bin\neo4j console

WARNING: This command does not appear to be running with administrative rights.  Some commands may fail e.g. Start/Stop
2018-06-22 10:57:30.718+0000 INFO  ======== Neo4j 3.4.1 ========
2018-06-22 10:57:30.798+0000 INFO  Starting...
2018-06-22 10:57:44.457+0000 INFO  Bolt enabled on 127.0.0.1:7687.
2018-06-22 10:57:51.711+0000 INFO  Started.
2018-06-22 10:57:53.633+0000 INFO  Remote interface available at http://localhost:7474/
2018-06-22 10:59:13.571+0000 ERROR Unexpected error detected in bolt session '000d3afffef740dc-00001590-00000001-0d9b31c28436a5ec-5d4b6c13'. The client is unauthorized due to authentication failure.
org.neo4j.bolt.v1.runtime.BoltConnectionFatality: The client is unauthorized due to authentication failure.
        at org.neo4j.bolt.v1.runtime.BoltStateMachine.handleFailure(BoltStateMachine.java:742)
        at org.neo4j.bolt.v1.runtime.BoltStateMachine.handleFailure(BoltStateMachine.java:728)
        at org.neo4j.bolt.v1.runtime.BoltStateMachine.access$500(BoltStateMachine.java:62)
        at org.neo4j.bolt.v1.runtime.BoltStateMachine$State$1.init(BoltStateMachine.java:435)
        at org.neo4j.bolt.v1.runtime.BoltStateMachine.init(BoltStateMachine.java:145)
        at org.neo4j.bolt.v1.messaging.BoltMessageRouter.lambda$onInit$0(BoltMessageRouter.java:70)
        at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatch(DefaultBoltConnection.java:195)
        at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatch(DefaultBoltConnection.java:143)
        at org.neo4j.bolt.runtime.ExecutorBoltScheduler.executeBatch(ExecutorBoltScheduler.java:170)
        at org.neo4j.bolt.runtime.ExecutorBoltScheduler.lambda$scheduleBatchOrHandleError$2(ExecutorBoltScheduler.java:153)
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)


原因没有登录  7474端口修改默认密码。

修改密码后:



neo4j 导入数据

将大规模数据导入Neo4j的五种方法.

https://blog.csdn.net/xingxiupaioxue/article/details/71747284

如何使用batch-import工具向neo4j中导入海量数据.http://database.51cto.com/art/201704/538007.html

LOAD CSV and batch-import.http://pettyandydog.com/2016/09/27/neo4j-import/



  1. 官方提供的 neo4j-import 工具导入大规模数据
导入数据

模板:

neo4j-import --into ../data/databases/graph.db --id-type string --nodes:movie ../import/movie.csv --nodes:country ../import/country.csv  --relationships:MADE_IN ../import/MADE_IN.csv --multiline-fields=true --skip-bad-relationships=true --bad-tolerance=20


准备尝试的代码:


neo4j-import --into ../data/databases/msTriple.db --nodes:Type "type-header.c,type.csv" --nodes:Entity "entity-header.csv,entity.csv" --relationships:is_a "relation-header.csv,relation.csv"

neo4j-import --into ../data/databases/msTriple.db --nodes:Type "type.csv" --nodes:Entity "entity.csv" --relationships:is_a "relation.csv"  #这样写文件需要在bin目录下

../bin/neo4j-import.bat --into ../data/databases/msTriple.db --nodes:Type ../import/type.csv --nodes:Entity  ../import/entity.csv --relationships:is_a  ../import/relation.csv 


../bin/neo4j-import.bat --into ../data/databases/msTriple.db --nodes:Type ../import/type.csv --nodes:Entity ../import/entity.csv  #只导入顶点

windows下 cmd的正确写法: bin\neo4j-import.bat --into data\databases\msTriple.db --nodes:Type import\type.csv --nodes:Entity import\entity.csv


windows cmd 不识别./ 和 ..





C:\Users\t-lichen\Downloads\neo4j-community-3.4.1-windows\neo4j-community-3.4.1>bin\neo4j install-service
WARNING: This command does not appear to be running with administrative rights.  Some commands may fail e.g. Start/Stop
Invoke-Neo4j : This command cannot be run due to the error: The requested operation requires elevation.
At line:1 char:305
+ ... 3.4.1\bin\Neo4j-Management.psd1'; Exit (Invoke-Neo4j install-service)
+                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-Neo4j


C:\Users\t-lichen\Downloads\neo4j-community-3.4.1-windows\neo4j-community-3.4.1>bin\neo4j start
WARNING: This command does not appear to be running with administrative rights.  Some commands may fail e.g. Start/Stop
Invoke-Neo4j : Cannot find any service with service name 'neo4j'.
At line:1 char:305
+ ... community-3.4.1\bin\Neo4j-Management.psd1'; Exit (Invoke-Neo4j start)
+                                                       ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-Neo4j

参考资料:

https://neo4j.com/docs/developer-manual/3.1/

猜你喜欢

转载自blog.csdn.net/wzwdcld/article/details/80763251