ulimit:修改和检查文件句柄数限制

写的好,我收藏起来慢慢看. 写的好,我支持一下. 没什么意思,把他踩下去. 阅读次数:43 | 订阅者:IceskYsl | 来源:IceskYsl@1sters! | 文章作者: iceskysl | 发表时间: 2008-08-19

在Linux下面部署应用的时候,有时候会遇上Socket/File: Can’t open so many files的问题,其实Linux是有文件句柄限制的,而且默认不是很高,一般都是1024,作为一台生产服务器,其实很容易就达到这个数量,因此我们需 要把这个值改大一些。

我们可以用ulimit -a来查看所有限制值,我只关心文件句柄数量的问题
open files (-n) 1024
这个就是限制数量 ,其指的是当前用户准备要运行的程序的限制。比较推荐的修改方法是:

正确的做法,应该是修改/etc/security/limits.conf
里面有很详细的注释,比如
* soft nofile 2048
* hard nofile 32768

检查:

Ruby代码

#check file descriptor  
  
echo  
echo "-----------------------------------------------"  
echo "Begin to check the file descriptor limit"  
fd=`ulimit -n`  
if [ $fd -lt 8192 ];  
   then  
   echo "Fatal Error!"  
   echo "The file descriptor limit is only '"$fd"'!"  
   echo "Please make it more than 8192!"  
   exit  
fi  
echo "OK, the file descriptor limit is" $fd  
echo "-----------------------------------------------"  
echo  
echo 

参考文章:
http://blog.chinaunix.net/u2/64804/showart_1019246.html
http://hi.baidu.com/leshy/blog/item/f57f4a903fb0898ea877a452.html阅读全文

技能云友情提示您: 如果您对本文观点感兴趣,欢迎到原文出处讨论,谢谢!