Symptoms
When restarting a service, sometimes I see "Error: Too many open files".
Description
Each server is provided with a maximum amount of files it can open. Depending on the environment, there are a few things to determine if you're being limited inside, or outside of your server.
Workaround
The first thing we can do is run ulimit to see the current imposed limits.
Show ulimits:
ulimit -a
Show soft limit:
ulimit -Sa
Hard limits:
ulimit -Ha
This will tell us the current values set for the server. If this is an OpenVZ server, you can check beancounter with cat /proc/user_beancounters and here, you'll look for numproc:
# cat /proc/user_beancounters
Version: | 2.5 | |||||
UID | Resource | held | maxheld | barrier | limit | failcnt |
6870096 | kmemsize | 755075224 | 1240723456 | 1951399936 | 2147483648 | 0 |
lockedpages | 0 | 8 | 524288 | 524288 | 0 | |
privvmpages | 677930 | 2904353 | 9223372036854775807 | 9223372036854775807 | 0 | |
shmpage |
1155 | 1622766 | 9223372036854775807 | 9223372036854775807 | 0 | |
dummy | 0 | 0 | 9223372036854775807 | 9223372036854775807 | 0 | |
numproc | 714 | 858 | 9223372036854775807 | 9223372036854775807 | 0 |
If you see the failcnt increase for numproc, you'll want to check the host node or contact your hosting provider.
It's also a good idea to check what the system is saying you can use:
cat /proc/sys/fs/file-max
If that looks good, then also check for any limits in limits.conf.
egrep -v '^#|^$' /etc/security/limits.conf
If there are no limits set in the limits file, and you haven't hit a "failcnt" for "numproc", you can edit the limit by using ulimit. As an example, to change open file limits, you can use ulimit -n
ulimit -n 8192 # set open files limit
If you are running CentOS 7, you can also set limits for systemd services in their respective paths. If the .d path does not exist, no limit is set.
/usr/lib/systemd/system/$service_name.service.d/openfiles.conf
If you need to change other limit values, please refer to the man page for additional details.
Comments
0 comments
Article is closed for comments.