How to Fix the ‘Too Many Open Files’ Error in Linux?

Very typically ‘too many open recordsdata’ errors happen on high-load Linux servers. It signifies that a course of has opened too many recordsdata (file descriptors) and can’t open new ones. In Linux, the most open file limits are set by default for every course of or person and the values are quite small.

In this text we’ll learn the way to verify the present restrict on the most variety of open recordsdata in Linux and the way to change it for the whole host, particular person service or a present session.

‘Too Many Open Files’ Error & Open File Limits in Linux

First of all, let’s see the place the ‘too many open recordsdata’ error seems. The most frequently it happens on the servers with an put in NGINX/httpd net server or a database server (MySQL//PostgreSQL) when studying a lot of logs. For instance, when an Nginx net server exceeds the open file restrict, you will notice an error:

socket () failed (29: Too many open recordsdata) whereas connecting to upstream

Too many open files error in Linux log files

Using this command, you may get the most variety of file descriptors your system can open:

# cat /proc/sys/fs/file-max

The open file restrict for a present person is 1024. You can verify it as follows:

# ulimit -n

get default open file limit in LInux

There are two restrict varieties: Hard and Soft. A person can change a mushy restrict (nevertheless, the mushy worth can’t exceed the exhausting one). Only a privileged or root person can modify a tough restrict worth.

To show the mushy restrict, run this command:

# ulimit –nS

To show the exhausting restrict worth:

# ulimit -nH

How to Increase the Max Open File Limit in Linux?

To permit all companies open a lot of recordsdata, you’ll be able to change the limits in your Linux OS. To make new settings everlasting and stop their reset after a server or session restart, you should make modifications to /and many others/safety/limits.conf. Add these traces:

* exhausting nofile 97816
* mushy nofile 97816

If you’re utilizing Ubuntu, add this line as nicely:

session required pam_limits.so

This parameter permits to set open recordsdata limits after person authentication.

After making any modifications, reload the terminal and verify the max_open_files worth:

# ulimit -n

97816

Increasing the Open File Descriptor Limit per Service

You can change the restrict of open file descriptors for a particular service, quite than for the whole working system. Let’s take apache for example. Open the service settings utilizing :

# systemctl edit httpd.service

Add the limits you need, e.g.:

[Service]
LimitNOFILE=16000
LimitNOFILESoft=16000

set LimitNOFILE for systemd service

After making the modifications, replace the service configuration and restart it:

# systemctl daemon-reload
# systemctl restart httpd.service

To ensure that if the values have modified, get the service PID:

# systemctl standing httpd.service

For instance, the service PID is 3724:

# cat /proc/3724/limits | grep "Max open recordsdata”

get Max open files per process by PID

hus, you could have modified the values for the most variety of open recordsdata for a particular service.

How to Set Max Open Files Limit for Nginx & Apache?

When altering the restrict on the variety of open recordsdata for an online server, you even have to change the service configuration file. For instance, specify/change the following directive worth in the Nginx configuration file /and many others/nginx/nginx.conf:

worker_rlimit_nofile 16000
When configuring Nginx on a extremely loaded Eight-core server with worker_connections 8192, you want to specify 8192*2*Eight () = 131072 in worker_rlimit_nofile.

Then restart Nginx.

For apache, create a listing:

# mkdir /lib/systemd/system/httpd.service.d/

Then create the limit_nofile.conf file:

# nano /lib/systemd/system/httpd.service.d/limit_nofile.conf

LimitNOFILE set ulimiys for apache and nginx

Add to it:

[Service]
LimitNOFILE=16000

Don’t overlook to restart httpd.

Change the Open File Limit for the Current Session

To change most open file limits in your terminal session, run this command:

# ulimit -n 3000

After closing the terminal and creating a brand new session, the limits will get again to the authentic values specified in /and many others/safety/limits.conf.

To change the basic worth for the system /proc/sys/fs/file-max, change the fs.file-max worth in /and many others/sysctl.conf:

fs.file-max = 100000

And apply it:

# sysctl -p

fs.file-max

In this text we’ve got realized how to clear up the subject when the worth of open file descriptor restrict in Linux is just too small, and mentioned some choices of fixing these limits on the server.

Check Also

How to Use and Repair Windows Recovery Environment (WinRE) on Windows 10?

Windows Recovery Environment (WinRE) is the minimal OS based mostly on Windows Preinstallation Environment (WinPE) …

Leave a Reply

Your email address will not be published. Required fields are marked *