Chinaunix首页 | 论坛 | 博客
  • 博客访问: 867621
  • 博文数量: 179
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1546
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-27 11:05
个人简介

MySQL工程师 QQ:1815357042

文章分类

全部博文(179)

文章存档

2015年(179)

分类: LINUX

2015-09-02 23:05:26

ulimit命令参数及用法
 
功能说明:控制shell程序的资源。 
补充说明:ulimit为shell内建指令,可用来控制shell执行程序的资源。 
参  数: 
-a   显示目前资源限制的设定。 
-c   设定core文件的最大值,单位为区块。 
-d    <数据节区大小> 程序数据节区的最大值,单位为KB。 
-f     <文件大小> shell所能建立的最大文件,单位为区块。 
-H  设定资源的硬性限制,也就是管理员所设下的限制。 
-m    <内存大小> 指定可使用内存的上限,单位为KB。
-n     <文件数目> 指定同一时间最多可开启的文件数。
-p     <缓冲区大小> 指定管道缓冲区的大小,单位512字节。
-s     <堆叠大小> 指定堆叠的上限,单位为KB。
-S  设定资源的弹性限制。 
-t   指定CPU使用时间的上限,单位为秒。 
-u    <程序数目> 用户最多可开启的程序数目。 
-v    <虚拟内存大小>  指定可使用的虚拟内存上限,单位为KB。
   
ulimit -a来查看所有限制值
 
01
core file size          (blocks, -c) 0
02
data seg size           (kbytes, -d) unlimited
03
scheduling priority             (-e) 0
04
file size               (blocks, -f) unlimited
05
pending signals                 (-i) 256590
06
max locked memory       (kbytes, -l) 64
07
max memory size         (kbytes, -m) unlimited
08
open files                      (-n) 1024
09
pipe size            (512 bytes, -p) 8
10
POSIX message queues     (bytes, -q) 819200
11
real-time priority              (-r) 0
12
stack size              (kbytes, -s) 10240
13
cpu time               (seconds, -t) unlimited
14
max user processes              (-u) 80920
15
virtual memory          (kbytes, -v) unlimited
16
file locks                      (-x) unlimited
 
使用命令ulimit -HSn 65536可以立即生效.
 
ulimit -u 80920 在centos 6.2不能立即生效,还需要修改
 
vim /etc/security/limits.d/90-nproc.conf     原因应该是新特性
   
1
# Default limit for number of user's processes to prevent
2
# accidental fork bombs.
3
# See rhbz #432903 for reasoning.
4
 
5
*          soft    nproc     80920
  
注:/etc/security/limits.conf  
   
limits.conf的工作原理: 
  limits.conf的后端是这样工作的:limits.conf是pam_limits.so的配置文件,然后/etc/pam.d/下的应用程序调用pam_***.so模块。譬如说,当用户访问服务器,服务程序将请求发送到PAM模块,PAM模块根据服务名称在/etc/pam.d目录下选择一个对应的服务文件,然后根据服务文件的内容选择具体的PAM模块进行处理。
limits.conf的格式
01
#<domain> can be:
02
#        - an user name
03
#        - a group name, with @group syntax
04
#        - the wildcard *, for default entry
05
#        - the wildcard %, can be also used with %group syntax,
06
#          for maxlogin limit
07
设置需要被限制的用户名,组名前面加@和用户名区别。也可以用通配符*来做所有用户的限制。
08
#<type> can have the two values:
09
#        - "soft" for enforcing the soft limits
10
#        - "hard" for enforcing hard limits
11
hard 表明系统中所能设定的最大值。soft 的限制不能比hard 限制高。  
12
#<item> can be one of the following:
13
#        - core - limits the core file size (KB)
14
           core - 限制内核文件的大小
15
#        - data - max data size (KB)
16
           date - 最大数据大小
17
#        - fsize - maximum filesize (KB)
18
           fsize - 最大文件大小
19
#        - memlock - max locked-in-memory address space (KB)
20
           memlock - 最大锁定内存地址空间
21
#        - nofile - max number of open files
22
           nofile - 打开文件的最大数目
23
#        - rss - max resident set size (KB)
24
           rss - 最大持久设置大小
25
#        - stack - max stack size (KB)
26
           stack - 最大栈大小
27
#        - cpu - max CPU time (MIN)
28
           cpu - 以分钟为单位的最多 CPU 时间
29
#        - nproc - max number of processes
30
           noproc - 进程的最大数目
31
#        - as - address space limit (KB)
32
           as - 地址空间限制
33
#        - maxlogins - max number of logins for this user
34
           maxlogins - 此用户允许登录的最大数目
35
#        - maxsyslogins - max number of logins on the system
36
#        - priority - the priority to run user process with
37
#        - locks - max number of file locks the user can hold
38
#        - sigpending - max number of pending signals
39
#        - msgqueue - max memory used by POSIX message queues (bytes)
40
#        - nice - max nice priority allowed to raise to values: [-20, 19]
41
#        - rtprio - max realtime priority
42
#
43
#<domain>      <type>  <item>         <value>
44
#
45
 
46
#*               soft    core            0
47
#*               hard    rss             10000
48
#@student        hard    nproc           20
49
#@faculty        soft    nproc           20
50
#@faculty        hard    nproc           50
51
#ftp             hard    nproc           0
52
#@student        -       maxlogins       4
53
 
54
# End of file
55
mysql                soft    core            2048000
56
mysql                hard    core            2048000
57
mysql                soft    nofile          819200
58
mysql                hard    nofile          819200
如果遇到“段错误”(segmentation fault)这样的问题,这主要就是由于Linux系统初始的堆栈大小(stack size)太小,可以使用ulimit  -s
   
core - 限制内核文件的大小 
  何谓core文件,当一个程序崩溃时,在进程当前工作目录的core文件中复制了该进程的存储图像。core文件仅仅是一个内存映象(同时加上调试信息),主要是用来调试的。 core文件是个二进制文件,需要用相应的工具来分析程序崩溃时的内存映像。 
 
nofile -打开文件的最大数目 
  对于需要做许多套接字连接并使它们处于打开状态的应用程序而言,最好通过使用 ulimit –n,或者通过设置nofile 参数,为用户把文件描述符的数量设置得比默认值高一些
阅读(2351) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~