Resource temporarily unavailable 解决方案

最近主机上经常出现“Resource temporarily unavailable”错误,无法执行任何命令,甚至使用root也切不进相关用户。上网查了一下,发现是最大线程数限制了,无法创建新线程导致,虽然已有线程不受影响,但是给新建线程,或者管理员使用来说,造成了很大的麻烦,具体情形如下:

1
2
3
4
5
6
7
[asbuser@TEST ~]$ sudo su - bdexuser
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: Resource temporarily unavailable
-bash-4.1$
1
2
3
4
5
6
7
8
9
10
11
12
-bash-4.1$ whoami
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: Resource temporarily unavailable
-bash-4.1$
1
2
3
[root@TEST limits.d]# su - test
su: cannot set user id: Resource temporarily unavailable
[root@TEST limits.d]#

后来通过查看/etc/security/limits.d/90-nproc.conf,发现对于普通用户的线程最大数才1024* soft nproc 1024),这对于服务账号来说,远远不够,故将1024改成65535,问题解决。

注意:

  • /etc/security/limits.d/90-nproc.conf不一定所有主机都会创建,只需要查看/etc/security/limits.d/目录下的.conf文件,或/etc/securitylimits.conf文件,看是否有对应的限制即可。

  • 如果用户较多,不建议泛指(* soft nproc 65535),可在后面添加一行,给指定用户开放限制即可(test soft nproc 65535)。