我在/etc/security/limits.conf(CentOS 6.2)中设置了以下值(-1将被解析为无限制,我猜)
root nofile soft -1
root nofile hard -1
我现在无法使用root用户登录.与here中描述的问题类似.将值设置回来可以解决问题.
任何人都可以帮忙解释一下吗?
更新:
多谢你们.我错误地记住了我的设置.那些价值观应该是
root soft nofile -1 root hard nofile -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)