一个和worker_connections参数相关的Nginx系统问题及解决办法

来源:互联网 发布:linux本地socket 编辑:程序博客网 时间:2024/05/19 17:27
1. 问题现象 
nginx运行过程中,发现无法访问nginx(导致nagios监控告警) ,且error日志中一直报如下错误 

2011/05/10 16:31:07 [alert] 24082#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:07 [alert] 24082#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:07 [alert] 24085#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:07 [alert] 24082#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:07 [alert] 24085#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:08 [alert] 24082#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:08 [alert] 24082#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:08 [alert] 24085#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 
2011/05/10 16:31:08 [alert] 24082#0: 1024 worker_connections is not enough while accepting new connection on 0.0.0.0:81 

2.初步原因分析 
目前nginx 中worker_connections 值设置是1024,worker_processes 值设置是4,按反向代理模式下最大连接数的理论计算公式: 
最大连接数 = worker_processes * worker_connections/4 
算出目前每台nginx理论上只支持1024个。但观察NGINX 历史性能数据,发现活动连接数经常是大于1024,并且最高达到5000左右,因而有时会导致连接数不够,直到NGINX无法再处理新的连接请求。 
3.解决办法 
查看相关资料,生产环境中worker_connections 建议值最好超过9000,计划将一台nginx 设置为10240,再观察一段时间。