Set the maximum number of opened files in the Ubuntu 12 ulimit System

Source: Internet
Author: User

I can search a lot on the Internet, but it seems to be useless ..

Basic commands:

Root @ Ubuntu :~ #Ulimit-
Core File size (blocks,-C) 0
Data seg size (Kbytes,-d) Unlimited
Scheduling Priority (-e) 0
File size (blocks,-f) Unlimited
Pending signals (-I) 31498
Max locked memory (Kbytes,-l) 64
Max memory size (Kbytes,-m) Unlimited
Open File (-N) 1024
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) 31498
Virtual Memory (Kbytes,-v) Unlimited
File locks (-x) Unlimited

The red part is to open 1024 files, which is usually too small. You can also useUlimit-nView

How to Set it? The official website is as follows:

Step 1: Configure/etc/security/limits. conf

Append * hard nofile 40960 * Soft nofile 40960 to the end of sudo Vim/etc/security/limits. conf file

4096 you can set the parameters on your own. For the settings of the four parameters, refer to English for a brief introduction:

The first column can be a user or a group. Use the @ group syntax or a wildcard such as * %.

The second column has two values: Hard, hard, soft, and software. Generally, soft is smaller than hard, and hard is the bottom line. The number of soft alarms is exceeded until the hard number.

Column 3, see the list. The number of opened files is nofile.

The fourth column, number, cannot be too large.

#
# Each line describes a limit for a user in the form:
#
# <Domain> <type> <item> <value>
#
# Where:
# <Domain> can be:
#-An user name
#-A group name, with @ group syntax
#-The wildcard *, for default entry
#-The wildcard %, can be also used with % group syntax,
# For maxlogin limit
#-Note: group and wildcard limits are not applied to root.
# To apply a limit to the root user, <domain> must be
# The literal username root.
#
# <Type> can have the two values:
#-"Soft" for enforcing the Soft Limits
#-"Hard" for enforcing Hard Limits
#
# <Item> can be one of the following:
#-Core-limits the core file size (KB)
#-Data-max data size (KB)
#-Fsize-maximum filesize (KB)
#-Memlock-Max locked-in-memory address space (KB)
#-Nofile-Max number of open files
#-RSS-Max resident set size (KB)
#-Stack-Max stack size (KB)
#-CPU-Max CPU time (min)
#-Nproc-Max number of processes
#-As-address space limit (KB)
#-Maxlogins-Max number of logins for this user
#-Maxsyslogins-Max number of logins on the System
#-Priority-the priority to run user process
#-Locks-Max number of file locks the user can hold
#-Sigpending-Max number of pending Signals
#-Msgqueue-Max memory used by POSIX message queues (bytes)
#-Nice-Max nice priority allowed to raise to values: [-20, 19]
#-Rtprio-Max realtime priority
#-Chroot-change root to directory (Debian-specific)
#
# <Domain> <type> <item> <value>
#

# * Soft Core 0
# Root hard core 100000

Step 2:/etc/PAM. d/SU (official) or/etc/PAM. d/common-session (network)

Sudo Vim/etc/PAM. d/su remove the comments of pam_limits.so and restart the system.
Sudo Vim/etc/PAM. d/common-session Add the following session required pam_limits.so

Open/etc/PAM. d/Su and find that it contains the/etc/PAM. d/common-session file. Therefore, you can modify any file.

I think it is better to modify the su file. It is OK to cancel the comment and it is not prone to errors. Open and locate the file in Vim, and click X.

The official website only restarts the system in step 2. It does not seem to work in step 3. Does it all work in step 3 ?!

Step 3: Configure/etc/profile

Add the last line

ulimit -SHn 40960

Restart, verify ulimit-N, and check that 40960 is OK.

Updated: 2012/9/29:

On centos 6.3, you only need to modify/etc/security/limits. conf and log on again.

On Ubuntu server 12.04.1, modify/etc/security/limits. conf. Try again and restart. Change/etc/PAM. d/common-session, Su, re-login and restart are not required. Do you have to change/etc/profile?

Is there a difference between the two? Or is my test not in place?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.