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章。
/usr/bin/cypher-shell
service neo4j stop 和 neo4j stop 都执行后,远程websever还是能打开。
使用(service) neo4j start 或 service neo4j status可以查到meo4j目录组织相关信息。
# 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.
解决:
vim /ete/security/limits.conf 写入
* - nofile 633565
* - nproc 65536
# neo4j stop
Neo4j not running
t-lichen@stcal-129:~$ sudo find / -name "neo4j-import"
/usr/bin/neo4j-import
/usr/share/neo4j/bin/neo4j-import
find: ‘/run/user/118/gvfs’: Permission denied
官方文档. Configure Neo4j connectors.https://neo4j.com/docs/operations-manual/current/configuration/connectors/
如果不设置Neo4j的配置文件,只能从本机访问Neo4J的web控制台(http://localhost:7474/)和Server.
Neo4j的控制文件一般位于config: /etc/neo4j下的neo4j.conf
将conf中connector配置部分的注释去掉和修改为如下图:
当然,还需要配置系统防火墙,如linux下的iptables,开放7474端口号,否则你还是无法远程访问Web控制台。
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 7474 -j ACCEPT
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,必须修改密码,否则之后会无法使用。
简单的测试案例
我们先创建一个简单的父子关系图。用来简单演示一下图形数据库的使用。如下所示。
[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>
如果你在Web控制台执行命令,就能得到如下一个图形关系。如下所示。
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:
看上图,
# 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端口修改默认密码。
修改密码后:
https://neo4j.com/docs/developer-manual/3.1/