这发生在 Ubuntu Release 12.04(精确)64 位内核 Linux 3.2.0-25-virtual
我正在尝试增加允许用户打开的文件数。这适用于我的 eclipse java 应用程序,其中 1024 的当前限制是不够的。
根据到目前为止我发现的帖子,我应该能够将行放入
/etc/security/limits.conf 像这样:
soft nofile 4096
hard nofile 4096
Run Code Online (Sandbox Code Playgroud)
增加允许所有用户打开的文件数。
但这对我不起作用,我认为问题与该文件无关。
对于所有用户,默认限制为 1024,无论 /etc/security/limits.conf 中的内容如何(更改该文件后我重新启动)
$ ulimit -n
1024
Run Code Online (Sandbox Code Playgroud)
现在,尽管 /etc/security/limits.conf 中的条目我无法增加:
$ ulimit -n 2048
Run Code Online (Sandbox Code Playgroud)
-bash: ulimit: open files: cannot modify limit: Operation not allowed 奇怪的是我可以向下改变限制,但不能向上改变 - 甚至回到低于原始限制的数字:
$ ulimit -n 800
$ ulimit -n
800
$ ulimit -n 900
-bash: ulimit: open files: cannot modify limit: Operation not permitted
Run Code Online (Sandbox Code Playgroud)
作为 root,我可以将限制更改为任何我想要的,向上或向下。它甚至似乎都不关心 /proc/sys/fs/file-max 中所谓的系统范围限制
# cat /proc/sys/fs/file-max
188897
# ulimit -n 188898
# ulimit -n
188898
Run Code Online (Sandbox Code Playgroud)
但即使我让 eclipse 以 root 身份运行,我的应用程序仍然因为“打开文件太多”异常而崩溃!
到目前为止,我还没有找到任何方法来增加非 root 用户的打开文件限制。
我应该如何正确地做到这一点?我看过其他几个帖子,但没有运气!
lor*_*nix 157
ulimit默认情况下,该命令会更改 HARD 限制,您(用户)可以降低该限制,但不能提高该限制。
使用-S选项更改SOFT限制,范围可以是 0-{ HARD }。
我实际上已别名ulimit为ulimit -S,因此它始终默认为软限制。
alias ulimit='ulimit -S'
Run Code Online (Sandbox Code Playgroud)
至于您的问题,您在/etc/security/limits.conf.
应该有四列,但您的示例中缺少第一列。
* soft nofile 4096
* hard nofile 4096
Run Code Online (Sandbox Code Playgroud)
第一列描述了申请限额的世卫组织。'*' 是通配符,表示所有用户。要提高root的限制,您必须明确输入 'root' 而不是 '*'。
您还需要编辑/etc/pam.d/common-session*以下行并将其添加到末尾:
session required pam_limits.so
Run Code Online (Sandbox Code Playgroud)
小智 23
如果您在每个用户的基础上使用软限制和硬限制,您可以使用以下内容:
su USER --shell /bin/bash --command "ulimit -n"
Run Code Online (Sandbox Code Playgroud)
检查您的设置是否适用于该特定用户。
ulimit -S -n 4096
Run Code Online (Sandbox Code Playgroud)
这应该会将打开文件的软限制 (-n) 增加到 4096。
我有很多麻烦让这个工作。
无论您的用户许可如何,使用以下内容都可以让您更新它。
sudo sysctl -w fs.inotify.max_user_watches=100000
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
489914 次 |
| 最近记录: |