Please indicate the source for reprinting: http://blog.csdn.net/l1028386804/article/details/51425325
There is a server with very high traffic, using nginx, error log The following error keeps reporting:
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2016/05/16 08 :53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files) )
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2016/05/16 08:53:49 [alert] 13576 #0: accept() failed (24: Too many open files)
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2016/05/16 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
Solution:
ulimit in centos5.3 - n is 1024. When the number of Nginx connections exceeds 1024, the following error appears in error.log:
[alert] 12766#0: accept() failed (24: Too many open files)
Use ulimit -n 655350 to set the number of open files large enough, modify nginx.conf at the same time, add worker_rlimit_nofile 655350; (same level as error_log)
This can solve the problem of too many Nginx connections, Nginx It can support high concurrency. <Also modify nginx>
In addition, ulimit -n will also affect the number of concurrent connections of mysql. Improving it will also increase mysql concurrency.
Note: The modification with ulimit -n 2048 is only effective for the current shell and will become invalid after exiting.
Modification method
If you want to modify the value of ulimits permanently, you must modify the configuration document. You can put the ulimit modification command into /etc/profile. This method is really inconvenient.
Another method is to modify the format of /etc/security/limits.conf
/etc/security/limits.conf. There are very detailed comments in the file. For example,
* soft nofile 655360
* hard nofile 655360
The asterisk represents the global situation, soft is software, and hard is Hardware, nofile here refers to the number of open files.
Add the above two lines to the limits.conf file.
In addition, for the limits.conf file configuration to take effect, you must ensure that the pam_limits.so file is added to the startup file. Check the /etc/pam.d/login file and find:
session required /lib/security/pam_limits.so
You can see the effect by logging in again after making the modification. , can be viewed through ulimit -n.
The above introduces Nginx - nginx: accept failed 24: Too many open files, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.