Centos ulimit设置
1.三处配置
1. 系统编译时默认设置文件(centos7新增)
服务配置 /etc/systemd/system.conf
用户配置 /etc/systemd/user.conf
2. PAM模块配置文件
/etc/security/limits.conf
EXAMPLES
These are some example lines which might be specified in /etc/security/limits.conf.
* soft core 0
* hard nofile 512
@student hard nproc 20
@faculty soft nproc 20
@faculty hard nproc 50
ftp hard nproc 0
@student - maxlogins 4
:123 hard cpu 5000
@500: soft cpu 10000
600:700 hard locks 10
第一列用户和组名:*表示通配所有用户;@表示组名;:表示uid或者gid;
第二列资源值类型:hard的值只能由root用户增加,其root权限用户和进程可以减少;soft的值,非root用户和进程可以修改;
第三列是资源类型:nofile为打开文件数,nproc为运行进程数,maxlogins为登录次数cpu、ram等等
第四列是资源数值:大于0的数值
非root用户的默认最大进程数配置文件/etc/security/limits.d/20-nproc.conf内容如下:
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 4096
root soft nproc unlimited
3.profile配置文件
系统默认配置文件(ulimit命令设置) /etc/profile 和 /etc/bashrc
用户家目录下的配置文件 bash_profile 和 .bashrc
用户shell或者服务启动脚本内运行 ulimit -n 10240
4.验证非root权限用户不能增加hard值(以nofile为例) 如果ulimit运行在非root用户的shell下,只能修改比当前值小,大的会报错
[tomcat@localhost ~]$ ulimit -n
4096
[tomcat@localhost ~]$ ulimit -n 8192
-bash: ulimit: open files: cannot modify limit: Operation not permitted
2.优先级
第一优先级:最后一次ulimit命令设置
第二优先级:/etc/security/limits.d/
第三优先级:/etc/security/limits.conf
系统优先级:/etc/systemd/system.conf 、user.conf
所谓系统优先级,即不受一二三优先级的影响,针对系统服务和用户服务的配置
3.系统服务配置举例
假设系统内的apache需要设置打开文件为20000
建立apache服务的配置文件的目录
mkdir -p /etc/systemd/system/httpd.service.d/
创建如下apache的独立配置文件
cat /etc/systemd/system/httpd.service.d/limits.conf
[Service]
LimitNOFILE=20000 #操作系统级别对每个用户创建的进程数的限制
LimitNPROC=20000 #每个进程可以打开的文件数的限制
systemd重读新的配置文件
systemctl daemon-reload
systemctl restart httpd
4.系统配置举例
centos7
[root@centos7 infra]# cat /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning. #* soft nproc 4096
#root soft nproc unlimited
* soft nofile 102400
* hard nofile 102400
root soft nofile 102400
root hard nofile 102400
* soft nproc 102400
* hard nproc 102400
root soft core unlimited
centos6
[root@centos6 infra]# cat /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning. #* soft nproc 1024
#root soft nproc unlimited * soft nofile 100001
* hard nofile 100002
* soft nproc 100001
* hard nproc 100002
* soft core unlimited
* hard core unlimited
最新文章
- SqlServer 常用函数
- Android下的xml资源详解
- javascript常用数组算法总结
- Leetcode Word Break
- temp - Linux administration handbook 答案
- BZOJ_1096_[ZJOI2007]_仓库建设_(斜率优化动态规划+单调队列+特殊的前缀和技巧)
- [九度OJ]1137.浮点数加法
- 没有document.getElementByName
- C++使用模版技术将任意类型的数据转为某个类型的数据
- 利用Ihttpmodel实现网站缓存,解决Server.Transfer 直接输出HTML源代码的问题
- COST CUTTING THE ALAN GREENBERG WAY
- STL源代码分析 集装箱 stl_set.h
- LeetCode之旅(19)-Power of Two
- day01 进制转换与内存分布
- unittest的使用三——断言
- HTML学习笔记Day11
- build.gradle最佳实践之buildConfigField
- An error occurred (500 Error)
- 747. Largest Number At Least Twice of Others
- trait代码复用