Neo4j警告:最多允许打开1024个文件,建议至少打开40000个。请参阅Neo4j手册。

57

我按照这些说明在Ubuntu 12.04上安装了Neo4j:http://www.neo4j.org/download/linux

wget -O - http://debian.neo4j.org/neotechnology.gpg.key | apt-key add - 
echo 'deb http://debian.neo4j.org/repo stable/' > /etc/apt/sources.list.d/neo4j.list
apt-get update
apt-get install neo4j

我确保安装了正确的JDK:

root@precise64:~# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

启动 neo4j 时出现以下错误:

警告:最大允许打开的文件数为1024,建议至少为40000。请参考Neo4j手册。

因此,我按照这里的说明进行操作:http://docs.neo4j.org/chunked/1.6.2/configuration-linux-notes.html

并将下列内容添加到/etc/security/limits.conf中:

neo4j   soft    nofile  40000
neo4j   hard    nofile  40000

请取消注释 /etc/pam.d/su 中的此行

session    required   pam_limits.so

我重新启动服务器后,验证新限制

neo4j@precise64:~$ ulimit -n
40000

然后我重启了服务器。在启动时仍然遇到了相同的错误。

root@precise64:~# service neo4j-service 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...WARNING: not changing user
process [3161]... waiting for server to be ready....... OK.
http://localhost:7474/ is ready.

尽管该服务正在以neo4j用户身份运行:

root@precise64:~# ps -ef | grep 3161
neo4j     3161     1  2 17:43 pts/0    00:00:10 /usr/bin/java -cp /var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:/var/lib/neo4j/lib/geronimo-jta_1.1_spec-1.1.1.jar:/var/lib/neo4j/lib/lucene-core-3.6.2.jar:/var/lib/neo4j/lib/neo4j-cypher-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-commons-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-1.9-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-2.0-2.0.0.jar:/var/lib/neo4j/lib/neo4j-graph-algo-2.0.0.jar:/var/lib/neo4j/lib/neo4j-graph-matching-2.0.0.jar:/var/lib/neo4j/lib/neo4j-jmx-2.0.0.jar:/var/lib/neo4j/lib/neo4j-kernel-2.0.0.jar:/var/lib/neo4j/lib/neo4j-lucene-index-2.0.0.jar:/var/lib/neo4j/lib/neo4j-shell-2.0.0.jar:/var/lib/neo4j/lib/neo4j-udc-2.0.0.jar:/var/lib/neo4j/lib/org.apache.servicemix.bundles.jline-0.9.94_1.jar:/var/lib/neo4j/lib/parboiled-core-1.1.6.jar:/var/lib/neo4j/lib/parboiled-scala_2.10-1.1.6.jar:/var/lib/neo4j/lib/scala-library-2.10.3.jar:/var/lib/neo4j/lib/server-api-2.0.0.jar:/var/lib/neo4j/system/lib/asm-3.1.jar:/var/lib/neo4j/system/lib/bcprov-jdk16-140.jar:/var/lib/neo4j/system/lib/commons-beanutils-1.8.0.jar:/var/lib/neo4j/system/lib/commons-beanutils-core-1.8.0.jar:/var/lib/neo4j/system/lib/commons-collections-3.2.1.jar:/var/lib/neo4j/system/lib/commons-compiler-2.6.1.jar:/var/lib/neo4j/system/lib/commons-configuration-1.6.jar:/var/lib/neo4j/system/lib/commons-digester-1.8.1.jar:/var/lib/neo4j/system/lib/commons-io-1.4.jar:/var/lib/neo4j/system/lib/commons-lang-2.4.jar:/var/lib/neo4j/system/lib/commons-logging-1.1.1.jar:/var/lib/neo4j/system/lib/jackson-core-asl-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-jaxrs-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-mapper-asl-1.9.7.jar:/var/lib/neo4j/system/lib/janino-2.6.1.jar:/var/lib/neo4j/system/lib/javax.servlet-3.0.0.v201112011016.jar:/var/lib/neo4j/system/lib/jcl-over-slf4j-1.6.1.jar:/var/lib/neo4j/system/lib/jersey-core-1.9.jar:/var/lib/neo4j/system/lib/jersey-multipart-1.9.jar:/var/lib/neo4j/system/lib/jersey-server-1.9.jar:/var/lib/neo4j/system/lib/jetty-http-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-io-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-security-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-server-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-servlet-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-util-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-webapp-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-xml-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jsr311-api-1.1.2.r612.jar:/var/lib/neo4j/system/lib/logback-access-1.0.9.jar:/var/lib/neo4j/system/lib/logback-classic-1.0.9.jar:/var/lib/neo4j/system/lib/logback-core-1.0.9.jar:/var/lib/neo4j/system/lib/mimepull-1.6.jar:/var/lib/neo4j/system/lib/neo4j-browser-2.0.0.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.0-static-web.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.0.jar:/var/lib/neo4j/system/lib/rhino-1.7R3.jar:/var/lib/neo4j/system/lib/rrd4j-2.0.7.jar:/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:/var/lib/neo4j/conf/ -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 -Dneo4j.home=/var/lib/neo4j -Dneo4j.instance=/var/lib/neo4j -Dfile.encoding=UTF-8 org.neo4j.server.Bootstrapper
root      3238  2056  0 17:49 pts/0    00:00:00 grep --color=auto 3161

我认为以root身份启动该服务可能是问题的原因,所以我将其关闭并以neo4j用户身份启动。

