每个用户在Linux中设置“打开文件”限制。 不能设置超过1024

我尝试在CentOS 5.5 Linux上为特定用户增加打开的文件限制。 我在/etc/security/limits.conf中添加了一个新行:

seed hard nofile 10240 

然后做testing:

 runuser -s /bin/bash - seed -c "ulimit -S -c 0>/dev/null 2>&1; ulimit -a" 0 core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 8185 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) unlimited virtual memory (kbytes, -v) unlimited file locks (-x) unlimited 

正如你所看到的 – 打开的文件限制仍然是1024.如果我设置限制为1000,它将被应用。 所以,我不能设置超过1024的限制。

我怎样才能做到这一点?? 我只需要为1个用户设置设置,而不是系统范围。

我怀疑runuser没有通过PAM的“login”进程应用limits.conf,或者pam_limits.so被禁用。 在Debian中,至less,/etc/pam.d/su将pam_limits.so注释掉,以便限制从运行su的用户inheritance。

在CentOS 5.5 Linux上增加某些用户的开放文件限制:

1 – 在文件'/etc/security/limits.conf'中添加: – http://gerardnico.com/wiki/linux/limits.conf

 ... # seed osuser - extended max number of open files seed hard nofile 10240 # End of file 

2 – 在文件“ / etc / profile ”或“ /home/seed/.bash_profile ”中添加:

 if [ $USER = "seed" ]; then ulimit -n 10240 fi 

在linux系统上,有三个地方设置了文件限制,每个地方都是独立的:

  1. 内核,如在/ proc / sys / fs / file-max中,通过sysctl fs.filemax或/etc/sysctl.conf

  2. 由ulimit -n控制的shell中的ulimit

  3. PAM,通过/etc/security/limits.conf来设置

优先级数字实际上决定了你的进程的限制是上述三者中的至less一个。

使用“ulimit -a”可以看到软限制,红帽5.8中的1024是默认的软限制

 vim /etc/security/limits.conf user01 soft nofile 1024 user01 hard nofile 2048 ulimit -Sn 1024 ulimit -Hn 2048 

阅读过程

 grep "Max open files" /proc/$$/limits Max open files 1024 2048 files