永久提高 Ubuntu 14.04 LTS 中的 nofile 限制

永久提高 Ubuntu 14.04 LTS 中的 nofile 限制

我似乎无法弄清楚究竟需要什么才能允许所有用户永久提高最大文件描述符数量。

/etc/security/limits.conf

root    hard    nofile    1500000
root    soft    nofile    1000000
root    hard    nproc     15000
root    soft    nproc     10000
*       hard    nofile    1500000
*       soft    nofile    1000000
*       hard    nproc     15000
*       soft    nproc     10000

我已将以下内容放置在/etc/pam.d/common-session

session required pam_limits.so

重新启动后,以任何用户身份登录并发出ulimit -n结果1024

之后,我尝试pam_limits.so进入下的每个文件/etc/pam.d。重新启动。登录。没有那么幸运。

如果我发出命令ulimit -n 1000000,然后检查,限制是否按预期设置。因此,我将其放入@reboot ulimit -n 1000000crontab -e重新启动。登录。没有运气。

我检查过/etc/ssh/sshd_config并且 PAM 已启用。

我尝试使用以下方法在每次重启时设置限制:

/sbin/sysctl -w fs.file-max=1000000
/sbin/sysctl -p

没有运气。

我的服务器有大量并发流量,需要这么高的限制,因为服务器需要很长时间才能清除文件描述符。我必须做什么才能永久提高文件描述符限制?

答案1

我通过以下方式增加了每个人的文件数量限制(摘自/etc/security/limits.conf):

#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files (Doug: - so Samba will not complain)
* - nofile 16384
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)

那是在 12.04 服务器上。但是,我在 14.04 服务器上测试了 100000,运行正常。(编辑:也在 20.04 上检查过)

~/config/security$ ulimit -n
16384

编辑:对于大多数应用程序来说这已经足够了,但它不会改变 root 的默认值:

# ulimit -n
1024

如果 root 也需要更改该数字,那么(2020.09.04 - 我现在使用 131,072):

#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
* - nofile 131072
root - nofile 131072
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)

所以:

$ sudo su
# ulimit -n
131072

相关内容