9
SERVER:/etc # ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 96069
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 96069
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
SERVER:/etc # 

How can I set the limit of the root user from 1024 to something else, PERMANENTLY? How can I set the ulimit globally? Will the changes take effect in the moment?

p.s.: I already googled for it but can't find the file where I can set it permanently:

SERVER:/etc # grep -RiI ulimit * 2>/dev/null | egrep -v ":#|#ulimit"
init.d/boot.multipath:      ulimit -n $MAX_OPEN_FDS
init.d/multipathd:      ulimit -n $MAX_OPEN_FDS
rc.d/boot.multipath:        ulimit -n $MAX_OPEN_FDS
rc.d/multipathd:        ulimit -n $MAX_OPEN_FDS

and..:

SERVER:/etc # grep -RiI 'MAX_OPEN_FDS' * 2>/dev/null
init.d/boot.multipath:MAX_OPEN_FDS=4096
init.d/boot.multipath:  if [ -n "$MAX_OPEN_FDS" ] ; then
init.d/boot.multipath:      ulimit -n $MAX_OPEN_FDS
init.d/multipathd:MAX_OPEN_FDS=4096
init.d/multipathd:  if [ -n "$MAX_OPEN_FDS" ] ; then
init.d/multipathd:      ulimit -n $MAX_OPEN_FDS
rc.d/boot.multipath:MAX_OPEN_FDS=4096
rc.d/boot.multipath:    if [ -n "$MAX_OPEN_FDS" ] ; then
rc.d/boot.multipath:        ulimit -n $MAX_OPEN_FDS
rc.d/multipathd:MAX_OPEN_FDS=4096
rc.d/multipathd:    if [ -n "$MAX_OPEN_FDS" ] ; then
rc.d/multipathd:        ulimit -n $MAX_OPEN_FDS
SERVER:/etc # 
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
gasko peter
  • 5,434
  • 22
  • 83
  • 145

1 Answers1

9

Use pam_limits(8) module and add following two lines to /etc/security/limits.conf:

root hard nofile 8192
root soft nofile 8192

This will increase RLIMIT_NOFILE resource limit (both soft and hard) for root to 8192 upon next login.

Petr Uzel
  • 7,157
  • 4
  • 30
  • 26
  • 1
    I modified it, but it seems no effect when seeing ulimit -a with the root, even after a re-login, how to apply this change to limits.conf without a reboot? :D – gasko peter Nov 23 '12 at 11:07
  • 1
    `ulimit -n 8192` will set the limit immediately for the current shell and all its child processes. – Petr Uzel Nov 23 '12 at 13:11
  • I'M accepting.. but afaik the machine will needs a reboot :) - until then .bash_profile.. ulimit -n 8192 – gasko peter Nov 26 '12 at 18:20
  • The file `/etc/security/limits.conf` is only half of the truth: The file is read by `pam_limits.so`, which, in turn, has to be configured. The manual page says `/etc/pam.d/login` should have a line `session required pam_limits.so`. – U. Windl Feb 27 '19 at 13:04