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
Centos ulimit设置的更多相关文章
- 如何在 CentOS 中设置 NTP 服务器
网络时间协议(NTP)用来同步网络上不同主机的系统时间.你管理的所有主机都可以和一个指定的被称为 NTP 服务器的时间服务器同步它们的时间.而另一方面,一个 NTP 服务器会将它的时间和任意公共 NT ...
- VMware于CentOS网络设置
VMware于CentOS网络设置 底: 笔记本电脑有两块网卡: 1. 网卡连接公司内网,仅仅配置了内网ip和子网掩码. 2. 无线网卡.连接4g无线路由器.dhcp自己主动配置. 问题: 在VMwa ...
- CentOS 网络设置修改 指定IP地址 DNS 网关(转)
CentOS 网络设置修改 指定IP地址 DNS 网关(实测 笔记) 环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 ...
- CentOS 网络设置
CentOS 网络设置有两种方式配置网络可以连接外网: 自动分配与手动设置Ip 一,自动分配ip: 新装的centos6.0,用ifconfig只显示ifcfg-lo的信息,可以用ifup eth0的 ...
- linux centos 如何设置swap大小?
linux centos 如何设置swap大小? swap的值都是安装系统的时候设置好的,一般设置为内存的两倍大小.使用过程中发现swap值过小只能添加.用free -m 命令查看当前swap大小 使 ...
- yum命令安装软件时,出现--centos 7 安装apache 出现 Could not resolve host: mirrorlist.centos.org; 未知的错误"--CentOS网络设置 couldn't resolve host 'mirrorlist.centos.org问题解决
CentOS网络设置 couldn't resolve host 'mirrorlist.centos.org问题解决 今天在虚拟机上安装完CentOS6.5之后,首次使用时yum命令安装软件时,出现 ...
- centos 基础设置
centos 6 关闭防火墙 查看防火墙是否开启 service iptables status 停止防火墙 service iptables stop 禁止开机自启动防火墙 chkconfig ip ...
- CentOS中设置Windows共享文件夹
在CentOS中设置Samba可实现和Windows共享文件夹.常见的需求:1)用户能够在Windows机器上通过共享文件夹访问远程Linux服务器上自己的主目录:2)用户能够在Windows机器上访 ...
- Centos 7设置静态IP,修改时区,关闭防火墙
Centos 7设置静态IP # vi /etc/sysconfig/network-scripts/ifcfg-enxxx BOOTPROTO="static" ...... I ...
随机推荐
- IPMI中sol的使用
IPMI中sol的使用 转载韦远科 最后发布于2013-05-09 15:19:18 阅读数 7920 收藏 http://blog.chinaunix.net/uid-1838361-id-3 ...
- ubuntu中安装visual studio code-(转载)
在Ubuntu中安装Visual Studio Code 编译自:http://itsfoss.com/install-visual-studio-code-ubuntu/ 作者: Abhishek ...
- keil 中的incompatible错误
http://blog.csdn.net/kobesdu/article/details/42268065
- vue 实现带模板的EXCEL导出
话不多说直接上代码 1.前端(个人逻辑做了Excel导出和world导出,world导出会在下一个博客中列出) var xhr = new XMLHttpRequest() var url = win ...
- Ansible学习分享(基本)
背景:Teamleader提到一款好用的自动化配置管理工具,于是前去学习实践,有了下面分享. 纲要 一.Ansible简介 二.Ansible准备 2.1 Ansible安装 2.2 设置SSH公钥验 ...
- openresty 学习笔记一:环境安装
openresty 学习笔记一:环境安装 openresty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭 ...
- GO语言常用标准库02---os包
package main import ( "fmt" "os" ) func main() { //获得当前工作路径(当前工程根目录) dir, err := ...
- grasshopper DataTree 树形数据以及Graft Flatten Simplify的理解
问题的来源: 要在grasshopper里面输出 类似于二维数组的数据 但是在 grasshopper里的 C# 电池里面,无法显示 二维ArrayList里面的数据. 在 C# 电池里参考这个帖子: ...
- 第一个 Angular 应用程序
node download https://nodejs.org/zh-cn/ 全局安装 npm install @angular/cli -g 指定版本 npm install @angular/c ...
- TensorRT-优化-原理
TensorRT-优化-原理 一.优化方式 TentsorRT 优化方式: TensorRT优化方法主要有以下几种方式,最主要的是前面两种. 层间融合或张量融合(Layer & Tensor ...