limits.conf的工作原理:
limits.conf的后端是這樣工作的:limits.conf是 pam_limits.so的配置文件,然后/etc/pam.d/下的應用程序
調用pam_***.so模塊。譬如說,當用戶訪問服務器,服務程序將請求發(fā)送到PAM模塊,PAM模塊根據(jù)服務名稱在/etc/pam.d目錄下
選擇一個對應的服務文件,然后根據(jù)服務文件的內容選擇具體的PAM模塊進行處理。[摘抄]
相關的應用以及配置, 還得繼續(xù)研究!下面分享一個小實驗!
實驗:limits實驗!關于能打開的最大文件數(shù)和能并發(fā)的最大進程數(shù):
[研究背景: nginx 與 php 的連接, 以及對其做壓力測試的時候! 由于php-cgi是單進程的,影響nginx的效率, 然后便使用產蛋程序 spawn.
但是它依然受到限制, 怎么辦? 系統(tǒng)最大并發(fā)進程數(shù)的控制, 也就是下面實驗的目的了! ]
[注意, 先將系統(tǒng)的默認全局參數(shù)調大 sysctl.conf -->kernel.threads-max = xxxxx .... ]
實驗結論:
a. nofile的配置,可以用 * 來通配對所有的用戶的設置!
b. noproc的配置,不能用 * 無效, 只能指定特定的用戶!
溫馨提醒: 最大進程并發(fā)數(shù)的設置很危險的,如果你的機器性能不是很好的話,用spawn產出5000個cgi進程,然后用ab并發(fā)出上萬個查詢請求進行壓力測試!
最后你發(fā)現(xiàn),并發(fā)數(shù)小于5000的時候錯誤率為零,再高點兒,就有錯了!
另外,當要killall全殺掉服務端開啟的cgi進程,你會發(fā)現(xiàn)機器卡了,我的實驗機器性能不怎么好,崩掉啦~
- 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
- ####################################
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
- ######################################
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
- #######################################
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
- ########################################
億恩-天使(QQ:530997) 電話 037160135991 服務器租用,托管歡迎咨詢。
本文出自:億恩科技【www.cmtents.com】
服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM]
|