In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to modify the file handle restrictions of the SUSE LINUX system, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
When deploying applications under SUSE Linux, we sometimes encounter the problem of "Socket/File: Can't open so many files". In fact, this is due to the file handle limitation of the SUSE Linux system. The general system allows 1024 files to be opened by default. As an application server in a production environment, it is easy to reach this default value, so we need to increase this value.
File handle interpretation: in the file Icano, to read data from a file, the application first calls the operating system function and passes the file name, and chooses a path to the file to open the file. This function takes back a sequence number, the file handle (file handle), which is the only identification basis for the open file. To read a piece of data from a file, the application calls the function ReadFile and passes the address of the file handle in memory and the number of bytes to copy to the operating system. When the task is complete, close the file by calling the system function.
Let's see how to modify it:
1. Check the system defaults first
Note that the red line "open files (- n) 1024" shows that the limited number of file handles is 1024, which is too small for the application server in the actual production environment. We need to modify the size of the file handle.
2. Modify the system default file handle limit
# vi / etc/security/limits.conf
If you modify a user's file handle limit, you can add the following two sentences:
Your user name is soft nofile 2048
Your user name is hard nofile 65536
If you modify all users' file handles uniformly, you can add the following two sentences:
* soft nofile 2048
* hard nofile 65536
Notice that wq saves and exits.
We added two kinds of restrictions: soft and hard: the hard limit is the actual limit, and the soft limit is the warnning limit, which only makes warning. After modification, save and restart shell (some systems may need to restart the system, SUSE LINUX is not needed), and then use ulimit-a to check the settings and find that it is successful.
3. Ulimit is actually a restriction on users and a single program. Let's take a look at the total limits of the system:
View the system total limit command:
# cat / proc/sys/fs/file-max
View the number of file handles currently used by the entire system command:
# cat / proc/sys/fs/file-nr
If you want to change the values of file-max and file-nr, you need to edit them through vi / etc/sysctl.conf and use sysctl-p to make them take effect.
1024 is sufficient for general applications (Apache, system processes), but not enough for applications such as squid, mysql, java, where a single process handles a large number of requests. So how do you know how many file handles are open by the current process? We can look at this:
# lsof-n | awk'{print $2}'| sort | uniq-c | sort-nr | more
The left column is the number of open file handles, and the second column is the process ID number. If the system concurrency is particularly large, the number of file handles is likely to exceed 1024, so we have to adjust the system parameters to adapt to the changes of practical application.
Add:
See which handles are opened by a process:
# lsof-p pid
See how many handles have been opened by a process:
# lsof-p pid | wc-l
See what process a file / directory is occupied by, and display all the process information that has been opened for that directory or file:
# lsof path/filename
The above content is how to modify the file handle restrictions of the SUSE LINUX system. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.