How Do I Handle the "Too many open files" Error in ECS Logs?
Symptom
The error message "Too many open files" is displayed in the logs of a Linux ECS.

Possible Causes
"Too many open files" indicates that the number of file handles opened by a program exceeds the limit of a certain resource. Generally, the resource limit includes two dimensions: the overall system limit and the individual user limit. When this problem occurs, you need to determine the limit dimension and then adjust the limit parameter.
Method 1: System-wide Settings
- Log in to the server as the root user.
- Run the following commands to check the number of currently opened files and the maximum number of opened files allowed in the OS (366954 by default in some versions):
cat /proc/sys/fs/file-nr
cat /proc/sys/fs/file-max
The first column in the command output indicates the number of currently opened files in the system.

- Change the maximum number of opened files allowed in the system.
- Press i to enter insert mode.
- Add the following content to the end of the file. You can change the value as required.
fs.file-max = 495000
- Press Esc to exit and enter :wq! to save the configuration.
- Run the following command to apply the change:
Method 2: User-Level Settings
- Log in to the server as the root user.
- Run the following command to check the maximum number of files that can be opened:
- Run the following command to increase the limit:
The parameter value changed using this method is valid only during the current running and will be restored to the default value after the system is restarted. This method is generally used for temporary verification. To apply the change permanently, perform steps 4 to 8.
- Edit /etc/security/limits.conf to increase the maximum number of files that can be opened.
vim /etc/security/limits.conf
- Press i to enter insert mode.
- Add the content below to the end of the file. 655350 is used as an example. You can change the value as required.
- For specific users only:
user - nofile 655350
- For all users:
* - nofile 655350
- For specific users only:
- Press Esc to exit and enter :wq! to save the configuration.
- Restart the server to apply the change permanently:
In a Linux ECS, the system first reads /etc/security/limits.conf and then reads /etc/security/limits.d/*.conf for resource limits. Any changes you make in /etc/security/limits.conf may be overwritten by subsequent files. If the modification does not take effect after the restart, see Why Do the Modifications to /etc/security/limits.conf Not Take Effect After the ECS Restarts?.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot