• Linux常用错误too many open files


    最大文件数

    socket: too many open files

    原因:服务器打开文件数超过限制
    解决方法:修改服务器最大打开文件数配置
    查看服务器限制配置:

    [root@node-21-243 ~]# ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 257168
    max locked memory       (kbytes, -l) 8192
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 65535
    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) 257168
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    

    查看修改最大打开文件数:

    # 查看最大打开文件数
    [root@node-21-243 ~]# ulimit -n
    65535
    # 临时修改最大打开文件数,重启失效
    [root@node-21-243 ~]# ulimit -n 655350
    [root@node-21-243 ~]# ulimit -n
    655350
    
    

    长期有效的修改方法(服务器重启依然有效):

    vi /etc/security/limits.conf
    root soft nofile 65535
    root hard nofile 65535
    * soft nofile 65535
    * hard nofile 65535
    

    supervisor托管程序,最大文件数修改

    场景:如果服务是通过supervisor来托管的话,ulimits配置的修改可能无效。
    原因:supervisor有自己的程序最大打开文件数配置。

    查看程序最大打开文件数:

    [root@node-21-243 ~]# cat /proc/${进程id}/limits 
    Limit                     Soft Limit           Hard Limit           Units     
    Max cpu time              unlimited            unlimited            seconds   
    Max file size             unlimited            unlimited            bytes     
    Max data size             unlimited            unlimited            bytes     
    Max stack size            8388608              unlimited            bytes     
    Max core file size        0                    unlimited            bytes     
    Max resident set          unlimited            unlimited            bytes     
    Max processes             257168               257168               processes 
    Max open files            1048576              1048576              files     
    Max locked memory         8388608              8388608              bytes     
    Max address space         unlimited            unlimited            bytes     
    Max file locks            unlimited            unlimited            locks     
    Max pending signals       257168               257168               signals   
    Max msgqueue size         819200               819200               bytes     
    Max nice priority         0                    0                    
    Max realtime priority     0                    0                    
    Max realtime timeout      unlimited            unlimited            us  
    

    查看程序当前打开文件数:

    [root@node-21-243 ~]# lsof -p ${进程id}|wc -l
    78
    

    修改supervisor最大文件数配置:

    # 该文件路径不一定,需要根据自己环境确定
    vi supervisord.conf
    [supervisord]
    minfds=65535   
    

    重启supervisor服务:

    systemctl restart supervisor
    
  • 相关阅读:
    ubuntu在图形界面下打开一个终端
    [置顶] 屠夫与大夫
    service bound(一)
    Android Interface Definition Language (AIDL)
    service bound(二)
    移动应用开发原则
    Service bound(三)
    Linux 安装SSH服务
    JDK中设计模式
    Bad Hair Day【单调栈】
  • 原文地址:https://www.cnblogs.com/52why/p/16415534.html
Copyright © 2020-2023  润新知