Lately I’ve been working on deploying and stress testing web applications. I came across a known problem: too many opened files. This post is a simple guide on how to change the maximum opened files (file descriptor) on your Debian like distribution.
There are two different limits. One is the maximum opened files the kernel can use and the other one is per-process.
$ cat /proc/sys/fs/file-max
379126
$ ulimit -a | grep "open files"
open files (-n) 1024
Now configure a new value for the maximum of opened files.
1. Add the following line to /etc/sysctl.conf to change the kernel maximum opened files. (I’m not going to change the value)
fs.file-max = 379126
2. Edit /etc/security/limits.conf and add the following lines:
* soft nofile 65000
* hard nofile 65000
3. Edit /etc/pam.d/common-session and add the following line:
session required pam_limits.so
4. Edit /etc/ssh/sshd_config and add the following line:
UseLogin yes
5. Reboot.