In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to solve the problem of opening too many files in Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Answer 1.
[root@lxadmin nginx] # cat / proc/sys/fs/file-max
8192
Maximum number of files that can be opened in the file system
[root@lxadmin nginx] # ulimit-n
1024
The program is limited to 1024 files.
Use [root@lxadmin nginx] # ulimit-n 8192 to adjust
Or permanently adjust the number of open files can be added at the end of the startup file / etc/rc.d/rc.local (adding fs.file-max=xxx at the end of / etc/sysctl.conf is not valid)
Ulimit-n 8192
Answer 2.
The Linux kernel sometimes reports "Too many open files" because the file-max default value (8096) is too small. To solve this problem, you can execute the following commands as root (or add them to the init script under / etc/rcS.d/*. )
# echo "65536" > / proc/sys/fs/file-max # for version 2.2 and 2.4 kernels
# echo "131072" > / proc/sys/fs/inode-max # is only applicable to version 2.2 kernel
Answer 3.
The way to do this is to modify the operating system's limit on the number of open files as follows:
1. Set up the system according to the requirements for the maximum number of open files, and check the / proc/sys/fs/file-max file to make sure that the maximum number of open files has been set correctly.
# cat / proc/sys/fs/file-max
If the setting is too small, modify the variable in the file / etc/sysctl.conf to the appropriate value. This will take effect after each restart. If the setting is large enough, skip the next step.
# echo 2048 > / proc/sys/fs/file-max
Edit the file / etc/sysctl.conf and insert the following line.
Fs.file-max = 8192
two。 To set the maximum number of open files in the / etc/security/limits.conf file, here is a prompt:
#
Add the following line.
*-nofile 8192
This line sets the default number of open files per user to 2048. Note that there are two possible restrictions for the "nofile" item. Are hard and soft under this item. For the maximum number of open files to take effect, these two limits must be set. If you use the "-" character setting, the hard and soft settings are set at the same time.
The hard limit indicates the maximum value that can be set in the soft limit. The soft limit refers to the setting for which the current system is in effect. The hard limit can be lowered by ordinary users. But it cannot be increased. The soft limit cannot be higher than the hard limit. Only root users can increase the hard limit.
When adding a file limit description, you can simply double the current value. As an example, if you want to increase the default value of 1024, you'd better increase it to 2048, and if you want to continue to increase it, you need to set it to 4096.
Another situation 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 exceeding the operating system limit, and the merge factor can be modified. You can also modify the operating system limit on the number of open files. The other is that the merging factor cannot be adjusted to a larger size due to the limitation of virtual machine memory, and the number of doc that needs to be indexed is very large, so it can only be solved by modifying the open file limit of the operating system.
On this basis, I also modified the following configuration file
Vi / etc/sysctl.conf
Add:
# Decrease the time default value for tcp_fin_timeout connection
Net.ipv4.tcp_fin_timeout = 30
# Decrease the time default value for tcp_keepalive_time connection
Net.ipv4.tcp_keepalive_time = 1800
# Turn off tcp_window_scaling
Net.ipv4.tcp_window_scaling = 0
# Turn off the tcp_sack
Net.ipv4.tcp_sack = 0
# Turn off tcp_timestamps
Net.ipv4.tcp_timestamps = 0
Then service network restart, these are all TCP sockets-related optimizations.
In addition, you need to add it to / etc/rc.d/rc.local to make it take effect when you restart.
Echo "30" > / proc/sys/net/ipv4/tcp_fin_timeout
Echo "1800" > / proc/sys/net/ipv4/tcp_keepalive_time
Echo "0" > / proc/sys/net/ipv4/tcp_window_scaling
Echo "0" > / proc/sys/net/ipv4/tcp_sack
Echo "0" > / proc/sys/net/ipv4/tcp_timestamps
Because not all programs run under root, all linux have a distinction between hard and soft open files. Ordinary users are limited by hard. No matter how high the value of ulimit-n $is, they cannot run to the value of nofile in / etc/security/limits.conf.
After this optimization, lsof-p $java_pid | wc-l can run to more than 4, 000 without throwing too many open files.
That's all for the content of "how to solve the problem of opening too many files in Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.