The logs record too many open files words, resulting in the failure to open the site, open the service and the solution.
1、What is the file handle?
Baidu encyclopedia.
In file I/O, to read data from a file, the application must first call the operating system function and transmit the file name, and select a path to the file to open the file. The function retrieves a sequential number, the file handle, which is the unique identifier for the opened file. To read a piece of data from a file, the application calls the function ReadFile and transmits the address of the file handle in memory and the number of bytes to be copied to the operating system. When the task is completed, and then by calling the system function to close the file
2、Why does it report too many open files?
By default, the default file handle under Linux is 1024, when the server has high concurrency or a large number of open files, it will report too many open files
Query:
ulimit -n

3、How to solve
Modify the number of files opened by the process
1、Interim solution:
ulimit -n 204800
This method does not need to restart the server, the current environment variables, temporary effect, after restarting the server, invalid
2, permanent solution, you need to modify the /etc/security/limits.conf file
echo "* soft nofile 204800" >> /etc/security/limits.conf
echo "* hard nofile 204800" >> /etc/security/limits.conf
echo "* soft nproc 204800" >> /etc/security/limits.conf
echo "* hard nproc 204800 " >> /etc/security/limits.conf
After modification, you need to restart the server to see if it takes effect
ulimit -n
The above changes the number of file handles opened by a process, but you also need to change the total system limit to make it work. For example, if we set the default number of open file handles per process to 1024, but the system limit is 500, the final number of open file handles for a process is also 500
Modify the system limit
1、Interim solution.
echo 6553560 > /proc/sys/fs/file-max
- Permanent solution, requiring a reboot to take effect.
echo fs.file-max = 6553560 >> /etc/sysctl.conf
To see if it is in effect.
sysctl -p
You need to know what you know, but you also need to know what you know. If you have other suggestions and opinions about this article, please leave a comment.
