无法像我想要的那样设置 ulimit -n

Pet*_*pho 2 linux ulimit

我只想设置 ulimit -n (每个进程最大打开文件数)并让设置在重新启动后继续存在,但事实证明这很困难。

我不知道还能在哪里进行更改以允许对其进行设置。

root@z:~# cat /etc/sysctl.conf | grep file-max
fs.file-max = 2000000
root@z:~# cat /etc/security/limits.conf | grep nofile
#        - nofile - max number of open files
* soft     nofile         2000000   
* hard     nofile         2000000
root@z:~# sudo sysctl -p | grep file
fs.file-max = 2000000
root@z:~# ulimit -n 2000000
-su: ulimit: open files: cannot modify limit: Operation not permitted
root@z:~# whoami
root
Run Code Online (Sandbox Code Playgroud)

另一方面,这个较低的设置是有效的:

ulimit -n 1048576
Run Code Online (Sandbox Code Playgroud)

请让我知道如何将每个进程限制设置为 2000000 以及如何在重新启动后保持该设置,我使用的是 Ubuntu 18.04

ilk*_*chu 5

# ulimit -n 1048576
# ulimit -n 2000000
bash: ulimit: open files: cannot modify limit: Operation not permitted
# sysctl fs.nr_open
fs.nr_open = 1048576
# sysctl fs.nr_open=2000000
fs.nr_open = 2000000
# ulimit -n 2000000
# ulimit -n
2000000
Run Code Online (Sandbox Code Playgroud)

proc(5) 手册页

/proc/sys/fs/nr_open
该文件对资源限制可以提高到的值施加上限 RLIMIT_NOFILE(请参阅 getrlimit(2))。对于非特权进程和特权进程都强制执行此上限。该文件中的默认值为 1048576。

另一方面,file-max是所有进程的极限:

/proc/sys/fs/file-max
该文件定义了所有进程打开文件数量的系统范围限制。遇到此限制时失败的系统调用会失败并显示错误 ENFILE。

我并不是完全不知道足够多的打开文件是否会导致其他问题。