ulimit 解决 Nginx accept() failed (24: Too many open files) 错误
centos5 中ulimit-n 默认为1024, 当Nginx连接数超过1024时,error.log中就出现以下错误:12766#0: accept() failed (24: Too many open files)
使用 ulimit -n 65535 可以把打开文件数设置足够大, 同时修改nginx.conf , 添加 worker_rlimit_nofile 65535; (与error_log同级别)
这样就可以解决Nginx连接过多的问题,Nginx就可以支持高并发。
另外, ulimit -n 还会影响到mysql 的并发连接数。把他提高,也就提高了mysql并发。
注意: 用ulimit -n 65535 修改只对当前的shell有效,退出后失效。
修改方法
若要令修改ulimits的数值永久生效,则必须修改配置文档,可以给ulimit修改命令放入/etc/profile里面,这个方法实在是不方便,
还有一个方法是修改/etc/sysctl.conf . /etc/security/limits.conf 格式,文件里面有很详细的注释,比如
* softnofile 65535
* hard nofile 65535
星号代表全局, soft为软件,hard为硬件,nofile为这里指可打开文件数。
把以上两行内容加到 limits.conf文件中即可。
另外,要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:
session required /lib/security/pam_limits.so
修改完重新登录就可以见到效果,可以通过 ulimit -n 查看。
页:
[1]