你的位置:首页 > 网海拾贝

limits.conf配置文件详解

2015-10-05 浏览:(4104) 网海拾贝 评论(0)

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

  • 发表评论
  • 查看评论
【暂无评论!】

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。