ulimit 命令详解

简介: ulimit 命令详解

阅读目录

回到顶部

ulimit 的简介及常用参数

ulimit:显示(或设置)用户可以使用的资源的限制(limit),这限制分为软限制(当前限制)和硬限制(上限),其中硬限制是软限制的上限值,应用程序在运行过程中使用的系统资源不超过相应的软限制,任何的超越都导致进程的终止。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

参数 描述

ulimited 不限制用户可以使用的资源,但本设置对可打开的最大文件数(max open files)

和可同时运行的最大进程数(max user processes)无效

-a 列出所有当前资源极限

-b 最大套接字缓冲区大小

-c 设置core文件的最大值.单位:blocks

-d 设置一个进程的数据段的最大值.单位:kbytes

-f Shell 创建文件的文件大小的最大值,单位:blocks

-h 指定设置某个给定资源的硬极限。如果用户拥有 root 用户权限,可以增大硬极限。任何用户均可减少硬极限

-k 可以分配的最大 kqueue 数

-i 待处理信号的最大数量

-l 可以锁住的物理内存的最大值

-m 可以使用的常驻内存的最大值,单位:kbytes

-n 每个进程可以同时打开的最大文件数

-p 设置管道的最大值,单位为block,1block=512bytes

-s 指定堆栈的最大值:单位:kbytes,Java程序需要适当的设置大一点

-S 指定为给定的资源设置软极限。软极限可增大到硬极限的值。如果 -H 和 -S 标志均未指定,极限适用于以上二者

-t 指定每个进程所使用的秒数,单位:seconds

-u 单个用户可用的最大进程数

-v 进程可用的最大虚拟内存量,单位:kbytes

-x 文件锁的最大数量

-T 最大线程数 

回到顶部

l临时生效

1

2

3

4

5

6

7

ulimit -u 10240 # 用户的最大进程数

ulimit -n 4096  #每个进程可打开的文件数

ulimit -d unlimited #数据段长度

ulimit -m unlimited #最大内存大小

ulimit -s unlimited  #堆栈大小

ulimit -t unlimited #CPU 时间

ulimit -v unlimited #虚拟内存

 

回到顶部

永久生效

修改所有 linux 用户的环境变量文件

1

2

3

4

5

6

7

8

vi /etc/profile.d/ulimit.sh # ~/.bashrc

   ulimit -u 10000

   ulimit -n 4096

   ulimit -d unlimited

   ulimit -m unlimited

   ulimit -s unlimited 

   ulimit -t unlimited

   ulimit -v unlimited

修改配置文件

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

# vi /etc/security/limits.conf

#<domain>        <type>  <item>  <value>

 

*               -       core             <value>

*               -       data             <value>

*               -       priority         <value>

*               -       fsize            <value>

*               soft    sigpending       <value> eg:57344

*               hard    sigpending       <value> eg:57444

*               -       memlock          <value>

*               -       nofile           <value> eg:1024

*               -       msgqueue         <value> eg:819200

*               -       locks            <value>

*               soft    core             <value>

*               hard    nofile           <value>

@<group>        hard    nproc            <value>

<user>          soft    nproc            <value>

%<group>        hard    nproc            <value>

<user>          hard    nproc            <value>

@<group>        -       maxlogins        <value>

<user>          hard    cpu              <value>

<user>          soft    cpu              <value>

<user>          hard    locks            <value>

<domain>可以是以下值

1

2

3

4

用户名

组名,带有@group语法

通配符*,用于默认条目

通配符%,也可以与%group语法一起使用,用于maxlogin限制

<type>可以有两个值: 

1

2

soft:用于执行软限制

hard:用于执行硬限制

<item>可以是以下之一

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

core- 限制核心文件大小 (KB)

data- 最大数据大小 (KB)

fsize- 最大文件大小 (KB)

memlock- 最大锁定内存地址空间 (KB)

nofile- 最大打开文件数

rss- 最大驻留集大小 (KB)

stack- 最大堆栈大小 (KB)

cpu- 最大 CPU 时间 (MIN)

nproc- 最大进程数(见下面的注释)

as- 地址空间限制 (KB)

maxlogins- 此用户的最大登录次数

maxsyslogins- 系统上的最大登录数

priority- 运行用户进程的优先级

locks- 用户可以持有的最大文件锁数

sigpending- 挂起信号的最大数量

msgqueue- POSIX 消息队列使用的最大内存(字节)

nice- 允许提升到值的最大优先级:[-20, 19]

rtprio- 最大实时优先级 

注意事项

1

在 /etc/security/limits.conf 中设置 nproc 在 Red Hat Enterprise Linux 中无效,要在/etc/security/limits.d/90-nproc.conf文件中修改。


相关文章
|
安全 Linux Shell
linux查看/修改各种资源限制ulimit
在Linux资源管理中,适当的使用 `ulimit`,结合系统配置文件的修改,可以更好地控制和优化系统资源,提高系统的稳定性和效率。对于系统管理员而言,精通这些知识是十分必要的,可以有效地防止因资源滥用导致的各种问题。
1620 5
|
安全 Linux
Linux命令(63)之ulimit
Linux命令(63)之ulimit
460 2
|
安全 Linux Shell
Linux - ulimit命令详解与修改不生效
Linux - ulimit命令详解与修改不生效
2409 1
|
安全 Linux
Linux - 修改系统的max open files、max user processes(附ulimit的使用方法)
Linux - 修改系统的max open files、max user processes(附ulimit的使用方法)目录 1 问题说明2 修改max open files3 修改max user processes4 附录: ulimit命令说明1 问题说明Linux 系统默认的 max op...
7530 0
|
安全 Linux Windows
Linux 基础之 TOP 命令详解
【2月更文挑战第10天】Linux 基础之 TOP 命令详解
1546 0
Linux 基础之 TOP 命令详解
|
Linux 安全 关系型数据库
linux设置ulimit值永久生效
小知识的积累,转自 http://hi.baidu.com/moonelf9989/blog/item/1deadf12780fa0c5c2fd789d.html linux 默认打开文件数linux 默认打开文件数为1024个,通过ulimit -a 可以查看open files 修改这个限制可以使用ulimt -SHn 65536 永久生效需要进行下面设置: 1.
12860 0
|
安全 网络安全 数据安全/隐私保护
/etc/ssh/sshd_config line 142: Deprecated option RSAAuthentication 是什么
【5月更文挑战第6天】/etc/ssh/sshd_config line 142: Deprecated option RSAAuthentication 是什么
3821 4
|
关系型数据库 MySQL Linux
【Linux环境】centos安装mysql5.7.26报 ./mysqld: error while loading shared libraries: libaio.so.1: cannot op
【Linux环境】centos安装mysql5.7.26报 ./mysqld: error while loading shared libraries: libaio.so.1: cannot op
1949 0
|
存储 缓存 数据处理
完全揭秘log file sync等待事件
什么是log file sync等待事件呢?在一个提交(commit)十分频繁的数据库中,一般会出现log file sync等待事件,当这个等待事件出现在top5中,这个时侯我们需要针对log file sync等待事件进行优化,一定要尽快分析并解决问题,否则当log file sync等待时间从几毫秒直接到20几毫秒可能导致系统性能急剧下降,甚至会导致短暂的挂起。
完全揭秘log file sync等待事件
|
8月前
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
2169 10

热门文章

最新文章

下一篇
开通oss服务