ulimit 解决 Nginx accept() failed (24: Too many open files) 错误
2012-12-20 15:01
393 查看
centos5 中 ulimit -n 默认为1024, 当Nginx连接数超过1024时,error.log中就出现以下错误:
使用 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 格式,文件里面有很详细的注释,比如
星号代表全局, soft为软件,hard为硬件,nofile为这里指可打开文件数。
把以上两行内容加到 limits.conf文件中即可。
另外,要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:
修改完重新登录就可以见到效果,可以通过 ulimit -n 查看。
[alert] 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 格式,文件里面有很详细的注释,比如
* soft nofile 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 查看。
相关文章推荐
- ulimit 解决 Nginx accept() failed (24: Too many open files) 错误
- Python错误提示:[Errno 24] Too many open files的分析与解决
- nginx报错accept() failed (24: Too many open files) 分析解决
- nginx:accept() failed (24: Too many open files)解决方法
- nginx accept() failed (24: Too many open files)
- Nginx: 24: Too Many Open Files 错误和解决方案
- Too many open files 错误解决
- Too many open files 问题的解决--浅谈linux ulimit命令
- nginx:accept() failed (24: Too many open files)
- 运维实战案例之“Too many open files”错误与解决方法
- Linux 下Tomcat运行一段时间报java.net.SocketException: Too many open files的错误问题解决
- Nginx之——nginx:accept() failed (24: Too many open files)
- 在执行ab压力测试时出现socket: Too many open files (24)的解决方法
- 运维实战案例之“Too many open files”错误与解决方法
- nginx报错accept() failed (24: Too many open files)
- 运行ab测试时socket: Too many open files (24)的解决办法
- 浅谈linux ulimit命令(Too many open files 问题的解决)
- nginx socket() failed (24: Too many open files)
- python——ubuntu下[Error 24: too many open files]的解决方法
- 关于mina框架里产生too many open files的错误的解决办法