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

    too many open files

    出现这句提示的原因是程序打开的文件/socket连接数量超过系统设定值。

     

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

    ulimit -a

    1. fdipzone@ubuntu:~$ ulimit -a
    2. core file size (blocks, -c) 0
    3. data seg size (kbytes, -d) unlimited
    4. scheduling priority (-e) 20
    5. file size (blocks, -f) unlimited
    6. pending signals (-i) 16382
    7. max locked memory (kbytes, -l) 64
    8. max memory size (kbytes, -m) unlimited
    9. open files (-n) 1024
    10. pipe size (512 bytes, -p) 8
    11. POSIX message queues (bytes, -q) 819200
    12. real-time priority (-r) 0
    13. stack size (kbytes, -s) 8192
    14. cpu time (seconds, -t) unlimited
    15. max user processes (-u) unlimited
    16. virtual memory (kbytes, -v) unlimited
    17. file locks (-x) unlimited


    其中 open files (-n) 1024 表示每个用户最大允许打开的文件数量是1024 

    查看当前系统打开的文件数量

    1.  lsof | wc -l
       
    2.  watch "lsof | wc -l"
       

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

    1.  lsof -p pid | wc -l
       
    2.  lsof -p 1234 | wc -l
       

    设置open files数值方法

    ulimit -n 2048

    1.  fdipzone@ubuntu:~$ ulimit -n 2048
       
    2.  fdipzone@ubuntu:~$ ulimit -a
       
    3.  core file size (blocks, -c) 0
       
    4.  data seg size (kbytes, -d) unlimited
       
    5.  scheduling priority (-e) 20
       
    6.  file size (blocks, -f) unlimited
       
    7.  pending signals (-i) 16382
       
    8.  max locked memory (kbytes, -l) 64
       
    9.  max memory size (kbytes, -m) unlimited
       
    10.  open files (-n) 2048
       
    11.  pipe size (512 bytes, -p) 8
       
    12.  POSIX message queues (bytes, -q) 819200
       
    13.  real-time priority (-r) 0
       
    14.  stack size (kbytes, -s) 8192
       
    15.  cpu time (seconds, -t) unlimited
       
    16.  max user processes (-u) unlimited
       
    17.  virtual memory (kbytes, -v) unlimited
       
    18.  file locks (-x) unlimited
       

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

     

    永久设置方法

     

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

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

     

    fdipzone soft nofile 8192
    fdipzone hard nofile 8192

    改完后注销一下就能生效。

    转自:https://blog.csdn.net/fdipzone/article/details/34588803

  • 相关阅读:
    PHP 反射API
    wamp下mysql错误提示乱码的解法
    PDO、PDOStatement、PDOException
    PHP 常用函数
    TCP/IP
    centOS7+mariadb+Nginx+PHP7.0 安装
    php中引用&的真正理解-变量引用、函数引用、对象引用
    cgi fastcgi php-cgi php-fpm
    03 : linux判断服务器是虚拟机还是物理机
    02 :history命令显示日期-时间-登录IP-用户名
  • 原文地址:https://www.cnblogs.com/heluan/p/9597636.html
Copyright © 2011-2022 走看看