【问题标题】:How to increase Neo4j's maximum file open limit (ulimit) in Ubuntu?如何在 Ubuntu 中增加 Neo4j 的最大文件打开限制(ulimit)?
【发布时间】:2014-02-26 05:41:09
【问题描述】:

目前ulimit -n 显示10000。我想把它增加到40000。我已经编辑了“/etc/sysctl.conf”并输入了fs.file-max=40000。我还编辑了/etc/security/limits.conf 并更新了硬值和软值。但是 ulimit 仍然显示10000。完成所有这些更改后,我重新启动了笔记本电脑。我可以访问 root 密码。

usr_name@usr_name-lap:/etc$ /sbin/sysctl fs.file-max
fs.file-max = 500000

/etc/security/limits.conf 中添加了以下行 -

*     soft    nofile          40000
*     hard    nofile          40000

我还在/etc/pam.d/su-中添加了以下行-

session    required   pam_limits.so

我已经尝试了其他论坛上给出的所有可能的方法,但我可以达到10000 的最大限制,不能超过这个限制。可能是什么问题?

我进行此更改是因为 neo4j 引发最大打开文件限制已达到错误。

【问题讨论】:

  • 你做对了,重启系统就可以了:sudo ulimit -n 40000
  • @0x90 我重新启动了系统。但即便如此,它也不会改变。
  • 作为 Ubuntu 特有的,它可能实际上属于 askubuntu.com ;类似的问题在这里:askubuntu.com/questions/162229/…
  • 添加到 /etc/security/limits.conf 后,要重新启动哪个服务以使更改生效?

标签: linux ubuntu neo4j limit ulimit


【解决方案1】:

您正在做的事情不适用于 root 用户。也许您以 root 身份运行服务,因此您看不到更改。

要增加 root 用户的 ulimit,您应该将 * 替换为 root。 * 不适用于 root 用户。休息和你一样。我会在这里重新引用它。

将以下行添加到文件中:/etc/security/limits.conf

root soft  nofile 40000

root hard  nofile 40000

然后在文件中添加以下行:/etc/pam.d/common-session

session required pam_limits.so

这将更新 root 用户的 ulimit。正如 cmets 中所述,您甚至不必重新启动即可看到更改。

【讨论】:

  • 您实际上不需要重新启动即可使新限制生效。编辑 /etc/pam.d/common-session 文件的目的是,任何新会话的创建都会导致限制文件被处理。
  • 此过程有效。无需重新启动。只需注销并重新登录即可查看结果。
  • 对于 neo4j-service 或任何其他使用 start-stop-daemon 的服务,common-session-* 技巧将不起作用,因为 start-stop-daemon 根本不利用 PAM。除了在服务启动之前在 init 脚本的某处添加显式 ulimit -n xxx 调用之外别无他法。
  • 在 Ubuntu 16.04.1 LTS 上运行良好
【解决方案2】:

1) 检查 sysctl file-max 限制:

$ cat /proc/sys/fs/file-max

如果限制低于您的期望值,请打开sysctl.conf 并在文件末尾添加此行:

fs.file-max = 65536

最后,应用sysctl 限制:

$ sysctl -p 

2) 编辑/etc/security/limits.conf 并在下面添加

* soft     nproc          65535    
* hard     nproc          65535   
* soft     nofile         65535   
* hard     nofile         65535

这些限制不适用于root 用户,如果您想更改root 限制,您必须明确地这样做:

root soft     nofile         65535   
root hard     nofile         65535
...

3) 重启系统或在/etc/pam.d/common-session末尾添加以下行:

session required pam_limits.so

注销并重新登录。

4) 检查软限制:

$ ulimit -a

和硬性限制:

$ ulimit -Ha
....

open files                      (-n) 65535

参考:http://ithubinfo.blogspot.in/2013/07/how-to-increase-ulimit-open-file-and.html

【讨论】:

  • 确保您注销并重新登录,以便它可以反映您的更改,如果您没有使用 root 用户检查它,对于 ubuntu,您可以通过 gnome-session-quit 执行此操作
  • /proc/sys/fs/file-max 不是系统允许的最大 nofile !!!例如,在我的系统上,默认设置为 1528702。将其设置为limits.conf 中软/硬限制的值根本不允许用户从1024 增加限制。我不得不将 limits.conf 设置为更保守的东西,例如256*1024 = 262144,最后 ulimit -a 对普通用户显示相同。
【解决方案3】:

我使用的是 Debian,但这个解决方案应该适用于 Ubuntu。
您必须在 neo4j-service 脚本中添加一行。
这是我所做的:

nano /etc/init.d/neo4j-service
start-stop-daemon 行之前添加 « ulimit –n 40000 » do_start 部分

请注意,我使用的是 2.0 版企业版。 希望这会对你有所帮助。

【讨论】:

  • FWIW Ubuntu Server 14.04 上没有这样的脚本。我的解决方案是在这个问题(和lornix的回答)中找到的:askubuntu.com/questions/162229/…——简而言之,你需要编辑/etc/security/limits.conf/etc/pam.d/common-session*
  • 我看到原来的提问者顺便提到了neo4j。似乎这可能属于问题的主题,因为它与 Ubuntu 无关。
  • 在 Ubuntu 14.04 中,确实有一个 /etc/init.d/neo4j-service 文件,Martin Larivière 是对的,插入 uname -n 40000 解决了这个问题。我不知道 Ubuntu Server 和 Ubuntu 之间的区别,所以也许你也是对的,我添加这个只是为了澄清 Martin 写的内容解决了普通 Ubuntu 14.04 的问题。
  • @Lambat,对于 neo4j-service,common-session-* 技巧不起作用,因为 neo4j-service 基于 start-stop-daemonstart-stop-daemon 根本不利用 PAM .唯一的解决方案确实是在初始化脚本中添加一个显式的ulimit -n xxx 调用。
  • 这不是解决方案,这是创可贴。
