Unfortunately this is still in a state of trial and error. What I can describe are the steps that I took to get it work and the steps that I took to validate it works:
Source articles for this article:
- https://medium.com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a
- https://superuser.com/questions/1200539/cannot-increase-open-file-limit-past-4096-ubuntu/1200818#1200818
First off... There are multiple levels where you can specify the maximum nr of open files:
- Based on user
- Soft limit / hard limit
- Based on process
As the user:
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 509342
max locked memory (kbytes, -l) 16384
max memory size (kbytes, -m) unlimited
open files (-n) 65536 # <-----------
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) 509342
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
And based on the process:
ps | grep kabisa # and take the correct PID
cat /proc/<pid>/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 509342 509342 processes
Max open files 65535 65535 files # <----------------
Max locked memory 16777216 16777216 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 509342 509342 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
As long as this doesn't give a high enough number it's not going to work
Several ways to set the max open files. I don't know which one is not necessary. I know at least of 1 that is necessary.
sudo vim /etc/sysctl.conf
Add the following line to it
fs.file-max = 65535
And then run
sudo sysctl -p
sudo vim /etc/security/limits.conf
Add the following lines to it
* soft nofile 65536
* hard nofile 65536
kabisa soft nofile 65536
kabisa hard nofile 65536
root soft nofile 65536
root hard nofile 65536
sudo vim /etc/pam.d/common-session
Add the following line
session required pam_limits.so
sudo vim /etc/systemd/user.conf
Add the following line
DefaultLimitNOFILE=65535
Without this one it didn't work!
sudo vim /etc/systemd/system.conf
Add the following line
DefaultLimitNOFILE=65535
Now reboot and check the proc filesystem for the process limits