[Reprint]linux Modify open files number

Source: Internet
Author: User

Overview:
Linux system default open files number is 1024, sometimes the application will report too many open files error, because the number of open files is not enough. This requires modifying Ulimit and File-max. In particular, to provide a large number of static file access to the Web server, cache servers (such as squid), pay more attention to this problem.
the tutorials on the web are simply instructions on how to set up Ulimit and File-max, but the relationship between the two is different and not carefully explained.

Description:
1. The meaning of File-max. Man proc, can get the description of File-max:
/proc/sys/fs/file-max
This file defines a system-wide limit on the number of open files for all processes. ( See
also Setrlimit (2), which can is 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 messages
About running out of the file handles, try increasing this value:
that is, File-max is the number of files that can be opened by all processes in the system. At the same time, some programs can set limits for each process through Setrlimit calls. If you get a large number of error messages using the file handle, you should increase this value.
In other words, this parameter is system-level.

2. Ulimit
provides control over the resources available to the shell and to processes started by it, in systems that allow such Control.
that is, the resource limit for the current shell and the process that it initiates is set.
obviously, for the server, File-max, ulimit all need to be set, otherwise the file descriptor is exhausted

Modify:
1. Modify File-max

# echo  6553560 >/proc/sys/fs/file-max  //sysctl-w "fs.file-max=34166", the front 2 restart the machine will revert to the default value  or # vim /etc/sysctl.conf, add the following to restart the active FS.  File-=6553560       


2. Modify the Ulimit open file, the system default Ulimit on the number of file opening limit is 1024

# ULIMIT-HSN 102400//This is only valid at the current terminal, and after exiting, open files becomes the default value. You can also write to/etc/profile because each time you log in to the terminal, the/etc/profile# vim/etc/security/limits.conf//Add the following configuration, reboot is effective *  soft nofile 65535 * hard Nofile 65535            


Appendix:
Appendix 1.
In order to enlarge the number of open files for a program, you can precede the startup script with the ULIMIT-HSN 102400 command. But when the program is a daemon, this method may not work because there is no terminal.

Appendix 2.
If a service has been started, then dynamically adjusting the ulimit is not valid, especially when it comes to online business is more troublesome.
At this point, you can consider modifying the/proc/' program PID '/limits to achieve dynamic modification!!!

[Reprint]linux Modify open files number

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.