zoukankan      html  css  js  c++  java
  • linux打开文件数 too many open files 解决办法


    title: linux打开文件数 too many open files 解决办法
    date: 2020-05-03 08:30:45
    tags:

    • linux
      categories:
    • linux

    阿里巴巴Java开发手册中规定:

    调大服务器所支持的最大文件句柄数(File Descriptor,简写为fd)。 说明:主流操作系统的设计是将 TCP/UDP 连接采用与文件一样的方式去管理,即一个连接对 应于一个 fd。主流的 linux 服务器默认所支持最大 fd 数量为 1024,当并发连接数很大时很 容易因为 fd 不足而出现“open too many files”错误,导致新的连接无法建立。 建议将 linux 服务器所支持的最大句柄数调高数倍(与服务器的内存数量相关)。

    查看每个用户最大允许打开文件数量

    ulimit -a

    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 20
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 16382
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) unlimited
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    

    查看某一进程的打开文件数量

    ps -ef | grep java
    lsof -p 进程号 | wc -l
    

    设置open files数值方法

    ulimit -n 2048
    

    这样就可以把当前用户的最大允许打开文件数量设置为2048了,但这种设置方法在重启后会还原为默认值。

    永久设置方法

    vim /etc/security/limits.conf
    在最后加入
    * soft nofile 4096
    * hard nofile 4096
    

    最前的表示所有用户,可根据需要设置某一用户,改完后注销一下就能生效。

  • 相关阅读:
    ES6 Set
    JavaScript 之 对象属性的特性 和defineProperty方法
    ES6 ... 展开&收集运算符
    ES6 箭头函数
    ES6 解构 destructuring
    canvas之事件交互效果isPointPath
    跨域及JSONP原理
    P03 显示隐藏
    最长公共子序列
    P02 CSS样式
  • 原文地址:https://www.cnblogs.com/zhaoran8775/p/12820732.html
Copyright © 2011-2022 走看看