Too many open files (CentOS7) - already tried setting higher limits
It is not actually open file handles that have run out, but inotify watches.
You can see this in the error message:
Sep 13 05:32:22 pars.work systemd[1]: Failed to set a watch for nginx.service's PID file /var/run/nginx.pid: Too many open files
To solve the problem, you need to raise the number of inotify watches the system has available. If you actually check, you will find it has some ridiculously low value like 8192.
$ sysctl fs.inotify.max_user_watches
fs.inotify.max_user_watches = 8192
You can set the sysctl fs.inotify.max_user_watches
to a higher value persistently by editing /etc/sysctl.conf
or creating a file in the /etc/sysctl.d
directory. For example, my system has:
$ cat /etc/sysctl.d/10-user-watches.conf
fs.inotify.max_user_watches = 1048576
And then load it with sysctl -p
.
You may not want to go straight to that number and cause the kernel to allocate memory to track a million user file watch slots; instead, just take the current value and double it until the problem stops occurring.