歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> limits.conf配置文件詳解

limits.conf配置文件詳解

日期:2017/2/27 16:04:45   编辑:Linux教程
limits.conf的工作原理:
  limits.conf的後端是這樣工作的:limits.conf是 pam_limits.so的配置文件,然後/etc/pam.d/下的應用程序調用pam_***.so模塊。譬如說,當用戶訪問服務器,服務程序將請求發送到PAM模塊,PAM模塊根據服務名稱在/etc/pam.d目錄下選擇一個對應的服務文件,然後根據服務文件的內容選擇具體的PAM模塊進行處理。

實驗:limits實驗!關於能打開的最大文件數和能並發的最大進程數:
[研究背景: nginx 與 php 的連接, 以及對其做壓力測試的時候! 由於php-cgi是單進程的,影響nginx的效率, 然後便使用產蛋程序 spawn.
但是它依然受到限制, 怎麼辦? 系統最大並發進程數的控制, 也就是下面實驗的目的了! ]
[注意, 先將系統的默認全局參數調大 sysctl.conf -->kernel.threads-max = xxxxx .... ]

實驗結論:
a. nofile的配置,可以用 * 來通配對所有的用戶的設置!
b. noproc的配置,不能用 * 無效, 只能指定特定的用戶!

溫馨提醒: 最大進程並發數的設置很危險的,如果你的機器性能不是很好的話,用spawn產出5000個cgi進程,然後用ab並發出上萬個查詢請求進行壓力測試!
最後你發現,並發數小於5000的時候錯誤率為零,再高點兒,就有錯了!
1> limits.conf
* soft nofile 1000000  
* hard nofile 1000000  
root soft nproc  20000  
root hard nproc  20000  
* soft nproc  20000  
* hard nproc  20000  
  
實驗結果:  
[root@lin /]# ulimit -u   //20000  
[root@lin /]# ulimit -n   //1000000  
[root@lin /]# su - test  
[test@lin ~]$ ulimit -u   //1024  
[test@lin ~]$ ulimit -n   //1000000

2> limits.conf   
* soft nofile 1000000  
* hard nofile 1000000  
root soft nproc  20000  
root hard nproc  20000  
* soft nproc  20000  
* hard nproc  20000  
test soft nproc  20000  
test hard nproc  20000  
 
實驗結果:  
[root@lin /]# ulimit -u   //20000  
[root@lin /]# ulimit -n   //1000000  
[root@lin /]# su - test  
[test@lin ~]$ ulimit -u   //20000  
[test@lin ~]$ ulimit -n   //1000000

3> limits.conf
* soft nofile 1000000  
* hard nofile 1000000  
root soft nproc  30000  
root hard nproc  30000  
 
實驗結果:  
[root@lin /]# su - root  
[root@lin ~]# ulimit -u  //30000  
[root@lin ~]# ulimit -n  //1000000  
[root@lin /]# su - test  
[test@lin ~]$ ulimit -u  //1024  
[test@lin ~]$ ulimit -n  //1000000

4> limits.conf 
* soft nofile 1000000  
* hard nofile 1000000  
* soft nproc  20000  
* hard nproc  20000  

實驗結果:  
[root@lin /]# su - root  
[root@lin ~]# ulimit -u  //1024  
[root@lin ~]# ulimit -n  //1000000  
[root@lin ~]# su - test  
[test@lin ~]$ ulimit -u  //1024  
[test@lin ~]$ ulimit -n  //1000000 
Copyright © Linux教程網 All Rights Reserved