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 > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to modify the limit on the number of open 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!
System environment
Centos7
Why limit the number of open files?
Because the operating system needs memory to manage each file, the number of files that can be opened may be limited. Because the program can also close the file handler, it can create files of any size until all available disk space is full. In this case, one aspect of security is to prevent resource exhaustion by imposing restrictions.
You can see the maximum number of open file descriptors on the Linux system, as follows:
[root@localhost ~] # cat / proc/sys/fs/file-max180965
This value shows the number of files the user can open per login session, and you will notice that the results may vary from system to system. For some reason, you may need to increase the value of the restriction set. This is why the Linux system offers the possibility to modify these limits (increase or decrease) by changing the maximum number of files opened per process and per system.
Method 1: use the ulimit command
The ulimit command can be used to increase the number of files opened in shell. This command is a built-in command on the system, so it only affects bash and programs started from it. The ulimit syntax is as follows:
Ulimit [option] [limit value]
The following options determine what is limited:
-a report showing all current restrictions-f (file restrictions) limits the size of files that shell can create-n limits the number of file descriptors open. -H and-S are set to hard limit and soft limit, respectively. The hard limit may not increase, but the soft limit may increase. If no options are provided, ulimit sets both hard and soft limits.
To view the soft limits of the currently open file, you can use the following command:
[root@localhost ~] # ulimit-a | grep openopen files (- n) 1024 or [root@localhost ~] # ulimit-n1024
If you need to view the hard limits, adapt to the following command:
[root@localhost ~] # ulimit-Hn4096
The following modifies the number of open files:
[root@localhost] # ulimit-n 2048
Then let's take a look:
[root@localhost ~] # ulimit-Hn2048 [root@localhost ~] # ulimit-Sn2048
It is found that when setting the ulimit value, no-H or-S is specified, and both limits are set to the same value.
The problem now is that if you log out or restart your computer, the value will be reset. Remember, to take effect, you need to edit the user's .bashrc or .bash _ profile configuration file, and you can make the parameters take effect by adding the ulimit command line to the end of the file.
[root@localhost ~] # echo "ulimit-n 2048" > > ~ / .bashrc method 2: use PAM module
This limitation is best achieved through a PAM module called pam_limits. You need to configure it by editing the / etc/security/limits.conf file. This file contains four basic fields:
Domain: describes the entities in which restrictions are applied. It can be user, group (group name preceded by @ for group), or match all users, using (*) wildcards. Wildcards are not suitable for root users.
Type: does this mean a hard limit or a soft limit? The hard limit is added by the system administrator and cannot be exceeded under any circumstances, while the user can temporarily exceed the soft limit. You can also use dashes-to indicate that a limit is hard and soft. Note that the soft limit can be increased to the hard limit
Type: it specifies the type of restricted entry. It can be core (limit core file size (KB)), data (maximum big data size (KB)), fsize (maximum file size (KB)), nofile (maximum number of open file descriptors), nproc (maximum number of processes), and so on. More types can be viewed using man limits.conf.
Type: fill in the value of the application limit here.
The following examples can be compared.
[root@localhost] # tail-12 / etc/security/limits.conf# * soft core 0mm * hard rss 10000#@student hard nproc 20#@faculty soft nproc 20#@faculty hard nproc 50#ftp hard Nproc 0#@student-maxlogins slave End of file
To edit the maximum number of files opened by all users, add the following line at the end of the file:
[root@localhost ~] # vim / etc/security/limits.conf* hard nofile 20000 * soft nofile 15000
After that, you need to edit the file / etc/pam.d/login configuration file, adding the following at the end:
[root@localhost ~] # vim / etc/pam.d/loginsession required pam_limits.so
Save the file. Then log out or restart the system. You can see that the values of both soft and hard limits have been modified successfully:
[root@localhost] # ulimit-Sn15000 [root@localhost ~] # ulimit-Hn20000 method III
View the maximum number of open file descriptors on the system:
[root@localhost ~] # cat / proc/sys/fs/file-max180965
Temporarily set this value:
[root@localhost ~] # echo "1000000" > / proc/sys/fs/file-max
Permanent setting, you need to set it in / etc/sysctl.conf and let it take effect:
[root@localhost ~] # echo "fs.file-max = 1000000" > > / etc/sysctl.conf [root@localhost ~] # sysctl-pfs.file-max = 1000000 "how to modify the limit on the number of open 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.