debian设置limits.conf

  最近已经把本身的游戏框架主要功能完成得差很少了,决定将本身的开发环境从debian7升级到debian9,否则太多第三方依赖都跟不上了。debian10刚出来,MongoDB还没适配,因此暂不考虑。ubuntu

  个人主系统是ubuntu14.04,经过VirtualBox安装debian9做为开发系统。本地的目录经过VirtualBox的目录共享功能挂载上去,而后用root用户进行编译、运行。bash

  部署开发环境,少不了要修改/etc/security/limits.conf,让系统能够coredump,方便debug。顺便改下最大文件数。这原本也很简单,就加两行配置。session

*               soft    core            unlimited
*               soft    nofile            65535

  然而重启后用ulimit -a查看发现它死活不生效。我虽然不记得当初部署debian7时改了哪些配置,但debian7的配置文件就是这么改的。猜想是debian9作了改动致使没生效,只能网上找资料一步步测试。app

 1. pam模块是否启用框架

/etc/pam.d/login
/etc/pam.d/sshd
/etc/pam.d/su

查看以上几个文件,都包含 session required pam_limits.so 因此是启用了的。ssh

2. ssh是否启用pam测试

我是经过ssh连上去的开发的,这个也须要排查下ui

cat /etc/ssh/sshd_config | grep UsePAM
UsePAM yes

ssh也是启用的。而后在VirtualBox的界面登陆也发现配置没生效,这个缘由排除掉。this

3. hard limit没设置debug

 

man limits.conf里有说到

for enforcing hard resource limits. These limits are set by the superuser and enforced by the Kernel. The user cannot raise his requirement of system resources above such values.

虽然以前历来没设置过hard limit,但也总得试下。因而我又加了一行

*               hard    nofile            65535

重启后也没有生效。

4. 查看日志,看是否有错误

cat /var/log/auth.log

Jul 21 12:25:01 debian CRON[686]: pam_unix(cron:session): session opened for user root by (uid=0)
Jul 21 12:25:01 debian CRON[686]: pam_unix(cron:session): session closed for user root
Jul 21 12:25:29 debian login[692]: pam_unix(login:session): session opened for user root by LOGIN(uid=0)也不

也没有发现什么异常,说明配置格式、权限都没什么问题。

到这里,网上经常使用的方法该试的都试了,都没能让。最后在https://serverfault.com/questions/610130/how-to-set-ulimit-value-permanently上有一个回复

Boom. * wildcard doesn't work for root. I added root instead of *, and it's working. Thank you! – NiCk Newman Jun 13 '16 at 15:25

*这个通配符对root用户没有效的。我测试了下,确实如此,另外一个号用ulimit -a查看配置修改为功。因为我部署环境一直用root,没发现这个。最后把用户名都改成root,重启后配置生效。

root               soft    core            unlimited
root               soft    nofile            65535
*               soft    core            unlimited
*               soft    nofile            65535

网上查了下资料,发现确实有这个限制。

man 5 limits.conf

NOTE: group and wildcard limits are not applied to the root user. To set a limit for the root user, this field must contain the literal username root.
相关文章
相关标签/搜索