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


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

http://www.linuxidc.com/Linux/2012-05/59489.htm

 

 

Linux就這個范兒P561

Linux處於穩定性的考慮,默認情況下對系統資源都做了限制,有一些Linux發行版會保守一些,如果不是很極端的話,盡量不要修改

還有一個限制最大打開文件描述符的地方,通過procfs文件系統來調整 cat /proc/sys/fs/file-max 

 

這個文件主要是用來限制用戶對系統資源的使用,具體的使用方法 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 descriptor計數)  
  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的時候遇到too 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則是一個真正意義的閥值,超過就會報錯

 


http://www.linuxidc.com/Linux/2012-05/59489.htm
改最大連接數
vi  /etc/security/limits.conf
 
*   hard   nproc    h1
*   hard   nofile     h1

vi /etc/security/limits.d/90-nproc.conf

*   hard    nproc    h2

echo  '*   hard   nproc    65535'  >>/etc/security/limits.conf  //centos5
echo  '*   hard   nofile     65535'  >>/etc/security/limits.conf
echo  '*   hard    nproc    65535'  >>/etc/limits.d/90-nproc.conf  //centos6

 

注意:  hard    nproc    h2,root用戶不受nproc    限制

 

 

lnmp第二部分

http://www.cnblogs.com/MYSQLZOUQI/p/4996262.html

nginx配置文件

nginx.conf
user nobody nobody; //使用哪個用戶和組來啟動子進程 主進程必須是root 1024以下的端口必須是root用戶監聽
worker_processes 2; //開啟多少個子進程
error_log /usr/local/nginx/logs/nginx_error.log crit; //日志級別crit
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200; //打開文件描述符的個數
events
{
use epoll; //事件模型
worker_connections 6000; 每個worker支持多少連接 曾經設置過10240 nginx做反向代理 導致502錯誤 最好不要設置那么大
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM