/etc/security/limits.conf
我在(CentOS 6.2)中设置了以下值(我想 -1 将被解析为无限制)
root 无文件软-1
root nofile 硬 -1
我现在无法以 root 用户身份登录。与描述的问题类似这里。将该值重新设置即可解决该问题。
有人能帮忙解释一下吗?
更新:
谢谢大家。我记错了我的设置。这些值应该是
root soft nofile -1
root hard nofile -1
答案1
正如@Michael Hampton 告诉你的那样,你的语法是错误的,但无论如何,我认为将文件限制设置为无限制并不是一个好主意
您可以阅读此文章以了解更多信息https://stackoverflow.com/questions/1212925/on-linux-set-maximum-open-files-to-unlimited-possible
我下载了内核版本 linux-2.6.32.61,并从 kernel/sys.c 中看到了以下内容:
SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)
{
struct rlimit new_rlim, *old_rlim;
int retval;
if (resource >= RLIM_NLIMITS)
return -EINVAL;
if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
return -EFAULT;
if (new_rlim.rlim_cur > new_rlim.rlim_max)
return -EINVAL;
old_rlim = current->signal->rlim + resource;
if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
!capable(CAP_SYS_RESOURCE))
return -EPERM;
if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
return -EPERM;
来自 man proc
The kernel constant NR_OPEN imposes an upper limit on the value that may be placed in
file-max.
来自./fs/file.c:
./fs/file.c:30:int sysctl_nr_open __read_mostly = 1024*1024;
echo $((1024*1024))
1048576
为什么你需要比 nr_open 更多的文件?
我使用您的 limits.conf 设置进行了测试:
/etc/pam.d/su:
egrep -v "^#|^$" /etc/pam.d/su
auth sufficient pam_rootok.so
session required pam_env.so readenv=1
session required pam_env.so readenv=1 envfile=/etc/default/locale
session optional pam_mail.so nopen
session required pam_limits.so
@include common-auth
@include common-account
@include common-session
现在我将使用 su 命令切换到 root 用户:
root@ubuntu:~# strace -e setrlimit su - root
setrlimit(RLIMIT_NOFILE, {rlim_cur=RLIM64_INFINITY, rlim_max=RLIM64_INFINITY}) = -1 EPERM (Operationnot permitted)
答案2
您已反转第二和第三个字段。
正确的内容如下:
root soft nofile -1
root hard nofile -1
答案3
您在 中设置的数字nofile
(打开文件数)不能大于 中找到的值/proc/sys/fs/nr_open
。请检查该文件并使用该值。
[root]# cat /proc/sys/fs/nr_open 1048576
[root]# cat /etc/security/limits.d/biguser.conf biguser - nofile 1048576