Uncle_Mike

导航

Resolution for error: su: failed to execute /bin/bash: Resource temporarily unavailable

Today we met a problem about user cannot su to a general dev account with the error message below:

su: failed to execute /bin/bash: Resource temporarily unavailable

And checked the /var/log/message and /var/log/secure, found there is no resource available for the fork() to generate new processes.

sshd[22208]: error: do_exec_pty: fork: Resource temporarily unavailable

Refer to: http://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/create.html  if you are interested in fork function.

 

Then we checked the max user processes for this user:

[test@hostname ~]$ ulimit -a

core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127951
max locked memory (kbytes, -l) 64
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) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 4096
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

[Test@lvs-genas-008 log]$ cat /proc/sys/fs/file-nr
1536   0   3247300

Or use lsof to check the opening files || processes.

Opened too files. 

Resolution: we just need to increase the open files param.

系统设置--ulimit
语  法:ulimit [-aHS][-c <core文件上 限>][-d <数据节区大小>][-f <文件大小>][-m <内存大小>][-n <文件数 目>][-p <缓冲区大小>][-s <堆叠大小>][-t <CPU时间>][-u <程序数 目>][-v <虚拟内存大小>]

补充说明:ulimit为shell内建指令,可用来控制shell执行程序的资源。

参  数:
  -a  显示目前资源限制的设定。 
  -c <core文件上限>  设定core文件的最大值,单位为区块。 
  -d <数据节区大小>  程序数据节区的最大值,单位为KB。 
  -f <文件大小>  shell所能建立的最大文件,单位为区块。 
  -H  设定资源的硬性限制,也就是管理员所设下的限制。 
  -m <内存大小>  指定可使用内存的上限,单位为KB。 
  -n <文件数目>  指定同一时间最多可开启的文件数。 
  -p <缓冲区大小>  指定管道缓冲区的大小,单位512字节。 
  -s <堆叠大小>  指定堆叠的上限,单位为KB。 
  -S  设定资源的弹性限制。 
  -t <CPU时间>  指定CPU使用时间的上限,单位为秒。 
  -u <程序数目>  用户最多可开启的程序数目。 
  -v <虚拟内存大小>  指定可使用的虚拟内存上限,单位为KB。
 
We can use ulimit -n number  to modify the opening files number.
 
Another way is:

Append a new line to current user's ./bash_profile

ulimit –n 65535

next time when get into this user's shell, will be good, no need to restart server.

Third way is change below file directly:

/etc/security/limits.conf

@test   soft    nofile           65535

@test          hard    nofile           65535

@test          soft    nproc           65535

@test          hard    nproc           65535

 

After a while the file will sync to server, also no need to reboot server.

posted on 2018-12-20 16:17  Uncle_Mike  阅读(3621)  评论(0编辑  收藏  举报