一、问题
一台现网主机在root用户登录时报错“ could not open session ” ,在这之前由于oracle需要进行过ulimit参数的调整。如下:
#- can be one of the following: # - core - limits the core file size (KB) # - data - max data size (KB) # - fsize - maximum filesize (KB) # - memlock - max locked-in-memory address space (KB) # - nofile - max number of open files # - rss - max resident set size (KB) # - stack - max stack size (KB) # - cpu - max CPU time (MIN) # - nproc - max number of processes # - as - address space limit (KB) # - maxlogins - max number of logins for this user # - maxsyslogins - max number of logins on the system # - priority - the priority to run user process with # - locks - max number of file locks the user can hold # - sigpending - max number of pending signals # - msgqueue - max memory used by POSIX message queues (bytes) # - nice - max nice priority allowed to raise to values: [-20, 19] # - rtprio - max realtime priority root soft nproc unlimited root hard nproc unlimited root soft nofile unlimited root hard nofile unlimited
<br />
上面的配置咋一看没什么问题,而且理论上来说root用户的nproc和nofile是不受限制的,这里根本也无需加该设置。通过手动去配置发现nofile是无法设置成unlimited的。如下:
[root@361way ~]# ulimit -u unlimited [root@361way ~]# ulimit -n unlimited -bash: ulimit: open files: cannot modify limit: Operation not permitted [root@361way ~]#
<br />
由上面可以发现max open file是无法设置成unlimited的,这样设置后,通过登录su到root就会提示”could not open session” 。修复方法就是将刚增加的四行或最后两行删除就行了。
在Http长连接200万尝试及调优篇中,也提到过 “在2.6.25内核之前有个宏定义,定义了这个值的最大值,为1024*1024,正好是100万,而在2.6.25内核及其之后,这个值是可以通过/proc/sys/fs/nr_open来设置。”,所以该值理论上最大也就200万左右。
二、扩展
其他情况下也可能会出现”could not open session” 报错的情况。如:
1、max open file值为负值;
2、/etc下部分目录被修改时,也会提示该报错。这里参见痞子阿飞的blog ,不过该问题我在测试时发现报错信息和原文提到的不同,如下:
[root@361way /]# su - amos -bash: /etc/profile: Permission denied -bash-4.1$ exit logout -bash: /etc/bash.bash_logout: Permission denied [root@361way /]# chmod 755 etc/
<br />