【解决方案4】:

我遇到了同样的问题,并通过将条目添加到 /etc/security/limits.d/90-somefile.conf 使其工作。请注意,为了查看限制是否有效,我必须完全退出 ssh 会话,然后重新登录。

我想为运行服务的特定用户设置限制,但似乎我得到了为我登录的用户设置的限制。下面是一个示例,说明如何根据经过身份验证的用户而不是有效用户设置 ulimit:

$ sudo cat /etc/security/limits.d/90-nofiles.conf
loginuser    soft    nofile   10240
loginuser    hard    nofile   10240
root         soft    nofile   10241
root         hard    nofile   10241
serviceuser  soft    nofile   10242
serviceuser  hard    nofile   10242

$ whoami
loginuser
$ ulimit -n
10240
$ sudo -i
# ulimit -n
10240    # loginuser's limit
# su - serviceuser
$ ulimit -n
10240    # still loginuser's limit.

您可以使用* 为所有用户指定增加值。如果我以我登录的用户身份重新启动服务,并将ulimit -n 添加到初始化脚本,我会看到初始登录用户的限制已经到位。我没有机会验证在系统启动期间使用了哪些用户限制,或者确定我正在运行的服务(以 start-stop-daemon 启动)的实际 nofile 限制是多少。

目前有两种方法有效:

  1. 在 start-stop-daemon 之前向 init 脚本添加 ulimit 调整。
  2. 安全文件中的通配符或更广泛的 ulimit 设置。

【讨论】:

  • 当我做你做的事情时(从whoami开始)我首先得到1024,然后是65536(对于root),然后是65536对于用户。但第一个是同一个用户。你对此有什么解释吗,我很困惑
  • 这听起来很奇怪。如何从用户切换到 root 并返回到用户?设置文件后是否完全注销?您最初可能处于缓存会话中,然后根据您返回用户的方式使用新会话。
  • 我一直在重启,只是为了确定。还尝试设置 /etc/sysctl.conf -> fs.file-max = 1000000 应该为所有用户全局修复它,也没有结果。就像一个过程忽略了我。正如您所描述的,我使用su - my_user_name 从root -> 用户切换到用户。这表明系统知道它应该为该用户使用什么,但它不...
【解决方案5】:

您可以在运行neo4j 之前更改neo4j 的初始化脚本以执行ulimit -n 40000

但是,我禁不住觉得你找错了树。 neo4j 是否合法需要超过 10,000 个打开的文件描述符?这听起来很像neo4j 或您使用它的方式中的错误。我会尝试解决这个问题。

【讨论】:

  • 我开始使用neo4j 使用neo4j start。我在哪里可以找到它的初始化脚本?
  • 尝试在neo4j start之前输入ulimit -n 40000
【解决方案6】:

我很难让它工作。

无论您的用户权限如何,都可以使用以下内容进行更新。

sudo sysctl -w fs.inotify.max_user_watches=100000

编辑

刚刚在另一个 stackexchange 网站上从另一个用户那里看到了这个(两者都有效,但这个版本永久更新系统设置,而不是临时):

echo fs.inotify.max_user_watches=100000 | sudo tee -a /etc/sysctl.conf; 
sudo sysctl -p

【讨论】:

    【解决方案7】:

    尝试运行这个命令,它会在/etc/security/limits.d下创建一个*_limits.conf文件

    echo "* soft nofile 102400" > /etc/security/limits.d/*_limits.conf && echo "* hard nofile 102400" >> /etc/security/limits.d/*_limits.conf
    

    只需退出终端并再次登录并通过ulimit -n进行验证,它将为*用户设置

    【讨论】:

    • 简单而有用的答案。
    【解决方案8】:

    tl;dr 设置软限制和硬限制

    我确定它按预期工作,但我会在此处添加它以防万一。 为了完整起见,此处设置了限制(语法见下文): /etc/security/limits.conf

    some_user       soft    nofile          60000
    some_user       hard    nofile          60000
    

    并在 /etc/pam.d/common-session 中使用以下内容激活:

    session required pam_limits.so
    

    如果您只设置硬限制,ulimit -a 将显示默认值 (1024): 如果您只设置了 soft 限制 ulimit -a 将显示 (4096)

    如果你同时设置它们ulimit -a 将显示软限制(当然是硬限制)

    【讨论】:

      【解决方案9】:

      我是这样做的

      echo "NEO4J_ULIMIT_NOFILE=50000" >> neo4j
      mv neo4j /etc/default/
      

      【讨论】:

        【解决方案10】:

        ULIMIT 配置:

        1. 以root用户登录
        2. vi security/limits.conf
        3. 在下面输入条目

          网站用户的

          Ulimit配置开始

          website   soft   nofile    8192
          website   hard   nofile    8192
          website   soft   nproc    4096
          website   hard   nproc    8192
          website   soft   core    unlimited
          website   hard   core    unlimited
          
        4. 为所有用户创建以下条目

          每个用户的ulimit配置

          *   soft   nofile    8192
          *   hard   nofile    8192
          *   soft   nproc    4096
          *   hard   nproc    8192
          *   soft   core    unlimited
          *   hard   core    unlimited
          
        5. 修改文件后,用户需要注销并重新登录才能看到新的值。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-06-03
          • 2011-03-11
          • 1970-01-01
          • 2022-01-25
          • 2017-10-19
          • 1970-01-01
          • 2016-06-24
          • 1970-01-01
          相关资源
          最近更新 更多