Linux systemd limits
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=
CentOS Linux release 7.4.1708 (Core)
默认 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是进程级别的
转载于:https://www.cnblogs.com/IMxY/p/8941022.html
Linux systemd limits相关推荐
- linux下limits.conf 修改不生效的原因
简介 ELK环境搭建时,发现需要修改ulimit 设置,否则就会报错. 总结下来发现要使limits.conf生效,需要设置 UsePAM yes UseLogin yes #这个保证其他的用户也能修 ...
- Linux Systemd服务
Linux Systemd服务(2021.07.09) 文章目录 Linux Systemd服务(2021.07.09) 一.概述 二.配置文件 2.1 Unit 2.2 Service 2.3 In ...
- 源码解读Linux的limits.conf文件
1. 前言 本文不一定适合比较老版本的Linux,如果只关心使用,请直接看"总结",本文主要针对CentOS,其它Linux发行版本类似,但细节可能有出入,比如重启服务可能不是用s ...
- linux systemd 服务管理脚本简介
我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web server等.因此管理 linux 服务器主要工作就是配置并管理上面运行的各种服务程序.在 linux 系统中 ...
- linux systemd服务,systemd服务管理
显示所有已启用的Unit(list-units) 因为systemctl命令的默认选项是systemctl list-units,不添加任何选项的话,将显示list-units的结果. 另外在syst ...
- linux systemd 使用
2019独角兽企业重金招聘Python工程师标准>>> Systemd 使用手册 https://www.freedesktop.org/software/systemd/man/s ...
- 【Linux】Linux Systemd 启动守护进程
1.概述 转载:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html 去看原文吧,排版比较好,这里转载防丢失 Sy ...
- linux systemd命令,systemd命令
systemd 是一个专用于 Linux 操作系统的系统与服务管理器.当作为启动进程(PID=1)运行时,它将作为初始化系统运行,也就是启动并维护各种用户空间的服务. 为了与传统的 SysV 兼容,如 ...
- linux systemd.service说明
翻译 描述 名称以".service"结尾的单元配置文件对有关由systemd控制和监督的进程的信息进行编码. 此手册页列出了特定于此单元类型的配置选项.有关所有单元配置文件的常用 ...
最新文章
- MySQL配置文件参数详解
- Tensorfow_yolov3 Intel Realsense D435 图像整合(合并)输入GPU计算耗时测试
- mac 下 使用 java运行 class 文件 总是提示 “错误: 找不到或无法加载主类”的解决方法...
- python3 一 线程与互斥锁详解
- 值类型与引用类型数据运算
- Python__名称空间与作用域
- C# PDF 转成图片利用GhostScript
- gflags.lib(gflags.obj) : error LNK2001: 无法解析的外部符号 __imp_PathMatchSpecA
- ArcMAP中如何将16位保存的卫星底图,转变为8位表示
- 【HNOI2006】【Luogu2320】鬼谷子的钱袋(进制,玄学)
- spark读取gz文件与parquet文件
- mysql 给表填充数据库_mysql---为测试数据库填充大量数据
- 华云数据收购国际超融合软件厂商Maxta全部资产
- redis 异常解决办法
- 【3D建模】2020最好用的3款3D建模软件!新手入门必备建模软件!
- 关于“DEP数据执行保护”的解决方案
- CTFSHOW愚人杯2023 部分wp
- iOS 内购项目的App Store推广
- CAcls命令在提权中的使用
- surface pro java_【微软SurfacePro4评测】两代产品外观对比_微软 Surface Pro 4_笔记本评测-中关村在线...
热门文章
- 掌握 Ajax,第 1 部分: Ajax 入门简介
- ×××数据库导数据ora-01400错误小计
- asp.net mvc 2被遗忘的%:Html.AntiForgeryToken() %
- [转贴]人老总是一场空
- python如何制作一个工程软件_使用python制作一个解压缩软件
- python字典函数_python-字典常用函数
- 开奖|八大福利,康康你中奖了没?
- Java研发知识图谱
- 用于对Compound协议进行无Gas投票和委托的社区工具发布
- 海德薇格:我很期待看到 数字货币将如何改变人民币支付市场