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的时候错误率为零,再高点儿,就有错了!
另外,当要killall全杀掉服务端开启的cgi进程,你会发现机器卡了,我的实验机器性能不怎么好,崩掉啦~
- 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.enkj.com】
服务器租用/服务器托管中国五强!虚拟主机域名注册顶级提供商!15年品质保障!--亿恩科技[ENKJ.COM]
|