How To Increase Open Files Limit in Linux
Learn in this tutorial how you can increase the number of files you can have open at the same time in Linux.
The limit of open files in Linux distros can be adjusted thanks to the ulimit command, and that is why today this tutorial will analyze in this opportunity how to establish the number of open files in Linux focusing on increasing the default limit.
See the Current File Limit in Ubuntu
The first step we must take is to know exactly what file limit we can open in Linux, in this case, we are using Ubuntu 16.04 Server, and knowing this value we will execute the following command:
The result displayed indicates the number of files that a user can open per login, and this will be variable in each Linux distro.
See the Limits of Hardware & Software in Ubuntu
Another essential aspect to keep in mind is to know the limits of the system both at the hardware and software level, and this is achieved by executing the following commands:
ulimit -Hn ulimit - Sn
Check Default limits on Linux for File Descriptors
When we run specific applications in the servers, it is necessary that they have a higher number of file limits since they are continually registering events or processes that involve a large number of files, we can mention applications such as PHP, MySQL, MariaDB, among others.
In these cases, we can increase the limit by editing the file fs.file-max through the sysctl utility.
To represent this, we will increase the limit of open files to 600,000. For this we will execute the following line as root user:
sudo sysctl -w fs.file-max=600000-w fs.file-max=600000
To verify that the new limit has been established correctly, we will run the following line:
One aspect to keep in mind is that by doing this process the set limit will only be available until the next session start, so if we want this limit to be constant we must access the following file using the preferred editor:
sudo nano /etc/sysctl.conf
In the open file we will add the next line at the end:
We save the changes using the keys Ctrl + O, and we exit the editor using the keys Ctrl + X.
It will be necessary to close the session to apply the changes, and if we want them to be made immediately we will execute the following command:
Set Open-File Limits per user in Ubuntu
We may want to set specific limits of open files for a particular user in a domain, for this we must access the following configuration file:
sudo nano /etc/security/limits.conf/etc/security/limits.conf
In the final part of this we will see the following syntax:
<domain> <type> <item> <value> <type> <item> <value>
There we must add the username the type of element and the limit to assign. We save the changes and leave the editor.
In this way, we have the opportunity to establish or increase the limits to users for open files in various Linux distros and especially in Ubuntu Server 16.04