服务器是 Ubuntu 13.04(GNU/Linux 3.9.3-x86_64-linode33 x86_64)。
nginx 是 nginx/1.2.6。
我已经为此工作了几个小时,所以这就是我得到的以及我所做的。
tail -f /usr/local/nginx/logs/error.log
2013/06/18 21:35:03 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:04 [crit] 3427#0: accept4() failed (24: Too many open files)
2013/06/18 21:35:05 [crit] 3426#0: accept4() failed (24: Too many open files)
Nginx 运行:
geuis@localhost:~$ ps aux | grep nginx
root 3422 0.0 0.0 39292 380 ? Ss 21:30 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 3423 3.7 18.8 238128 190848 ? S 21:30 0:13 nginx: worker process
nobody 3424 3.8 19.0 236972 192336 ? S 21:30 0:13 nginx: worker process
nobody 3426 3.6 19.0 235492 192192 ? S 21:30 0:13 nginx: worker process
nobody 3427 3.7 19.0 236228 192432 ? S 21:30 0:13 nginx: worker process
nobody 3428 0.0 0.0 39444 468 ? S 21:30 0:00 nginx: cache manager process
修改 /etc/security/limits.conf 中的软/硬限制(从文件末尾设置)
root soft nofile 65536
root hard nofile 65536
www-data soft nofile 65536
www-data hard nofile 65536
nobody soft nofile 65536
nobody hard nofile 65536
读取最大文件
cat /proc/sys/fs/file-max
500000
在 /etc/pam.d/common-session 中:
session required pam_limits.so
添加此项并重新启动服务器后,对于 nginx,我通过获取父进程的 PID 来计算软/硬限制:
cat /proc/<PID>/limits
Limit Soft Limit Hard Limit Units
Max open files 1024 4096 files
父进程以“root”身份运行,4 个工作进程以“nobody”身份运行。
root 2765 0.0 0.0 39292 388 ? Ss 00:03 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 2766 3.3 17.8 235336 180564 ? S 00:03 0:21 nginx: worker process
nobody 2767 3.3 17.9 235432 181776 ? S 00:03 0:21 nginx: worker process
nobody 2769 3.4 17.9 236096 181524 ? S 00:03 0:21 nginx: worker process
nobody 2770 3.3 18.3 235288 185456 ? S 00:03 0:21 nginx: worker process
nobody 2771 0.0 0.0 39444 684 ? S 00:03 0:00 nginx: cache manager process
我已经尝试了所有我知道的方法,并且能够从 Google 获得。我不能增加 nginx 的文件限制。
帮助?
答案1
将以下行添加到你的 nginx 并重新启动该进程:
worker_rlimit_nofile 30000;
这将允许工作人员处理更多文件。然后您可以使用以下方法进行验证:
su - nobody
ulimit -Hn
ulimit -Sn
这应该输出新的硬/软限制。
答案2
在 Ubuntu 中,编辑 /etc/pam.d/su 添加或取消注释 session required pam_limits.so
另外,在 /etc/security/limits.conf 中确保字符之间有 TABS 而不是空格。
答案3
确保在编辑这些文件后运行以下命令
sysctl -p
然后重启nginx