root@precise64:~# service neo4j-service stop
root@precise64:~# su - neo4j 
neo4j@precise64:~$ service neo4j-service start
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...WARNING: not changing user
process [3435]... waiting for server to be ready....... OK.
http://localhost:7474/ is ready.
cp: cannot create regular file `/var/run/neo4j.pid': Permission denied

这样做失败了,因为无法创建pid文件。我认为这意味着这不是正确的方法,但是我继续编辑/etc/init.d/neo4j-service将pid文件的位置更改为neo4j用户的主文件夹:

#PIDFILE=/var/run/$NAME.pid
PIDFILE=/var/lib/neo4j/$Name.pid

当我以Neo4j用户身份运行服务时,事情就没有错误地启动。

所以,我的问题是:预期的行为是什么?只要neo4j用户具有正确的ulimit权限,以root身份启动服务是否有效,还是需要修改启动脚本/权限以允许neo4j用户创建其PID文件?


11
这段话原本应该发到Server Fault论坛上,但我可以先告诉你,你应该以root身份启动服务,PAM会话参数有意地不适用于服务(因为每个守护进程可能需要自己特定的一组参数,而不同于用户会话所得到的参数),解决此问题的正确方法是将ulimit -n 40000放入/etc/init.d/neo4j-service中(就在实际启动守护进程的命令之前)。 - zwol
9个回答

30

正如在此问题评论中提到并由此提交修复,自Neo4J 3.1以来,

你可以在/etc/default/neo4j中添加一行:

NEO4J_ULIMIT_NOFILE=60000

现在在Debian上设置打开文件数量的ulimit设置(60000个打开文件)不再需要使用/etc/security/limits.conf


24
你需要将以下条目添加到 /etc/security/limits.conf 文件中。
root   soft    nofile  40000
root   hard    nofile  40000

你需要以root用户或使用sudo启动服务。

这样做时,最终启动服务的用户是root用户。

如果文件中没有root用户的条目,则无法正常工作。

因此,您只需要在文件中添加这些条目,然后重新启动您的服务器。

我曾经遇到过同样的问题,这就是我能够解决它的方法。


6
如果您正在以不同的用户身份运行服务器,那么该怎么办?您应该为该用户添加条目吗?例如:bill soft nofile 40000 - sidewaiise
@sidewaiise:是的,请也添加那个用户。"bill soft nofile 40000" 和 "bill hard nofile 40000"。 - Jabba
2
您也可以使用 * soft nofile 40000。在这种情况下,无需指定特定的用户。 - Paulin Amougou

14

对我来说,@israel和@Tomasz Swider发布的解决方案并没有起作用(我正在运行Ubuntu 14.04)。然而,我可以通过修改文件/etc/init.d/neo4j-service来消除这个警告,正如在问题下面的评论中由@zwol建议的那样:

我在这个文件的do_start()方法中添加了一行ulimit -n 40000。在我的情况下,这个方法看起来如下:

do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        ulimit -n 40000
        start-stop-daemon --chuid ${NEO_USER} --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --chuid ${NEO_USER} --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
}

当我使用该命令启动服务时

sudo service neo4j-service start

它在没有警告的情况下开始,并返回以下消息:

Starting Neo4j Server...WARNING: not changing user
process [9921]... waiting for server to be ready...... OK.
http://localhost:7474/ is ready.

我不确定这是否是正确的方法,但如上所述,这是迄今为止唯一可行的解决方案,可以消除此警告。

编辑:

尚未测试,但似乎现在有一个更简单的解决方案可用:请参阅@Schrodinger's'Cat's答案


8
在 /etc/security/limits.conf 文件中,您需要为作为 neo4j 服务器运行用户的限制设置限制。如果您想要使用的用户是 root,则可以使用 root,但这可能不是一个好主意。设置如下:
neo4j   soft    nofile  40000 
neo4j   hard    nofile  40000

如果您添加了neo4j用户,则会起作用。我遇到了一些问题,所以我只将其设置为我的默认用户,即'bob'。

bob   soft    nofile  40000 
bob   hard    nofile  40000

然后我只需以Bob的身份登录neo4j。


你也可以使用 * soft nofile 40000。在这种情况下,无需指定特定的用户。 - Paulin Amougou

7

我按照之前回答中的建议进行了更改

root   soft    nofile  40000
root   hard    nofile  40000

neo4j   soft    nofile  40000 
neo4j   hard    nofile  40000

/etc/security/limits.conf

尽管如此,我仍然收到了关于只允许打开1024个文件的警告。 命令

ulimit -a

只显示允许的1024个打开文件。

诀窍是注销服务器,然后重新登录。 在新会话中,新限制配置的值被应用,我可以

service neo4j-server restart

允许打开40,000个文件。


3

感觉这是最笨重的选项,但它确实有效。我个人只需要在/etc/systemd/user.conf中设置NOFILE限制就可以了。 - Benjamin R

0
你可以在 /etc/security/limits.conf 中设置硬限制,并重新启动服务器使其生效。
但是在当前会话中,你可以运行 ulimit -n 40000

0

Neo4j社区中的答案是正确的,但我错过的是,为了使它工作,你还应该在Debian上将neo4j用作服务,而不仅仅像一个简单的进程。这也在官方文档中得到确认。在我的情况下,neo4j start总是会抛出错误。

我当前正在使用的设置:

  1. systemctl edit neo4j.service
  2. 插入:LimitNOFILE=40000
  3. 将neo4j作为服务启动:systemctl start neo4j.service

然后,我可以按以下方式检查编号:cat /proc/[processId]/limits


0

从下面的命令中检查一次当前值: ulimit -n 和 ulimit -a

你可以在以下路径上编辑该值: /etc/security/limit.conf


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接