“软/硬 nofile”在 Linux 上是什么意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3107476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "soft/hard nofile" mean on Linux
提问by Frank Fu
When I tried to install a software on RedHat EL5, I got the error that the expected value of soft/hard nofile is 4096 while the default is 1024. I managed to increase the number, but I don't know what the parameters are. Are they refering to soft link and hard link?
尝试在RedHat EL5上安装软件时,出现soft/hard nofile的期望值为4096,而默认值为1024的错误。我设法增加了数字,但我不知道参数是什么。他们是指软链接和硬链接吗?
The way I change it is:
我改变它的方式是:
A) modify the /etc/security/limits.conf
A) 修改/etc/security/limits.conf
user soft nofile 5000
user hard nofile 6000
B) modify the /etc/pam.d/system-auth
B) 修改/etc/pam.d/system-auth
session required /lib/security/$ISA/pam_limits.so
C) modify /etc/pam.d/login
C) 修改 /etc/pam.d/login
session required pam_limits.so
After making the change (by switching to root). It seems that I have to reboot machine to make it effect. But some post online say that it should come to effect right after making the change. Would appreciate if someone can clarify it.
进行更改后(通过切换到 root)。看来我必须重新启动机器才能生效。但是网上的一些帖子说它应该在进行更改后立即生效。如果有人可以澄清它,将不胜感激。
采纳答案by Jacek Konieczny
These are: a 'soft' and a 'hard' limit for number of files a process may have opened at a time. Both limit the same resource (no relation to hard links or anything). The difference is: the soft limit may be changed later, up to the hard limit value, by the process running with these limits and hard limit can only be lowered – the process cannot assign itself more resources by increasing the hard limit (except processes running with superuser privileges (as root)).
它们是: 一个进程一次可能打开的文件数量的“软”和“硬”限制。两者都限制相同的资源(与硬链接或任何东西无关)。区别在于:软限制可能会在以后更改,直到硬限制值,由这些限制运行的进程和硬限制只能降低 - 进程不能通过增加硬限制为自己分配更多资源(运行的进程除外)具有超级用户权限(作为 root))。
Similar limits can be set for other system resources: system memory, CPU time, etc. See the setrlimit(2)
manual page or the description of your shell's ulimit
build-in command (e.g. in the bash(1)
manual page.
可以为其他系统资源设置类似的限制:系统内存、CPU 时间等。请参阅setrlimit(2)
手册页或 shellulimit
内置命令的说明(例如在bash(1)
手册页中。
回答by Chris
No reboot is required, but /etc/security/limits.conf is only processed when /lib/security/pam_limits.so runs, which is at login time, and the values are inherited by child processes. After a new login, anything under that login will inherit the values specified.
不需要重新启动,但 /etc/security/limits.conf 仅在 /lib/security/pam_limits.so 运行时处理,即在登录时,并且值由子进程继承。新登录后,该登录名下的任何内容都将继承指定的值。
回答by slm
As an additional aside, some distros include /etc/security/limits.d
where "snippets" of limit configurations can be placed. You can create files such as this:
另外,一些发行版包括/etc/security/limits.d
可以放置限制配置的“片段”的位置。您可以创建如下文件:
$ ll /etc/security/limits.d/
-rw-r--r--. 1 root root 191 Aug 18 10:26 90-nproc.conf
-rw-r--r-- 1 root root 70 Sep 29 12:54 90-was-filedesc.conf
With files containing whatever limits you want to set:
对于包含您要设置的任何限制的文件:
$ more /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 1024
root soft nproc unlimited
$ more /etc/security/limits.d/90-was-filedesc.conf
root hard nofile 20000
I find using this method to manage these types of overrides much cleaner than mucking with /etc/security/limits.conf
.
我发现使用这种方法来管理这些类型的覆盖比使用/etc/security/limits.conf
.
Also if you want to set both soft/hard to the same value you can use the -
as the type.
此外,如果您想将软/硬设置为相同的值,您可以使用-
作为类型。
$ more /etc/security/limits.d/90-was-filedesc.conf
root - nofile 20000