一、问题

一台现网主机在root用户登录时报错“ could not open session ” ,在这之前由于oracle需要进行过ulimit参数的调整。如下:

 1# can be one of the following:
 2#        - core - limits the core file size (KB)
 3#        - data - max data size (KB)
 4#        - fsize - maximum filesize (KB)
 5#        - memlock - max locked-in-memory address space (KB)
 6#        - nofile - max number of open files
 7#        - rss - max resident set size (KB)
 8#        - stack - max stack size (KB)
 9#        - cpu - max CPU time (MIN)
10#        - nproc - max number of processes
11#        - as - address space limit (KB)
12#        - maxlogins - max number of logins for this user
13#        - maxsyslogins - max number of logins on the system
14#        - priority - the priority to run user process with
15#        - locks - max number of file locks the user can hold
16#        - sigpending - max number of pending signals
17#        - msgqueue - max memory used by POSIX message queues (bytes)
18#        - nice - max nice priority allowed to raise to values: [-20, 19]
19#        - rtprio - max realtime priority
20root              soft    nproc   unlimited
21root              hard    nproc   unlimited
22root              soft    nofile  unlimited
23root              hard    nofile  unlimited

上面的配置咋一看没什么问题,而且理论上来说root用户的nproc和nofile是不受限制的,这里根本也无需加该设置。通过手动去配置发现nofile是无法设置成unlimited的。如下:

1[root@361way ~]# ulimit -u unlimited
2[root@361way ~]# ulimit -n unlimited
3-bash: ulimit: open files: cannot modify limit: Operation not permitted
4[root@361way ~]# 

由上面可以发现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 ,不过该问题我在测试时发现报错信息和原文提到的不同,如下:

1[root@361way /]# su - amos
2-bash: /etc/profile: Permission denied
3-bash-4.1$ exit
4logout
5-bash: /etc/bash.bash_logout: Permission denied
6[root@361way /]# chmod 755 etc/