Solution to opening too many files (Toomanyopenfiles) in Linux

Source: Internet
Author: User
Answer one file system allowed to open the maximum number of file handles 1 [root @ lxadminnginx] # cat/proc/sys/fs/file-max28192 each process can open the maximum number of file handles 1 [root @ lxadminnginx] # The ulimit-n21024 can be before starting a process, use [root @... answer 1
 
Maximum number of file handles allowed by the file system
 
1
[Root @ lxadmin nginx] # cat/proc/sys/fs/file-max
2
8192
Maximum number of file handles that a process can open
1
[Root @ lxadmin nginx] # ulimit-n
2
1024
 
You can use [root @ lxadmin nginx] # ulimit-n 8192 to adjust yixia before starting a process
If you need to permanently adjust the number of file handles allowed to be opened by the file system, you can start the file/etc/rc. d/rc. add ulimit-n x at the end of local (not applicable to ubuntu) or in/etc/sysctl. add fs. file-max = xxx
 
Answer 2
 
The Linux kernel sometimes reports "Too open files" because the default value of file-max (such as 8096) is Too small. To solve this problem, run the following command as root:
 
# Echo "65536">/proc/sys/fs/file-max # applicable to 2.2 and 2.4 kernels
# Echo "131072">/proc/sys/fs/inode-max # applicable only to version 2.2 kernel d
 
Or add them to the init script under/etc/rcS. d.
 
Answer 3
 
The method is to modify the limit on the number of files opened by the operating system. The method is as follows:
 
1. add fs. file-max = xxx at the end of/etc/sysctl. conf.
 
2. set the maximum number of file handles that can be opened by each process in the/etc/security/limits. conf file:
 
1
*-Nofile 8192
Or
1
* Hard nofile 8192
2
* Soft nofile 8192
The preceding settings set the default number of files opened by each process to 2048. Note that "nofile" has two soft and hard constraints. These two restrictions must be set for the maximum number of opened files that have been modified to take effect. If the "-" character is used, both hard and soft settings are set. Hard limit indicates the maximum value that can be set in the soft limit. The soft limit is the setting value that takes effect for the current system. The hard limit value can be reduced by common users. But cannot be added. Soft restrictions cannot be set more than hard restrictions. Only root users can increase the hard limit value. When the file limit description is added, you can simply double the current value. The example is as follows. if you want to increase the default value by 1024, it is best to increase it to 2048. if you want to continue to increase it, you need to set it to 4096.
 
Another case is that there are two possibilities when creating an index. One is that the merge factor is too small, resulting in the number of files created exceeds the operating system limit. in this case, you can modify the merge factor, you can also modify the limit on the number of files opened by the operating system. The other is that the merging factor is limited by the memory of the virtual machine and cannot be adjusted to a greater value. The number of doc files to be indexed is very large, in this case, you can only modify the limit on the number of files opened by the operating system.
 
On this basis, I also modified the configuration file/etc/sysctl. conf to optimize TCP sockets, for example:
01
# Decrease the time default value for tcp_fin_timeout connection
02
Net. ipv4.tcp _ fin_timeout = 30
03
# Decrease the time default value for tcp_keepalive_time connection
04
Net. ipv4.tcp _ keepalive_time = 1800
05
# Turn off tcp_window_scaling
06
Net. ipv4.tcp _ window_scaling = 0
07
# Turn off the tcp_sack
08
Net. ipv4.tcp _ sack = 0
09
# Turn off tcp_timestamps
10
Net. ipv4.tcp _ timestamps = 0
Note: A socket connection is also considered as a file
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.