Quantcast
Channel: ubuntu –雨泽博客
Viewing all articles
Browse latest Browse all 9

nginx报错accept() failed (24: Too many open files)

$
0
0

查看了一下nginx的error.log日志文件,发现有很多像下面这样的报错:

accept() failed (24: Too many open files)

一看就知道系统对打开文件数目做了限制,用下面命令

ulimit -n    查看当前用户的

命令查看了一下,结果显示文件打开数目限制为1024,我们需要让这个数字更大一些,好让我们的网站访问并发更高一些。

下面是修改 ulimit 限制数的方法:

1.首先你得修改nginx.conf配置文件,在定义error.log日志路径的位置添加一行

worker_rlimit_nofile 65535;

2.在/etc/profile文件最后面添加下面内容

ulimit -n 65535

3.在/etc/security/limits.conf文件最后面添加下面内容

* soft nofile 65535

* hard nofile 65535

*代表所有用户,如果想代表某个用户的话,则user soft nofile 65535

soft代表软连接   hard代表硬限制

查看软限制数量  ulimit -Sn

查看硬限制数量  ulimit -Hn

4.要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中

在/etc/pam.d/login 文件最后面添加下面内容

session required /lib/security/pam_limits.so

或者也可以在/etc/profile后面加上ulimit -n 65535

完成上面操作后,再用在退出当前会话,重新登录ulimit -n 查看文件限制数已经被修改为65535了。我再试了一下打开网站,速度快起来了,已经恢复正常了。观察了几分钟,发现nginx日志也没有此类报错信息了。


Viewing all articles
Browse latest Browse all 9

Trending Articles