ulimit resolves Nginx accept () failed (24:too many open files) error

Source: Internet
Author: User

The ulimit-n in centos5.3 is 1024, and when the number of nginx connections exceeds 1024, the following error occurs 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, while modifying nginx.conf, add Worker_rlimit_nofile 655350; (same level as Error_log)

This solves the problem of too many nginx connections, and nginx can support high concurrency.

In addition, Ulimit-n will also affect the number of concurrent connections to MySQL. Raise him up, also improve the MySQL concurrency.

Note: The ulimit-n 2048 modification is only valid for the current shell and expires after exiting.

Modify Method


To make the value of a modified ulimits permanent, you must modify the configuration document, and you can put the Ulimit modification command into/etc/profile, which is inconvenient.

Another way is to modify the/etc/sysctl.conf.

/etc/security/limits.conf format, there are very detailed comments in the file, such as

* Soft Nofile 655360
* Hard Nofile 655360

The asterisk represents the global, soft for software, hard for hardware, nofile for <type> This refers to the number of open files.

Add the above two lines of content to the limits.conf file.

In addition, to make the limits.conf file configuration effective , you must ensure that the pam_limits.so file is added to the startup file. See the/etc/pam.d/login file for:
Session required/lib/security/pam_limits.so

You can see the effect after you have modified the login, you can see it through ulimit-n.

Reference:

http://gfllove.blog.163.com/blog/static/1515027200923010653628/

http://loamy.javaeye.com/blog/380150

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.