Linux systemd limits
https://www.cnblogs.com/IMxY/p/8941022.html
limits
关于Centos 7 / RHEL 7 中的limits要了解以下几点:
- CentOS 7 / RHEL 7的系统中,使用Systemd替代了之前系统版本中的SysV。
- Systemd 中的 /etc/security/limits.conf 文件的配置作用域缩小了,只适用于通过PAM认证登录用户的资源限制,对Systemd的service的资源限制不生效。
- 登录用户的限制,通过 /etc/security/limits.conf 和 /etc/security/limits.d/*.conf 来配置。
- 系统全局的配置,在文件 /etc/systemd/system.conf 和/etc/systemd/system.conf.d/*.conf 来设定。
- 用户全局的配置,在文件 /etc/systemd/user.conf 和/etc/systemd/user.conf.d/*.conf 来设定。
- *.conf.d/*.conf 文件会覆盖 *.conf ,一般的sevice,使用system.conf中的配置即可。
例:编辑 limits.conf 配置文件在文件尾部添加以下内容
vim /etc/security/limits.conf
* - nofile 1024000
* - nproc 1024000
等于
* soft nofile 1024000
* hard nofile 1024000
* soft nproc 1024000
* hard nproc 1024000
两段配置参数为什么相等,在下面《添加格式》中有详细的参数说明。
参数生效:
- working下执行 source /etc/profile
- 退出当前shell重新登录
- 临时生效可用ulimit -n number
查看当前:
- 进程:cat /proc/<process_pid>/
limits - lsof -p $process_pid 每个文件描述符的具体属性
- lsof -p $process_pid | wc -l 当前进程file descriptor table中FD的总量
- 用户:ulimit -n -u
ulimit(选项):
-a:显示目前资源限制的设定; -c <core文件上限>:设定core文件的最大值,单位为区块; -d <数据节区大小>:程序数据节区的最大值,单位为KB; -f <文件大小>:shell所能建立的最大文件,单位为区块; -H:设定资源的硬性限制,也就是管理员所设下的限制; -m <内存大小>:指定可使用内存的上限,单位为KB; -n <文件数目>:指定同一时间最多可开启的文件数; -p <缓冲区大小>:指定管道缓冲区的大小,单位512字节; -s <堆叠大小>:指定堆叠的上限,单位为KB; -S:设定资源的弹性限制; -t <CPU时间>:指定CPU使用时间的上限,单位为秒; -u <程序数目>:用户最多可开启的程序数目; -v <虚拟内存大小>:指定可使用的虚拟内存上限,单位为KB。ulimits文件中的添加格式:
[username | @groupname] type resource [ limit | unlimited ]
[username | @groupname]:
username:设置需要被限制的用户名,
@groupname:组名前面加@和用户名区别。
也可以用通配符*来做所有用户的限制。
type:有 soft,hard 和 -,
soft :指的是当前系统生效的设置值。
hard:表明系统中所能设定的最大值。
- :表明同时设置了 soft 和 hard 的值。
注意:soft 的限制不能比hard 限制高。
resource:
core - 限制内核文件的大小(kb)
date - 最大数据大小(kb)
fsize - 最大文件大小(kb)
memlock - 最大锁定内存地址空间(kb)
nofile - 打开文件的最大数目
rss - 最大持久设置大小(kb)
stack - 最大栈大小(kb)
cpu - 以分钟为单位的最多 CPU 时间
noproc - 进程的最大数目
as - 地址空间限制
maxlogins - 此用户允许登录的最大数目
[ limit | unlimited ]:
limit :限制所用的数字,具体可根据服务器的硬件配置和服务所需自定义。
unlimited:无限制
/etc/systemd/system.conf

# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See systemd-system.conf(5) for details. [Manager]
#LogLevel=info
#LogTarget=journal-or-kmsg
#LogColor=yes
#LogLocation=no
#DumpCore=yes
#CrashShell=no
#ShowStatus=yes
#CrashChVT=1
#CtrlAltDelBurstAction=reboot-force
#CPUAffinity=1 2
#JoinControllers=cpu,cpuacct net_cls,net_prio
#RuntimeWatchdogSec=0
#ShutdownWatchdogSec=10min
#CapabilityBoundingSet=
#SystemCallArchitectures=
#TimerSlackNSec=
#DefaultTimerAccuracySec=1min
#DefaultStandardOutput=journal
#DefaultStandardError=inherit
#DefaultTimeoutStartSec=90s
#DefaultTimeoutStopSec=90s
#DefaultRestartSec=100ms
#DefaultStartLimitInterval=10s
#DefaultStartLimitBurst=5
#DefaultEnvironment=
#DefaultCPUAccounting=no
#DefaultBlockIOAccounting=no
#DefaultMemoryAccounting=no
#DefaultTasksAccounting=no
#DefaultTasksMax=
#DefaultLimitCPU=
#DefaultLimitFSIZE=
#DefaultLimitDATA=
#DefaultLimitSTACK=
#DefaultLimitCORE=
#DefaultLimitRSS=
#DefaultLimitNOFILE=
#DefaultLimitAS=
#DefaultLimitNPROC=
#DefaultLimitMEMLOCK=
#DefaultLimitLOCKS=
#DefaultLimitSIGPENDING=
#DefaultLimitMSGQUEUE=
#DefaultLimitNICE=
#DefaultLimitRTPRIO=
#DefaultLimitRTTIME=

默认 system.conf 文件中给很多可限制的参数
文件和进程的参数如下:
DefaultLimitNOFILE=1024000
DefaultLimitNPROC=1024000
参数生效:
systemctl daemon-reload
systemctl restart service_name.service
File Descriptors的设置
/proc/sys/fs/file-max决定了当前内核可以打开的最大的文件句柄数
使用shell计算
grep -r MemTotal /proc/meminfo | awk '{printf("%d",$2/10)}'
设置:
临时生效
sysctl -w fs.file-max=100000
永久生效
vim /etc/sysctl.conf + fs.file-max = 100000
查看
cat /proc/sys/fs/file-max
or
sysctl fs.file-max
/proc/sys/fs/file-nr中的值由三部分组成,分别为:
- 已经分配的文件句柄数
- 已经分配单没有使用的文件句柄数
- 最大文件句柄数
第二项的值总为0,这并不是一个错误,它实际上意味着已经分配的文件句柄无一浪费的都已经被使用了
查找文件句柄问题的时候,还有一个很实用的程序lsof,可以很方便看到某个进程开了那些句柄,也可以看到某个文件/目录被什么进程占用了
lsof -n |awk '{print $2}'|sort|uniq -c |sort -nr|more
- file-max是内核级别的,所有的进程总和不能超过这个数
- ulimit是进程级别的
Linux systemd limits的更多相关文章
- Linux systemd 打开调试终端、添加开机自运行程序
/************************************************************************* * Linux systemd 打开调试终端.添加 ...
- Linux systemd资源控制初探
Linux systemd资源控制初探 本文记录一次cgroup子目录丢失问题,并简单探索了Linux systemd的资源控制机制. 问题现象 我们希望通过systemd拉起服务并通过cgroup限 ...
- linux systemd 从简单的例子入门
linux systemd 从简单的例子入门 网上很多相关链接,一上来就给一大堆命令和讲解,让人头都大. 我们希望有一个service(服务),让它在开机启动的时候就执行. 用 root 登陆以后: ...
- [转帖]Linux systemd 常用命令
Linux systemd 常用命令 https://www.cnblogs.com/tsdxdx/p/7288490.html systemctl hostnamectl timedatectl l ...
- [转帖][Linux]systemd和sysV
[Linux]systemd和sysV 转自:https://www.cnblogs.com/EasonJim/p/7168216.html 在Debian8中systemd和sysVinit同时 ...
- 源码解读Linux的limits.conf文件
目录 目录 1 1. 前言 1 2. PAM 2 3. pam_limits 2 4. limits.conf的由来 3 5. 模块入口函数 4 6. 解析limits.conf 6 7. 生效lim ...
- Linux Systemd——在RHEL/CentOS 7中启动/停止/重启服务
RHEL/CentOS 7.0中一个最主要的改变,就是切换到了systemd.它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服务进行管理.systemd兼容SysV和Li ...
- linux systemd详解
CentOS 7 使用systemd替换了SysV.Systemd目的是要取代Unix时代以来一直在使用的init系统,兼容SysV和LSB的启动脚本,而且够在进程启动过程中更有效地引导加载服务. s ...
- [Linux]systemd和sysV
转自:https://www.cnblogs.com/EasonJim/p/7168216.html 在Debian8中systemd和sysVinit同时存在,NTP就是在/etc/init.d/n ...
随机推荐
- LOJ6070 基因 分块+回文自动机
这个在翁文涛的论文里有讲到 大概的就是一个子串的回文自动机是原串回文自动机的子图 于是每隔$\sqrt n$重新跑一个$(k \times \sqrt n,n)$的回文自动机 记录回文串个数和位置 并 ...
- Wed 基础
HTTP协议 www服务应用的默认端口为80 https加密服务的默认端口为443 常见状态码及其对应的作用 http://oldboy.blog.51cto.com/2561410/716294 2 ...
- Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Trident (又称为MSHTML),是微软的窗口操作系统(Windows)搭载的网页浏览器—Internet Explorer的排版引擎的名称. 它的第一个版本随着1997年10月Internet ...
- 导出putty配置
原文链接:http://downloadsquad.switched.com/2007/02/01/howto-transfer-your-putty-settings-between-compute ...
- 【转】浅谈分布式服务协调技术 Zookeeper
非常好介绍Zookeeper的文章, Google的三篇论文影响了很多很多人,也影响了很多很多系统.这三篇论文一直是分布式领域传阅的经典.根据MapReduce,于是我们有了Hadoop:根据GFS, ...
- How can I add a site title refiner
一篇非常好的博客,收藏一下 https://sharepoint.stackexchange.com/questions/109409/how-can-i-add-a-site-title-refin ...
- Windows 下的 Makefile 编写
Windows 下的 Makefile 编写(一)Makefile的基本规则 作者:cntrump Makefile对于很多人来说是陌生的,特别是习惯于使用 IDE 的人来说,似乎没有听说过 Make ...
- Markdown 语法手册 - 完整版(上)
https://blog.csdn.net/witnessai1/article/details/52551362 1. 斜体和粗体 代码: *斜体*或_斜体_ **粗体** ***加粗斜体*** ~ ...
- 基于Socket网络编程
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/a2011480169/article/details/73602708 博客核心内容: 1.Sock ...
- ds18b20采集温度并上报服务器
交叉编译器:arm-linux-gcc-4.5.4 Linux内核版本:Linux-3.0 主机操作系统:Centos 6.5 开发板:FL2440 温度传感器:ds18b20 注:此程序的客户端是在 ...