三分薄地,认真耕耘

导航

 

对于出现/bin/sh: fork: retry: 资源暂时不可用这样的报错时,说明Linux的open file最大连接数已满。

1、通过ulimit -a命令查看可以看到该用户的max user processes值


-bash-4.1$ 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) 127209
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
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) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

2、解决的方法如下:

切换至root用户依次执行

2.1 centos6中修改/etc/security/limits.d/90-nproc.conf文件,centos7中修改/etc/security/limits.d/20-nproc.conf。

将npoc设置最大。修改后,内容如下:


cat /etc/security/limits.d/90-nproc.conf

*          soft    nproc     65535
root       soft    nproc     unlimited


2.2 修改/etc/security/limits.conf,增加nofile。修改方法如下:


echo "* - nofile 65535" >> /etc/security/limits.conf
echo "* - noproc 65535" >> /etc/security/limits.conf

其中:

    • 代表针对所有用户,noproc 是代表最大进程数,nofile 是代表最大文件打开数
    • 的意思为soft 和hard 全部限制

2.3 /sbin/sysctl -p 使配置生效

-bash-4.1$/sbin/sysctl -p 
-bash-4.1$ 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) 127209
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
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) 65535     # Linux的open file最大连接数已经修改
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

posted on 2020-05-09 15:14  平复心态  阅读(3482)  评论(0编辑  收藏  举报