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

w3r*_*3ss 12 ssh cron pam ulimit

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

/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
Run Code Online (Sandbox Code Playgroud)

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

session required pam_limits.so
Run Code Online (Sandbox Code Playgroud)

重新启动后,登录为任何用户和发行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
Run Code Online (Sandbox Code Playgroud)

没运气。

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

Dou*_*ies 11

我以这种方式增加了每个人的文件数量限制(来自 的段/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)
Run Code Online (Sandbox Code Playgroud)

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

~/config/security$ ulimit -n
16384
Run Code Online (Sandbox Code Playgroud)

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

# ulimit -n
1024
Run Code Online (Sandbox Code Playgroud)

如果还需要为 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)
Run Code Online (Sandbox Code Playgroud)

所以:

$ sudo su
# ulimit -n
131072
Run Code Online (Sandbox Code Playgroud)

  • 那仍然没有效果。您是否必须在任何地方放置`session require pam_limits.so`? (2认同)