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.
相關文章
相關標籤/搜索