[转帖]/etc/security/limits.conf 详解与配置
https://www.cnblogs.com/operationhome/p/11966041.html
一、 /etc/security/limits.conf 详解
/etc/security/limits.conf 文件实际是 Linux PAM(插入式认证模块,Pluggable Authentication Modules)中 pam_limits.so 的配置文件,而且只针对于单个会话。 该设置不会影响系统服务的资源限制。还要注意 /etc/security/limits.d/ 的这个目录,
/etc/security/limits.conf 配置解析
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
该文件为通过PAM登录的用户设置资源限制。
#It does not affect resource limits of the system services.
#它不影响系统服务的资源限制。
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
请注意/etc/security/limits.d下按照字母顺序排列的配置文件会覆盖 /etc/security/limits.conf中的
domain相同的的配置
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
这意味着,例如使用通配符的domain会被子目录中相同的通配符配置所覆盖,但是某一用户的特定配置
只能被字母路中用户的配置所覆盖。其实就是某一用户A如果在/etc/security/limits.conf有配置,当
/etc/security/limits.d子目录下配置文件也有用户A的配置时,那么A中某些配置会被覆盖。最终取的值是 /etc/security/limits.d 下的配置文件的配置。
#
#Each line describes a limit for a user in the form:
#每一行描述一个用户配置
#<domain> <type> <item> <value>
#Where:
#<domain> can be:
# - a user name 一个用户名
# - a group name, with @group syntax 用户组格式为@GROUP_NAME
# - the wildcard *, for default entry 默认配置为*,代表所有用户
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
有soft,hard和-,soft指的是当前系统生效的设置值,软限制也可以理解为警告值。
hard表名系统中所能设定的最大值。soft的限制不能比hard限制高,用-表名同时设置了soft和hard的值。
#<item> can be one of the following: <item>可以使以下选项中的一个
# - core - limits the core file size (KB) 限制内核文件的大小。
# - data - max data size (KB) 最大数据大小
# - fsize - maximum filesize (KB) 最大文件大小
# - memlock - max locked-in-memory address space (KB) 最大锁定内存地址空间
# - nofile - max number of open file descriptors 最大打开的文件数(以文件描叙符,file descripter计数)
# - rss - max resident set size (KB) 最大持久设置大小
# - stack - max stack size (KB) 最大栈大小
# - cpu - max CPU time (MIN) 最多CPU占用时间,单位为MIN分钟
# - nproc - max number of processes 进程的最大数目
# - as - address space limit (KB) 地址空间限制
# - maxlogins - max number of logins for this user 此用户允许登录的最大数目
# - maxsyslogins - max number of logins on the system 系统最大同时在线用户数
# - priority - the priority to run user process with 运行用户进程的优先级
# - locks - max number of file locks the user can hold 用户可以持有的文件锁的最大数量
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19] max nice优先级允许提升到值
# - rtprio - max realtime pr iority
#
#<domain> <type> <item> <value>
#
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@st
/etc/security/limits.d/目录
/etc/security/limits.d/目录
该目录下默认有*-nproc.conf文件,该文件是用于限制用户的线程限制。我们也可以在该目录创建配置文件在/etc/security/limits.d/下,以 .conf 结尾。centos 7
在CentOS 7版本中为
/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 # 所有的用户默认可以打开最大的进程数为 4096
root soft nproc unlimited # root 用户默认可以打开最大的进程数 无限制的。CentOS 6
在CentOS 6版本中为
/etc/security/limits.d/90-nproc.conf
二、 ulimit 如何配置
配置注意事项
注意不能设置 nofile不能设置 unlimited,noproc可以.
当我们设置了 nofile不能设置 unlimited 后,我们进行 ssh 登录,是登录不了的,并且报错下面的内容。
Dec 1 14:57:57 localhost sshd[1543]: pam_limits(sshd:session): Could not set limit for 'nofile': Operation not permitted
当我们设置的 nofile 的值可以设置的最大值为 1048576(2**20),设置的值大于该数,就会进行登录不了。也会显示上面的登录错误。(亲测)
基础配置
我们不将所有的配置配置在/etc/security/limits.conf 而是将配置放在 /etc/security/limits.d/ 下。
比如我们将 nofile的配置放在 /etc/security/limits.d/20-nofile.conf ,nproc 的配置放在 /etc/security/limits.d/20-nproc.conf.
一般我们需要配置的 /etc/security/limits.d/20-nofile.conf 为。
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
/etc/security/limits.d/20-nproc.conf 设置为
* - nproc 65535
root soft nproc unlimited
root hard nproc unlimited
注意覆盖点的问题。
示例一:
当 /etc/security/limits.conf 配置了:
root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539
这个root 用户的 默认取值是 65538 ,* 统配符虽然在 root 配置后面,但是 root 的配置只能被 root 进行覆盖。
我们看下这个配置,当这样配置的时候
root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539
root soft nofile 65539
这个的 root 用户的取值还是 65538 ,因为虽然 root soft nofile 65539 会覆盖我们之前的配置,但是这个配置是不生效的。因为 root soft nofile 65539 配置的值大于root hard nofile 65538 , soft 配置的值不能大于 hard.
示例二:
当我们在 /etc/security/limits.conf 配置了:
root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539
然后我们在 /etc/security/limits.d/20-nofile.conf 配置了:
root soft nofile 65536
root hard nofile 65536
* soft nofile 65540
* hard nofile 65540
最后的取值是会取 /etc/security/limits.d/20-nofile.conf 里面的值。
- 配置,只能被特定覆盖。
/etc/security/limits.d/下文件的相同配置可以覆盖/etc/security/limits.confsoft和hard需要都进行设置,才能生效。nofile不能设置unlimitednofile可以设置的最大值为 1048576(2**20),设置的值大于该数,就会进行登录不了。- soft 设置的值 一定要小于或等于 hard 的值。
具体详细配置根据应用情况进行配置。
三、ulimit 配置后生效
临时配置
设置可以打开文件的最大数为 65536
ulimit -SHn 65536
重启后失效。
永久配置
配置到配置文件/etc/security/limits.conf或者 /etc/security/limits.d/ 中。
然后退出当前会话,重新登录。 即可生效,重启配置也会保留。
配置不生效的问题
2020年3月份补充
SSH 登陆 limits 配置不生效解决办法
四、ulimit 常用命令
-S use the `soft' resource limit # 设置软限制
-H use the `hard' resource limit # 设置硬限制
-a all current limits are reported# 显示所有的配置。
-b the socket buffer size # 设置socket buffer 的最大值。
-c the maximum size of core files created # 设置core文件的最大值.
-d the maximum size of a process's data segment # 设置线程数据段的最大值
-e the maximum scheduling priority (`nice') # 设置最大调度优先级
-f the maximum size of files written by the shell and its children # 创建文件的最大值。
-i the maximum number of pending signals # 设置最大的等待信号
-l the maximum size a process may lock into memory #设置在内存中锁定进程的最大值
-m the maximum resident set size
-n the maximum number of open file descriptors # 设置最大可以的打开文件描述符。
-p the pipe buffer size
-q the maximum number of bytes in POSIX message queues
-r the maximum real-time scheduling priority
-s the maximum stack size
-t the maximum amount of cpu time in seconds
-u the maximum number of user processes # 设置用户可以创建的最大进程数。
-v the size of virtual memory # 设置虚拟内存的最大值
-x the maximum number of file locks
查看配置
查看所有的配置
ulimit -a
查看配置的最大打开文件数
ulimit -n
更改配置
ulimit -SHn 65536
文章参考:
[转帖]/etc/security/limits.conf 详解与配置的更多相关文章
- /etc/security/limits.conf 详解与配置
目录 一. /etc/security/limits.conf 详解 /etc/security/limits.conf 配置解析 /etc/security/limits.d/ 目录 二. ulim ...
- [转帖]/etc/security/limits.conf的含义
https://www.cnblogs.com/pzk7788/p/7250723.html /etc/security/limits.conf 是 Linux 资源使用配置文件,用来限制用户对系统资 ...
- /etc/security/limits.conf配置文件详解
这个文件主要是用来限制用户对系统资源的使用.是/lib64/security/pam_limits.so模块对应的/etc/serurity/pam_limits的配置文件. # /etc/secur ...
- [转帖]linux文件描述符文件/etc/security/limits.conf
linux文件描述符文件/etc/security/limits.conf https://blog.csdn.net/fanren224/article/details/79971359 需要多学习 ...
- [转帖]ulimit、limits.conf、sysctl和proc文件系统
ulimit.limits.conf.sysctl和proc文件系统 来源:https://blog.csdn.net/weixin_33918114/article/details/86882372 ...
- Redis:默认配置文件redis.conf详解
转: Redis:默认配置文件redis.conf详解 # Redis配置文件样例 # Note on units: when memory size is needed, it is possibl ...
- Redis配置文件redis.conf详解
一.Redis配置文件redis.conf详解 # Note on units: when memory size is needed, it is possible to specifiy # it ...
- yum的配置文件yum.conf详解
说明:经过网上抄袭和自己的总结加实验,非常详细,可留作参考. yum的配置一般有两种方式: 一种是直接配置/etc目录下的yum.conf文件, 另外一种是在/etc/yum.repos.d目录下 ...
- linux /proc/sys/fs/file-nr /proc/sys/fs/file-max /etc/security/limits.conf 三者的关联
ulimit -n 对应 /etc/security/limits.conf 文件设置 问题: Can’t open so many files 对于linux运维的同学们,相信都遇到过这个问题. 在 ...
- linux资源使用配置文件 /etc/security/limits.conf和ulimit
limits.conf文件实际上是linux PAM中pam_limits.so的配置文件,而且只针对于单个会话. limits.conf的格式如下: <domain> <type& ...
随机推荐
- C语言汉诺塔递归算法实现
这是个目录 一.什么是递归函数 1.先看一下一个递归的例子 2.递归的基本原理 二.汉诺塔问题 1.简要概括一下汉诺塔的故事 2.回到编程,汉诺塔问题主要就是解决这个问题: 3.怎么解决汉诺塔问题 要 ...
- flutter中InheritedWidget共享数据
InheritedWidget是Flutter框架中用于在Widget树中共享数据的机制.它是一个特殊的Widget,可以将其放置在Widget树的上层,并向下传递共享的数据给其子Widget.子Wi ...
- 创新 = 颠覆?AI创新如何做大蛋糕
本文分享自华为云社区<创新 = 颠覆?AI创新如何做大蛋糕>,作者: 华为云PaaS服务小智 . 最近随着AI的风靡,各行各业都充斥着近乎疯狂的言论,"AI必将替代一切" ...
- 云图说 | 华为云GPU共享型AI容器,让你用得起,用得好,用的放心
摘要:容器以其独特的技术优势,已经成为业界主流的AI计算框架(如Tensorflow.Caffe)的核心引擎,为了进一步解决企业在AI计算性能与成本上面临的问题,华为云推出了AI容器产品. 容器以其独 ...
- 云图说 | Workflow:流水线工具,助您高效完成AI开发
摘要:Workflow是将ML Ops(机器学习和DevOps的组合实践)应用于ModelArts平台,可以让您更高效的完成AI开发. 本文分享自华为云社区<云图说 | 第263期 Workfl ...
- 如何极速极速搭建个人博客?Copy攻城狮用的这一招很优秀!
摘要:在中国功夫中,"天下武功,无坚不摧,唯快不破",在编程的世界里,如何快速搭建一个属于自己的博客呢?那么 Pagic + Vercel 应该是个不错的选择!接下来,由Copy攻 ...
- 百万奖池角逐,华为云IoT边缘带你看懂“边缘计算开发者大赛”
摘要:2022年9月1日,第二届边缘计算开发者大赛正式启动. 2022年9月1日,第二届边缘计算开发者大赛正式启动! 本届大赛由华为云参与承办,中国信息通信研究院.工业互联网产业联盟.边缘计算产业联盟 ...
- 最后一天,CDMP数据治理认证高分训练营(9-10月)开放报名!
大家好,我是独孤风,一位曾经的港口煤炭工人,目前在某国企任大数据负责人,公众号大数据流动主理人. 首先告诉大家一个好消息,在大家共同的努力下,我们的CDMP国际数据治理认证训练营(7-8月)基本收官, ...
- iOS上架报错:无法添加以供审核
无法提交以供审核 要开始审核流程 必须提供以下项目 您必须为要添加的 app 提供版权信息. 您在提交 app 审核时遇到的问题是因为需要提供版权信息,而您的 app 缺少相关的版权信息.以下是解 ...
- No compiler detected, make sure you are running on top of a JDK instead of a JRE
Java 调 webservice 报如下错误 [2023-11-07 17:01:02.315] ERROR [scheduling-1] ToHisApiImpl.java:106 - No co ...