zoukankan      html  css  js  c++  java
  • 解决Too many open files思路

    一、产生原因
    too many open files是Linux系统中常见的错误,从字面意思上看就是说程序打开的文件数过多,不过这里的files不单是文件的意思,也包括打开的通讯链接(比如socket),正在监听的端口等等,所以有时候也可以叫做句柄(handle),这个错误通常也可以叫做句柄数超出系统限制。 

    二、查看程序当前打开句柄的数量

    例如,我有个tomcat中报了这个错:

    ps -ef | grep tomcat      查看pid

    lsof -p 进程id | wc -l   查看进程打开句柄的数量

    cat /proc/进程id/limits  查看进程最大能打开的文件数

    ulimit -a         单个进程默认可以打开的句柄数上限

    三、解决方法
    1、增大允许打开的文件数——命令方式
    ulimit -n 2048
    这样就可以把当前用户的最大允许打开文件数量设置为2048了,但这种设置方法在重启后会还原为默认值。 
    ulimit -n命令非root用户只能设置到4096。 
    想要设置到更大需要sudo权限或者root用户。

    2、增大允许打开的文件数——修改系统配置文件
    vim /etc/security/limits.conf  
    #在最后加入  
    * soft nofile 4096  
    * hard nofile 4096  
    或者只加入

     * - nofile 8192

    最前的 * 表示所有用户,可根据需要设置某一用户,例如

    roy soft nofile 8192  
    roy hard nofile 8192  
    注意”nofile”项有两个可能的限制措施。就是项下的hard和soft。 要使修改过得最大打开文件数生效,必须对这两种限制进行设定。 如果使用”-“字符设定, 则hard和soft设定会同时被设定。

  • 相关阅读:
    navicat for mysql (本人亲测,真实有效)
    python 8 days
    python 19 days
    python 20 days
    python 21 days
    python 10 days
    python 9 days
    python 14 days
    python 15 days
    python 16 days
  • 原文地址:https://www.cnblogs.com/sss-justdDoIt/p/11933448.html
Copyright © 2011-2022 走看看