Modify the number of open files in linux and openfiles in linux

Source: Internet
Author: User

Modify the number of open files in linux and openfiles in linux
Summary

In linux, the default number of open files is 1024. Sometimes the application reports the Too program open files error because the number of open files is insufficient. In this case, you need to modify the ulimit and file-max. Especially for web servers that provide access to a large number of static files and cache servers (such as squid), pay attention to this issue.
The online tutorials only briefly describe how to set up ulimit and file-max, but the relationship between them is not carefully described.

Description 1. Meaning of file-max. Man proc, you can get the description of file-max:

/Proc/sys/fs/file-maxThis file defines a system-wide limit on the number of open files for all processes. (Seealso setrlimit (2), which can be used by a process to set the per-process limit, RLIMIT_NOFILE, on the number of files it may open .) if you get lots of error messagesabout running out of file handles, try increasing this value: that is, file-max sets the total number of files that can be opened by all processes in the system. At the same time, some programs can be called through setrlimit to set the limits for each process. This value should be added if you get a large number of error messages about the file handle used. That is to say, this parameter is system-level.

2. ulimit

Provides control over the resources available to the shell and to processes started by it, on systems that allow such control. This sets the resource limits for the current shell and processes started by it. Obviously, file-max and ulimit must be set for the server. Otherwise, the file descriptor may be used up:

1. Modify file-max
# Echo 6553560>/proc/sys/fs/file-max // sysctl-w "fs. file-max = 34166 ", the default value or # vim/etc/sysctl will be restored after the previous two restart machines. conf, add the following content, restart to take effect fs. file-max = 6553560
2. Modify the ulimit open file. The default ulimit limit on the number of opened files is 1024.
# Ulimit-HSn 102400 // This is only valid on the current terminal. After exiting, open files becomes the default value. Of course, you can also write it to/etc/profile, because/etc/profile or # vim/etc/security/limits will be automatically executed every time you log on to the terminal. conf // Add the following configuration and restart it to take effect * soft nofile 65535 * hard nofile 65535

 
Appendix:
Appendix 1.
To increase the number of open files of a program, you can add the ulimit-HSn 102400 command before the startup script. But when the program is a daemon, This method may be invalid because there is no terminal.

Appendix 2.
If a service has been started, dynamic ulimit adjustment is invalid, especially when online services are involved.
In this case, you can modify/proc/'program pid '/limits to achieve dynamic modification !!!

 

Source: http://coolnull.com/2796.html

Related Article

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.