在bash中,有个ulimit命令,提供了对shell及该shell启动的进程的可用资源控制。主要包括打开文件描述符数量、用户的最大进程数量、coredump文件的大小等。
在centos 5/6 等版本中,资源限制的配置可以在 /etc/security/limits.conf 设置,针对root/user等各个用户或者*代表所有用户来设置。 当然,/etc/security/limits.d/ 中可以配置,系统是先加载limits.conf然后按照英文字母顺序加载limits.d目录下的配置文件,后加载配置覆盖之前的配置。 一个配置示例如下:
1
2
3
4
5
6
|
*
soft
nofile
100000
hard
nofile
100000
soft
nproc
100000
hard
nproc
100000
soft
core
100000
hard
core
100000
|
1
2
3
|
DefaultLimitCORE
=
infinity
DefaultLimitNOFILE
=
100000
DefaultLimitNPROC
100000
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
$cat
/
proc
/
$
(
cat
/
var
run
.pid
)
/
limits
Limit
Soft
Hard
Units
Max
file
size
bytes
data
bytes
stack
size
8388608
bytes
core
size
bytes
resident
set
bytes
Max
processes
100000
processes
open
files
files
locked
memory
65536
bytes
address
space
bytes
locks
locks
pending
signals
1030606
signals
msgqueue
size
819200
bytes
nice
priority
0
0
realtime
priority
0
realtime
timeout
unlimited
us
|