NGINX保持崩溃,似乎是因为太多打开的文件

正如标题所述,我的Nginx服务器似乎不断崩溃,虽然原因不明。

我的错误日志中有一些提示,可能会导致问题。

我试图增加打开的文件限制,这有一些影响,但没有严重的效果。

2015/09/29 17:18:01 [crit] 20560#0: accept4() failed (24: Too many open files) 2015/09/29 17:18:01 [crit] 20560#0: accept4() failed (24: Too many open files) 

我试图增加限制,但我也看到这在我的错误日志

 2015/09/29 17:18:02 [alert] 20632#0: setrlimit(RLIMIT_NOFILE, 300000000) failed (1: Operation not permitted) 2015/09/29 17:18:02 [alert] 20633#0: setrlimit(RLIMIT_NOFILE, 300000000) failed (1: Operation not permitted) 2015/09/29 17:18:02 [alert] 20560#0: recvmsg() truncated data 

我如何给予权限来增加文件限制?

另外,这是甚至是我的服务器崩溃的原因?

谢谢!

刚刚检查了一些数据,我编辑了我的文件,但由于某种原因,当检查硬限制它说4096?

 root@nalsec:~# sysctl -p net.ipv4.ip_forward = 1 net.ipv6.conf.all.autoconf = 0 net.ipv6.conf.default.autoconf = 0 net.ipv6.conf.eth0.autoconf = 0 net.ipv6.conf.all.accept_ra = 0 net.ipv6.conf.default.accept_ra = 0 net.ipv6.conf.eth0.accept_ra = 0 fs.file-max = 2500000000000000000 root@nalsec:~# ulimit -Hn 4096 

这与我的fs.file-max形成鲜明对比

我试过了,它说我没有权限(我是根)

 root@nalsec:~# ulimit -Hn 1000000000 -bash: ulimit: open files: cannot modify limit: Operation not permitted 

我已经编辑这个文件已经无济于事的nano /etc/security/limits.conf

 #@faculty hard nproc 50 #ftp hard nproc 0 #ftp - chroot /ftp #@student - maxlogins 4 # End of file nginx soft nofile 10240000000000000000000 nginx hard nofile 10240000000000000000000 * hard nofile 10240000000000000000000000 * soft nofile 10240000000000000000000000 root hard nofile 10240000000000000000000000 root soft nofile 10240000000000000000000000 www-data soft nofile 1024000000000000000 www-data hard nofile 1024000000000000000 

fs.file-max是系统上可打开的文件描述符总数的系统范围限制。 它对每个进程的限制没有影响。

要增加单个进程的文件描述符限制,最简单的做法是通过limits.conf来完成:

 # cat /etc/security/limits.d/nofile.conf * soft nofile 10000 * hard nofile 1000000 

这将默认给所有进程10,000个文件描述符,如果需要的话,可以请求升级到1,000,000(通过setrlimit )。