BLACKROOM

Ulimit打开的文件和用户名进程

如何提高Linux的/ Centos的/ RHEL的ulimit打开的文件和用户进程

vi /etc/sysctl.conf

fs.file-max = 65536

增加linux最大用户进程

vi /etc/security/limits.conf

*   soft    nproc   65535
*   hard    nproc   65535
*   soft    nofile  65535
*   hard    nofile  65535

增加linux针对用户的最大进程文件的限制

vi /etc/security/limits.d/90-nproc.conf

*   soft    nproc   65535
*   hard    nproc   65535
*   soft    nofile  65535
*   hard    nofile  65535

保存并退出查看linux用户最大进程或文件句柄限制

[root@localhost# ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 127358
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 65535
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

如果没有更改重启系统即可

imits.conf 文件实际是 Linux PAM(插入式认证模块,Pluggable Authentication Modules)中 pam_limits.so 的配置文件,而且只针对于单个会话。

limits.conf的格式如下:
username|@groupname type resource limit
username|@groupname:

设置需要被限制的用户名,组名前面加@和用户名区别,也可以用通配符*来做所有用户的限制。 type:有 soft,hard 和 -,
soft 指的是当前系统生效的设置值。
hard 表明系统中所能设定的最大值。
soft 的限制不能比hard 限制高。
用 - 就表明同时设置了 soft 和 hard 的值。

resource:
core - 限制内核文件的大小
date - 最大数据大小
fsize - 最大文件大小
memlock - 最大锁定内存地址空间
nofile - 打开文件的最大数目
rss - 最大持久设置大小
stack - 最大栈大小
cpu - 以分钟为单位的最多 CPU 时间
noproc - 进程的最大数目
as - 地址空间限制
maxlogins - 此用户允许登录的最大数目

要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:
session required /lib/security/pam_limits.so

例如:修改文件描述符大小(65536)

vi /etc/security/limits.conf

*   soft    nofile  65536  
*   hard    nofile  65536