CentOS7 systemd的坑
2018-01-05 17:38
337 查看
原文出处:https://www.cnblogs.com/chris-cp/p/6667753.html
一、概述
在从 CentOS 6 迁移到 CentOS 7 的过程中,可能有一些地方需要调整,最显著的地方莫过于 systemd 带来的改变,不同的管理服务的方式,不同的日志方式,设置时区,时间等等。 当然,除了这些显而易见的改变之外,有些变化并不是那么引人注目,例如这里要介绍的你可能发现曾经配置了正确的 /etc/security/limits.conf 在 CentOS 7 中却没有生效了。 如果遇到上面的问题,很可能已经导致了你的应用异常了,例如:以前配置了服务的nproc为一个非常大的数值, 结果现在发现服务不能打开更多的文件。 惊讶之余,查看服务的
/proc/<pid>/limits却发现:
1 Max open files 1024 1024 files那么,为什么服务使用 systemd 启动就没有生效呢? 根据 redhat bugzilla 754285, systemd 实际上是会忽略
/etc/security/limits.conf,下面是 systemd 2 号人物的回答:
而这个 bug 也标记为已解决,在 pam 包中解决,这个包包含了
/etc/security/limits.conf, 在这个文件中加入了如下注释:
# /etc/security/limits.conf # #This file sets the resource limits for the users logged in via PAM. #It does not affect resource limits of the system services. #注意,这里的 system services 指的是 system wide service,对于 CentOS 7 来说也就是系统的 service。 systemd 还可以对普通用户启动,使用
--user参数。
二、解决之道
在CentOS 7 / RHEL 7的系统中,使用Systemd替代了之前的SysV,因此 /etc/security/limits.conf 文件的配置作用域缩小了一些。limits.conf这里的配置,只适用于通过PAM认证登录用户的资源限制,它对systemd的service的资源限制不生效。登录用户的限制,与上面讲的一样,通过 /etc/security/limits.conf 和 limits.d 来配置即可。 对于systemd service的资源限制,如何配置呢?全局的配置,放在文件 /etc/systemd/system.conf 和 /etc/systemd/user.conf。 同时,也会加载两个对应的目录中的所有.conf文件 /etc/systemd/system.conf.d/*.conf 和 /etc/systemd/user.conf.d/*.conf其中,system.conf 是系统实例使用的,user.conf用户实例使用的。一般的sevice,使用system.conf中的配置即可。systemd.conf.d/*.conf中配置会覆盖system.conf。
1 DefaultLimitCORE=infinity2 DefaultLimitNOFILE=1000003 DefaultLimitNPROC=100000然后运行如下命令,才能生效。
1 sudo systemctl daemon-reload2 sudo systemctl restart nginx.service查看一个进程的limit设置:cat /proc/YOUR-PID/limits
例如我的一个nginx service的配置效果:
1 $cat /proc/$(cat /var/run/nginx.pid)/limits 2 Limit Soft Limit Hard Limit Units 3 Max cpu time unlimited unlimited seconds 4 Max file size unlimited unlimited bytes 5 Max data size unlimited unlimited bytes 6 Max stack size 8388608 unlimited bytes 7 Max core file size unlimited unlimited bytes 8 Max resident set unlimited unlimited bytes 9 Max processes 100000 100000 processes10 Max open files 100000 100000 files11 Max locked memory 65536 65536 bytes12 Max address space unlimited unlimited bytes13 Max file locks unlimited unlimited locks14 Max pending signals 1030606 1030606 signals15 Max msgqueue size 819200 819200 bytes16 Max nice priority 0 017 Max realtime priority 0 018 Max realtime timeout unlimited unlimited us
顺便提一下,我还被CentOS7自带的/etc/security/limits.d/20-nproc.conf文件坑过,里面默认设置了非root用户的最大进程数为4096,难怪我上次在limits.conf中设置了没啥效果,原来被limit.d目录中的配置覆盖了。
相关文章推荐
- #25 centos7(RHEL)系列操作系统的启动流程、systemd的特性、与命令systemctl的使用
- Linux自学笔记——Centos7系统之systemd
- centos7 系统管理systemd学习记录
- systemd的使用(centos7之后使用systemd代替init)
- centos7的systemd命令对比
- Centos7 Systemd详解
- 深入浅析centos7中的systemd
- [svc]centos7的服务治理-systemd
- 在systemd(CentOS7)自启动zookeeper
- Centos7安装tomcat-8.5.9+jsvc并配置systemd服务
- 在systemd(CentOS7)自启动zookeeper
- centos7启动过程及systemd详细说明
- CentOS7管理系统服务命令systemd
- CENTOS7 安装VMWARE TOOLS
- centos7 firewall防火墙设置
- centos7 安装Git
- centos7安装web服务器(openresty1.11.2.1、mysql5.7、php7、redis3.2)
- CentOS7清除wnTKYg木马
- centos7安装python3.6.2
- CentOS7 安装mysql