1.三处配置
1.系统编译时默认设置文件(centos7新增)
服务配置 /etc/systemd/system.conf
用户配置 /etc/systemd/user.conf
2.PAM模块配置文件
/etc/security/limits.conf
第一列用户和组名:*表示通配所有用户;@表示组名;:表示uid或者gid;
第二列资源值类型:hard的值只能由root用户增加,其root权限用户和进程可以减少;soft的值,非root用户和进程可以修改;
第三列是资源类型:nofile为打开文件数,nproc为运行进程数,maxlogins为登录次数cpu、ram等等
第四列是资源数值:大于0的数值
非root用户的默认最大进程数配置文件/etc/security/limits.d/20-nproc.conf内容如下:
3.profile配置文件
系统默认配置文件(ulimit命令设置) /etc/profile 和 /etc/bashrc
用户家目录下的配置文件 bash_profile 和 .bashrc
用户shell或者服务启动脚本内运行 ulimit -n 10240
4.验证非root权限用户不能增加hard值(以nofile为例) 如果ulimit运行在非root用户的shell下,只能修改比当前值小,大的会报错
2.优先级
这里因为系统版本不同,所以优先级不同。这里分为centos6和centos7比较。
centos6
第一优先级:最后一次ulimit命令设置
第二优先级:/etc/security/limits.d/
第三优先级:/etc/security/limits.conf
系统优先级:/etc/systemd/system.conf 、user.conf
所谓系统优先级,即不受一二三优先级的影响,针对系统服务和用户服务的配置
centos7(因为系统版本不同,优先级也不相同,这里一定要注意)
第一优先级:最后一次ulimit命令设置
第二优先级:/etc/security/limits.conf
第三优先级:/etc/security/limits.d/
系统优先级:/etc/systemd/system.conf 、user.conf
所谓系统优先级,即不受一二三优先级的影响,针对系统服务和用户服务的配置
3.系统服务配置举例
假设系统内的apache需要设置打开文件为20000
建立apache服务的配置文件的目录
mkdir -p /etc/systemd/system/httpd.service.d/
创建如下apache的独立配置文件
systemd重读新的配置文件
4.系统配置举例
虽然优先级不同,但是这里还是使用/etc/security/limits.d/来举例,因为centos版本不同,相对应的文件名也不相同。如果使用centos7系统使用下面的方式,记得把/etc/securit/limits.conf下的配置文件注释掉。(centos7 limits.conf优先级高)
centos7
root soft nofile 102400
root hard nofile 102400
root soft nproc 102400
root hard nproc 102400
root soft core unlimited #不是非必要更改这个参数
root hard core unlimited
centos6
作者:小家电维修
转世燕还故榻,为你衔来二月的花。