歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux資源使用配置文件 /etc/security/limits.conf

這個文件主要是用來限制用戶對系統資源的使用,具體的使用方法 man 5 limits.conf,裡面便給出了詳細的用法

  1. user@db-2:~$ cat /etc/security/limits.conf   
  2. # /etc/security/limits.conf  
  3. #  
  4. #Each line describes a limit for a user in the form:  
  5. #  
  6. #<domain>        <type>  <item>  <value>  
  7. #  
  8. #Where:  
  9. #<domain> can be:  
  10. #        - an user name  
  11. #        - a group name, with @group syntax  
  12. #        - the wildcard *, for default entry  
  13. #        - the wildcard %, can be also used with %group syntax,  
  14. #                 for maxlogin limit  
  15. #  
  16. #<type> can have the two values:  
  17. #        - "soft" for enforcing the soft limits # 軟限制,必須必硬限制的值要小  
  18. #        - "hard" for enforcing hard limits     # 硬限制  
  19. #  
  20. #<item> can be one of the following:  
  21. #        - core - limits the core file size (KB)  
  22. #        - data - max data size (KB)  
  23. #        - fsize - maximum filesize (KB)  
  24. #        - memlock - max locked-in-memory address space (KB)  
  25. #        - nofile - max number of open files    # 最大打開的文件數(以文件描敘符,file descripter計數)  
  26. #        - rss - max resident set size (KB)  
  27. #        - stack - max stack size (KB)  
  28. #        - cpu - max CPU time (MIN)  
  29. #        - nproc - max number of processes  
  30. #        - as - address space limit  
  31. #        - maxlogins - max number of logins for this user  
  32. #        - maxsyslogins - max number of logins on the system  
  33. #        - priority - the priority to run user process with  
  34. #        - locks - max number of file locks the user can hold  
  35. #        - sigpending - max number of pending signals  
  36. #        - msgqueue - max memory used by POSIX message queues (bytes)  
  37. #        - nice - max nice priority allowed to raise to  
  38. #        - rtprio - max realtime priority  
  39. #  
  40. #<domain>      <type>  <item>         <value>  
  41. #  
  42. root            soft    nofile          200000  
  43. root            hard    nofile          200000  
  44. admin           hard    nofile          65536  
  45. admin           soft    nofile          65536  
  46. # End of file  

每行的格式:
用戶名/用戶組    類型(硬限制、軟限制)   選項     值

比如很多朋友可能在使用mysql的時候遇到two many open files的錯誤,此時便可以通過將運行mysqld的用戶的 nofile(最大打開文件數)這個值增大一點,例如
db_running_user      -      nofile    設定一個合理的值  
注意上面的第二列 ‘-’表示hard和soft,可以顯示的為soft和hard寫兩行

我這只是舉一個例子,這個文件還可以配置很多資源的使用,但是一般的情況下用默認的就行,當你有特殊需求或者自己對這些參數的來龍去脈又相當了解,你可以去改這些默認的參數,查看當前用戶的這些資源使用限制情況可以使用 ulimit -a(查看ulimit的使用方法,用man ulimit無效,可以用help ulimit)

那麼對它的修改什麼時候生效呢?每次重新login的時候生效,至於原因則是我參考的那篇文章裡面說了。


自己的的疑問:

1. 為什麼要同時有soft和hard這兩個限制?這個soft和hard應該是代表兩種類型的閥值吧,一定不能超過hard限制,但是可以超過soft限制,有一個hard不就夠了麼?

知道設置兩個參數的意義在於:hard是一個上限在運行期間不可以調大但可以調小,而soft只能比hard小,在運行期間可以調大。 我也用mysqld測試過,它讀取的是soft值,但是我又不解的是,既然修改/etc/security/limits.conf要重新login才生效,那麼這些修改的意義不就沒有了嗎?因為要重新登錄,意味著服務要重啟

應該是這個解釋比較合理,soft是一個警告值,而hard則是一個真正意義的閥值,超過就會報錯。
Copyright © Linux教程網 All Rights Reserved