Help Center/ Elastic Cloud Server/ Troubleshooting/ Linux ECS Issues/ How Do I Handle the "Too many open files" Error in ECS Logs?
Updated on 2026-07-07 GMT+08:00

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

  1. Log in to the server as the root user.
  2. 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.

  3. Change the maximum number of opened files allowed in the system.

    vim /etc/sysctl.conf

  4. Press i to enter insert mode.
  5. Add the following content to the end of the file. You can change the value as required.
    fs.file-max = 495000
  6. Press Esc to exit and enter :wq! to save the configuration.
  7. Run the following command to apply the change:

    sysctl -p

Method 2: User-Level Settings

  1. Log in to the server as the root user.
  2. Run the following command to check the maximum number of files that can be opened:

    ulimit -n

  3. Run the following command to increase the limit:

    ulimit -n <new_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.

  4. Edit /etc/security/limits.conf to increase the maximum number of files that can be opened.

    vim /etc/security/limits.conf

  5. Press i to enter insert mode.
  6. 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
  7. Press Esc to exit and enter :wq! to save the configuration.
  8. Restart the server to apply the change permanently:

    reboot

    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?.