zoukankan      html  css  js  c++  java
  • debian设置limits.conf

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

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

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

    *               soft    core            unlimited
    *               soft    nofile            65535

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

     1. pam模块是否启用

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

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

    2. ssh是否启用pam

    我是通过ssh连上去的开发的,这个也需要排查下

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

    ssh也是启用的。然后在VirtualBox的界面登录也发现配置没生效,这个原因排除掉。

    3. hard limit没设置

    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.
  • 相关阅读:
    第五周学习进度报告
    第四周学习进度报告
    第三周大数据学习进度
    十六周总结
    程序员修炼之道-从小工到专家阅读笔记03
    第二阶段冲刺10
    利用正则表达式,分割地址至省市县,更新MySQL数据库数据
    阅读笔记--《大型网站技术架构》—01大型网站概述
    第三周周总结——kettle的简单使用以及MYSQL数据库去重
    热词分析中运用可用性战术
  • 原文地址:https://www.cnblogs.com/coding-my-life/p/11220989.html
Copyright © 2011-2022 走看看