– Properly configure Linux to open file handle limits and lsof command usage
Today I saw a system error report from the performance test group, the application under the Linux system under pressure will appear "Too Many open files" error and cause the service to stop.
This is the old problem, that is, the need to properly configure Linux can also open the file handle number limit.
Of course, if the application has bugs, misuse of resources is another issue.
Linux most of the resources will be virtual files, as open Network connections will occupy the file handle, Linux default limit is generally 1024, this restriction on the general personal use is not a problem, but for a special application or both in the large concurrent access is not enough.
User level:
Linux limits the number of connected files per logged-on user. You can view the currently valid settings by Ulimit-n. If you want to modify this value, use the Ulimit-n command.
For the increase in the file descriptor, the data recommendation is referred to as a power of 2. If the current file descriptor number is 1024, it can be increased to 2048, if not enough, to 4096, and so on.
System level:
System-level settings are valid for all users. There are two ways to view the maximum file limit of a system
1 Cat/proc/sys/fs/file-max
2 sysctl-a View Results Fs.file-max the number of configurations in this item
If you need to increase the number of configurations, modify the/etc/sysctl.conf file, configure the Fs.file-max property, and add if the property does not exist.
Use Sysctl-p when configuration is complete to notify the system to enable this configuration
1 Cat/proc/sys/fs/file-max
2 sysctl-a
View the number of Fs.file-max this item in the results
If you need to increase the number of configurations, modify the/etc/sysctl.conf file, configure the Fs.file-max property, and add if the property does not exist.
Use Sysctl-p when configuration is complete to notify the system to enable this configuration
If you want to see the specific use of a file handle, you can use the lsof command to give a few examples:
1. View the files that a process (PID) is using
Lsof-p PID
2. Find out who is using a file
Lsof/var/run/sendmail.pid
3. Find the process of listening on port 25
Lsof-i: 25
Oh, the function is still very powerful.