Error “Too many files open” on CentOS

You may encounter “Too many open files” error during login, and the session is instantly canceled. This error happens when a user or system has more open files than the default setting allows.

Use the following command to see how many files can be open at the OS level.

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

This value shows how many files each process running on the system can open at once. By default, this number will change on its own based on how much RAM the system has. As a rough rule of thumb, there will be about 100,000 files per gigabyte (GB) of RAM. This means that there will be about 400, 000 files on a 4GB machine and 16,000,000 files on a 16GB machine. To change the maximum number of open files for the whole system, edit the file /etc/sysctl.conf as root and add the following to the end.

 fs.file-max = 495000

Then, to activate this change on the live system, give the following command.

 # sysctl -p

Issue the following commands as root to see a user’s maximum open file setting.

 # su - <user>
$ ulimit -n

Issue the following commands as root to see the setting for a user’s maximum open files. This is normally set to 1024 by default. If more is required for a certain user, edit the /etc/security/limits.conf file as root.

 user - nofile 2048

This will set the maximum open files for the specific “user” to 2048 files.

The limits module, which sets these settings, reads /etc/security/limits.conf first, then each file matching /etc/security/limits.d/*.conf. Any modifications you make to /etc/security/limits.conf may be overruled by a later file. To confirm that these files fulfill your criteria, you should review them all together.

To increase system-wide for all users, edit the /etc/security/limits.conf file as root and add the following.

 * - nofile 2048

This increased the maximum number of open files for ALL users to 2048. These changes will take effect after a reboot.

The error may appear on the client side of NFS mounted file systems, but it must be rectified on the NFS server side. An error like this may appear on the client, but for a program using NFS to access files. /apps/jenkins/jobs/TCE_FWS/builds/2013-03-21_04-01-34/archive/release/fws.war (Too many open files)

The remedy is to increase ulimit on the NFS server (we doubled it from the default value in /etc/security/limits.conf).

* - nofile 2048

Leave a Reply