Often we get “org.apache.tomcat.jni.Error: 24: Too many open files” errors on Apache Tomcat. If this happened then the process will wait for 3 minutes in open state and will fail after that. It can be fixed by increasing the Open file limits on OS limits. By default CentOS is set with 1024 limit.
1. Edit the file /etc/security/limits.conf and add the following lines
* soft nofile 8192 * hard nofile 65535
2. Edit the file /etc/pam.d/login and add the following lines
session required /lib/security/pam_limits.so
3. Check the limit again by logoff and login
core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 119859 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 8192 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 119859 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
Here we can see the open files is set to 8192 which should be enough but it is best practice to check the open file with lsof and adjust as per requirements.