ulimit

Linux ulimit命令用于控制shell程序的资源。

root@hecs-270451192.168.0.179 10:41:17 [pwd:~]# ulimit --help
ulimit: ulimit [-SHabcdefiklmnpqrstuvxPT] [limit]
    Modify shell resource limits.

    Provides control over the resources available to the shell and processes
    it creates, on systems that allow such control.

    Options:
      -S        use the `soft' resource limit. 设置软资源限制,设置后可以增加,但是不能超过硬资源设置。	ulimit – Sn 32;限制软资源,32 个文件描述符。
      -H        use the `hard' resource limit. 设置硬资源限制,一旦设置不能增加。	ulimit – Hs 64;限制硬资源,线程栈大小为 64K。
      -a        all current limits are reported. #显示当前所有的 limit 信息。
      -b        the socket buffer size  
      -c        the maximum size of core files created #最大的 core 文件的大小, 以 blocks 为单位。	ulimit – c unlimited; 对生成的 core 文件的大小不进行限制。
      -d        the maximum size of a process's data segment #进程最大的数据段的大小,以 Kbytes 为单位。	ulimit -d unlimited;对进程的数据段大小不进行限制。
      -e        the maximum scheduling priority (`nice') #可执行程序的优先级,表示进程对 CPU 资源的需求程度,较小的 nice 值表示更高的优先级。通过增加 nice 值,进程会变得更加"友好",对 CPU 的需求较低,给其他进程更多的执行时间。
      -f        the maximum size of files written by the shell and its children #进程可以创建文件的最大值,以 blocks 为单位。	ulimit – f 2048;限制进程可以创建的最大文件大小为 2048 blocks。
      -i        the maximum number of pending signals
      -k        the maximum number of kqueues allocated for this process
      -l        the maximum size a process may lock into memory #最大可加锁内存大小,以 Kbytes 为单位。	ulimit – l 32;限制最大可加锁内存大小为 32 Kbytes。
      -m        the maximum resident set size #最大内存大小,以 Kbytes 为单位。	ulimit – m unlimited;对最大内存不进行限制。
      -n        the maximum number of open file descriptors #可以打开最大文件描述符的数量。	ulimit – n 128;限制最大可以使用 128 个文件描述符。
      -p        the pipe buffer size #管道缓冲区的大小,以 Kbytes 为单位。	ulimit – p 512;限制管道缓冲区的大小为 512 Kbytes。
      -q        the maximum number of bytes in POSIX message queues
      -r        the maximum real-time scheduling priority
      -s        the maximum stack size #线程栈大小,以 Kbytes 为单位。	ulimit – s 512;限制线程栈的大小为 512 Kbytes。
      -t        the maximum amount of cpu time in seconds #最大的 CPU 占用时间,以秒为单位。	ulimit – t unlimited;对最大的 CPU 占用时间不进行限制。
      -u        the maximum number of user processes #用户最大可用的进程数。	ulimit – u 64;限制用户最多可以使用 64 个进程。
      -v        the size of virtual memory #进程最大可用的虚拟内存,以 Kbytes 为单位。	ulimit – v 200000;限制最大可用的虚拟内存为 200000 Kbytes。
      -x        the maximum number of file locks  # 进程的最大文件锁定数。
      -P        the maximum number of pseudoterminals  # 进程可以创建的伪终端的最大数量。
      -T        the maximum number of threads

    Not all options are available on all platforms.

    If LIMIT is given, it is the new value of the specified resource; the
    special LIMIT values `soft', `hard', and `unlimited' stand for the
    current soft limit, the current hard limit, and no limit, respectively.
    Otherwise, the current value of the specified resource is printed.  If
    no option is given, then -f is assumed.

    Values are in 1024-byte increments, except for -t, which is in seconds,
    -p, which is in increments of 512 bytes, and -u, which is an unscaled
    number of processes.

    Exit Status:
    Returns success unless an invalid option is supplied or an error occurs.

ulimit 未指定默认修改的是软限制还是硬限制?

使用ulimit -n 65535命令将文件描述符(file descriptor)的限制设置为65535时,默认情况下会同时修改软限制和硬限制。

需要注意的是,非特权用户只能降低软限制或将软限制设置为不超过当前硬限制的值。只有特权用户(例如超级用户)才能增加或降低硬限制。

ulimit -a 各项含义

root@hecs-270451192.168.0.179 10:41:25 [pwd:~]# ulimit -a
#输出的每一行由资源名字、(单位,ulimit命令的参数)、软限制
core file size          (blocks, -c) 0 #core文件的最大值为100 blocks,为0表示禁用核心转储文件的生成。
data seg size           (kbytes, -d) unlimited #进程的数据段可以任意大
scheduling priority             (-e) 0 #
file size               (blocks, -f) unlimited # 文件可以任意大
pending signals                 (-i) 14820 #最多有2047个待处理的信号
max locked memory       (kbytes, -l) 64 #一个任务锁住的物理内存的最大值为64kB
max memory size         (kbytes, -m) unlimited #一个任务的常驻物理内存的最大值
open files                      (-n) 65535 #一个任务最多可以同时打开65535个文件
pipe size            (512 bytes, -p) 8 #管道的最大空间为512字节
POSIX message queues     (bytes, -q) 819200 #POSIX的消息队列的最大值为819200字节
real-time priority              (-r) 0 #
stack size              (kbytes, -s) 8192 #进程的栈的最大值为8192字节
cpu time               (seconds, -t) unlimited #进程使用的CPU时间
max user processes              (-u) 10240 #当前用户同时打开的进程的最大个数为10240
virtual memory          (kbytes, -v) unlimited #没有限制进程的最大地址空间
file locks                      (-x) unlimited #所能锁住的文件的最大个数没有限制

DM安装部署需要修改哪些选项?

vim /etc/security/limits.conf
l1="dmdba  soft      nice       0"	#默认情况下,进程的nice值为0,表示正常优先级,没有进行任何调整。与其他进程竞争CPU资源的机会相对均等。
l2="dmdba  hard      nice       0"	#默认情况下,进程的nice值为0,表示正常优先级,没有进行任何调整。
l3="dmdba  soft      as    unlimited"	#虚拟内存的限制
l4="dmdba  hard      as    unlimited"
l5="dmdba  soft  fsize   unlimited" #文件大小限制
l6="dmdba  hard  fsize   unlimited"
l7="dmdba  soft  nproc   131072" #最大进程数
l8="dmdba  hard  nproc   131072" 
l9="dmdba  soft  nofile  131072" #最大打开文件描述符
l10="dmdba  hard  nofile  131072"
l11="dmdba  soft  core    unlimited" #core文件最大大小
l12="dmdba  hard  core    unlimited" 
l13="dmdba  soft  data    unlimited" #进程的数据段
l14="dmdba  hard  data    unlimited"

#《DM INSTALL》文档说明需要修改(数据段大小、文件大小、打开文件数大小、虚拟内存大小)
#未说明修改最大进程数和nice

临时修改和永久修改

#临时修改,只在此终端下有效
ulimit -d unlimited #进程的数据段
ulimit -f unlimited # 文件可以任意大
ulimit -n 131072  #最大打开文件描述符
ulimit -v unlimited #虚拟内存大小
#永久修改,重启服务器或者重新登录生效
vim /etc/security/limits.conf
内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/lixiaomeng/p/17456000.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!