[Centos] permanent ulimit -n on CentOS 3.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



This was what I found on the issue.

Barry
==================================================================================

Issue:
How do I increase the maximum number of open files on my system?

The current setting for maximum number of open files can be viewed with the
command:

ulimit -n

This number indicates the maximum number of files normal users (i.e. non-root)
can have open in a single session. Note that for the root user, ulimit -n will
sometimes output 1024 even after following the procedure to increase the
maximum number of open files. This won't effect root's ability to open large
numbers of files, as only normal users are bound by this value.

To increase the maximum number of open files beyond the default of 1024, two
changes to the system may be necessary. In these examples, we will increase the
maximum number of open files to the arbitrary value of 2048. All changes need to
be made by the root user and users will need to log out and log back in before
the changes will take effect.

   1. Configure the system to accept the desired value for maximum number of
open files
      Check the value in /proc/sys/fs/file-max to see if it is larger than the
value needed for the maximum number of open files:

      # cat /proc/sys/fs/file-max

      If the value isn't large enough, echo an appropriate number into the
variable and add the change to /etc/sysctl.conf to make it persistent across
reboots. If the number is already larger than the value you wish to use, skip
to step 2.

      # echo 2048 > /proc/sys/fs/file-max

      and edit /etc/sysctl.conf to include the line:

      fs.file-max = 2048

   2. Set the value for maximum number of open files
      In the file /etc/security/limits.conf, below the commented line that reads

#<domain>      <type>  <item>         <value>

      add this line:

      * - nofile 2048

      This line sets the default number of open file descriptors for every user
on the system to 2048. Note that the "nofile" item has two possible limit
values under the <type> header: hard and soft. Both types of limits must be set
before the change in the maximum number of open files will take effect. By using
the "-" character, both hard and soft limits are set simultaneously.

      The hard limit represents the maximum value a soft limit may have and the
soft limit represents the limit being actively enforced on the system at that
time. Hard limits can be lowered by normal users, but not raised and soft
limits cannot be set higher than hard limits. Only root may raise hard limits.

When increasing file limit descriptors, you may want to simply double the value.
For example, if you need to increase the default value of 1024, increase the
value to 2048 first. If you need to increase it again, try 4096, etc.
==================================================================================






Quoting Mike Obvious <mike4mike@xxxxxxxxx>:

> Thanks, Barry.
>
> It helps, but with some questions.
> I did it from console and from ssh logged as root - the same
> #ulimit -Hn
> 1024
>
> But if I do login as a user ( from console or from ssh - the same
> result) - I will have 16384. su - still 16384.
>
> See (ssh session):
>
> [root@NAFNAF root]# ulimit -Hn
> 1024
> [root@NAFNAF root]# su user1
> Password:
> [user1@NAFNAF root]$ ulimit -n
> 16384
> [user1@NAFNAF root]$ ulimit -Hn
> 16384
> [user1@NAFNAF root]$ su root
> Password:
> [root@NAFNAF root]# ulimit -n
> 16384
>
> So, at this point I not sure how many files will have  my application
> running as root.
> I put this:
> echo "ulimit -Hn, -n:" >> /root/ulimit.log
> ulimit -Hn >> /root/ulimit.log
> ulimit -n >> /root/ulimit.log
> at the beginning of the script running my app.
> And it gave me 1024.
> Sure I can say in the same script ulimit -n 16384 and it works.
> Any comments on this?
>
> Mike
>
> On Wed, 23 Feb 2005 21:39:45 -0600, Barry Brimer
> <barry.brimer@xxxxxxxxxxx> wrote:
> > Quoting "C. Linus Hicks" <lhicks@xxxxxxxxx>:
> >
> > > On Wed, 2005-02-23 at 21:50 -0500, Mike Obvious wrote:
> > > > Hi!
> > > >
> > > > Question from the novice.
> > > >
> > > > I have to permanently increase number of opened files ( ulimit -n 16384
> and
> > > > ulimit -Hn 16384) for some application.
> > > > I did custom kernel based on
> > > >
> > > >
> > >
> >
>
https://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/sysadmin-guide/s1-custom-kernel-modularized.html
> > > >
> > > > and application documentation ( written for RH 9), no error during all
> > > makes
> > > > but I have panic during the boot. ( It's Dell SC1425, dual CPU, 2GB
> RAM,
> > > > i686-based kernel).
> > > >
> > > > Is there any other way to do it ?
> > >
> > > Look in /etc/security/limits.conf
> >
> > To keep number of opened files at 16384 do the following
> >
> > Append this to your /etc/security/limits.conf
> > ====================
> > * soft nofiles 16384
> > * soft nofiles 16384
> > ====================
> > Append this to your /etc/sysctl.conf
> > ===================
> > fs.file-max = 16384
> > ===================
> > Type sysctl -p to reread your sysctl.conf file.  This will also syntax
> check
> > your sysctl.conf file for you.
> >
> > Log out, and log back in to complete this task and reread your environment
> with
> > the new settings.
> >
> > Important note: Centos 3.x uses a privelege separated sshd by default.  You
> can
> > disable this functionality if needed in /etc/ssh/sshd_config.  Basically,
> sshd
> > runs as the user connecting to it, instead of root.  Since root is the only
> > user who can change ulimit settings, you will be unable set ulimit settings
> as
> > an unprivelged user in an ssh session.  The way to test this is to make the
> > changes above and log in at the console.  Typing ulimit -n should work
> > correctly.  If you ssh to the server, and type ulimit -n it will show the
> > default (probably 1024).  If you su - user and then type ulimit -n it
> should
> > show the correct number (16384)
> >
> > Hope this helps.
> >
> > Barry
> > _______________________________________________
> > CentOS mailing list
> > CentOS@xxxxxxxxxxx
> > http://lists.caosity.org/mailman/listinfo/centos
> >
> _______________________________________________
> CentOS mailing list
> CentOS@xxxxxxxxxxx
> http://lists.caosity.org/mailman/listinfo/centos
>
> !DSPAM:421d7188228711035992961!
>
>




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux