ulimit is used to limit the resources available to each user, such as CPU, memory, handles, etc. The following takes CentOS 6.5 as an example to summarize.
1 View ulimit
Command format:
ulimit [-SHacdefilmnpqrstuvx]
- Parameter
S
: Indicates the soft limit, when the limit value is exceeded, it will alarm - Parameter
H
: Indicates a hard limit, which must not exceed the limit value - Parameters
a
: will list all resource limits like:
- Parameters
c
: When an error occurs in some programs, the system may write the program's information in memory into a file (for debugging), which is called a core file. This is to limit the maximum size of each core file - Parameters
d
: the maximum value of each process data segment - Parameters
f
: the maximum file size that the current shell can create - Parameters
l
: The maximum value of physical memory that can be locked - Parameters
m
: the maximum value of resident memory that can be used - Parameters
n
: the maximum number of file handles each process can open simultaneously - Parameters
p
: the maximum value of the pipe - Parameters
s
: the maximum value of the stack - Parameters
t
: the maximum time each process can use the CPU - Parameters
u
: the maximum number of concurrent processes running per user - Parameters
v
: the maximum virtual memory that the current shell can use
2 Modify ulimit
Command format:
ulimit [-SHcdefilmnpqrstuvx] [limit]
A limit can be adjusted by adding a limit value after the command to be viewed, but it is only valid for the current login shell.
The parameter S
means setting the soft limit; the parameter H
means setting the hard limit; when neither is specified, it means setting both the soft limit and the hard limit to the specified values.
3 Permanently modify ulimit
The so-called permanent means that every time you log in to the shell, it will be reset according to the configuration ulimit
to achieve the effect of permanent effect.
- Step 1: Modify /etc/security/limits.conf
Add the following:
For the configuration of this file, please refer to the following
[root@CentOS646506 ~]# vim /etc/security/limits.conf
* hard nproc 64000
* soft nproc 64000
* hard nofile 64000
* soft nofile 64000
The above content indicates that the soft limit and hard limit of sum will be modified to 64000 at the same time -u
.-n
- Step 2: Modify /etc/pam.d/login
Add the following:
[root@CentOS646506 ~]# vim /etc/pam.d/login
session required pam_limits.so
pam
The above indicates that use management when logging in limit
.
- Step 3: Modify /etc/profile
Add the following
[root@CentOS646506 ~]# vim /etc/profile
ulimit -u 64000
ulimit -n 64000
Each time you log in to the shell, these two ulimit
commands are initially executed and made effective.
- make the configuration take effect
Re-login or use source /etc/profile
takes effect immediately.
source causes the current shell to take effect on the contents of the specified file.
3.1 /etc/security/limits.conf configuration details
Format:
<domain> <type> <item> <value>
domain
means the effective entity- username
- You can also
@group
specify a user group by - Use
*
indicates default value
type
Refers to the type of restrictionsoft
soft limithard
hard limit
item
Limit resourcescore
sameulimit -c
data
sameulimit -d
fsize
sameulimit -f
memloc
sameulimit -l
nofile
sameulimit -n
stack
sameulimit -s
cpu
sameulimit -t
nproc
sameulimit -u
maxlogins
Specify the number of users who can log in at the same timemaxsyslogins
The number of users who can log in to the system at the same timepriority
User process running prioritylocks
The maximum number of files a user can locksigpengding
sameulimit -i
msgqueue
sameulimit -q