The cart is empty

In Linux systems, including CentOS 7 distribution, the file descriptors limit is a crucial parameter that determines how many files can be opened by the system or a user at once. Increasing this limit might be necessary for demanding applications or servers dealing with a large number of files. In this article, we'll discuss how to raise this limit on CentOS 7.

Overview

The system-wide limit for open files descriptors can be set at two basic levels: global (for the entire system) and user-specific (for a particular user). Elevating this limit can help prevent issues related to reaching the maximum number of open files, which could lead to application or system failures.

Global Limit

  1. Adjusting the System Limit - To increase the global limit of open files, edit the /etc/sysctl.conf file and add the following lines:

    fs.file-max = 2097152
    

    This value sets the maximum number of open files to 2097152. You can adjust the value as needed.

  2. Activating Changes - Activate the changes using the command:
    sudo sysctl -p
    ​

 

User Limit

  1. Modifying the Limit for Users For specific users, you can set the limit by editing the /etc/security/limits.conf file. Add the following lines for the username:

    username soft nofile 1024
    username hard nofile 4096
    

    This sets the "soft" limit to 1024 and the "hard" limit to 4096 open files for the username. The "soft" limit can be dynamically changed by applications, while the "hard" limit serves as the maximum upper bound.

  2. Applying Limits When Launching Applications To reflect the new limits, it may be necessary to restart services or newly logged-in users. In some cases, especially with daemons, it's preferable to add the relevant settings directly into the scripts that launch the services.

Using the ulimit Tool

For temporary changes to the limit in the current session, you can use the ulimit command. To increase the soft limit to 2048 open files in the current shell, use:

ulimit -Sn 2048

And for setting the hard limit:

ulimit -Hn 4096

These changes apply only to the current shell and are not permanent.

 

Increasing the open files limit on CentOS 7 may be necessary for the proper functioning of some applications and services. The steps outlined above should provide a clear procedure for setting this limit both at the global and user levels. It's important to keep in mind that excessively high limits may have a negative impact on system resources, so they should be set considering available hardware and system resources.