ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • LINUX Too many open files 에러 해결하는 방법
    System of Infra/Linux System 2022. 6. 22. 00:15
    반응형

    LINUX 로고이미지

     

    LINUX Too many open files 에러 해결하는 방법

    [root@LINUX01 ~]# cat /var/log/messages
    Jun 19 05:12:07 LINUX01 named[3699]: isc_socket_create: fcntl/reserved: Too many open files
    Jun 20 08:00:56 LINUX01 named[3699]: isc_socket_create: fcntl/reserved: Too many open files
    Jun 20 08:07:01 LINUX01 named[3699]: isc_socket_create: fcntl/reserved: Too many open files
    ▶ /var/log/messages에 isc_socket_create: fcntl/reserved: Too many open files 에러 메시지가 지속적으로 출력이 된다면 ulimit 파일을 확인해야 합니다.

    [Too many open files 원인]
    1차적인 원인은 프로세스가 OS에 요청할 수 있는 최대 Open 가능한 파일 개수에 limit이 있으면 그 제한을 초과할 경우 에러가 발생합니다.
    [root@LINUX01 ~]# ulimit -aS
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 49152
    max locked memory       (kbytes, -l) 32
    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) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 49152
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    ▶ ulmit -aS 옵션을 쓰게 되면 소프트웨어 기반으로 설정 값을 확인할 수 있습니다.  Default의 상태에서 open files를 보게 되면 65535의 개수로 설정이 되어 있는 것을 확인할 수 있습니다.
    [root@LINUX01 ~]# ulimit -aH
    core file size          (blocks, -c) unlimited
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 49152
    max locked memory       (kbytes, -l) 32
    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) unlimited
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 49152
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    ▶ ulmit -aH 옵션을 쓰게 되면 하드웨어 기반으로 설정 값을 확인할 수 있습니다.  Default의 상태에서 open files를 보게 되면 65535의 갯수로 설정이 되어 있는 것을 확인할 수 있습니다.
    차이점이라면 stack size가 소프트웨어 ulimit에서는 10240인데 하드웨어의 경우는 ulimited로 하드웨어 ulimit이 소프트웨어에 비해 더 넓은 범위로 설정을 할 수 있고 단순히 말해 최대치를 쓸 수 있는 범위라고 생각하시면 되겠습니다.
    [root@LINUX01 ~]# 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) 49152
    max locked memory       (kbytes, -l) 32
    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) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 49152
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    ▶ ulimit -a 명령어를 수행하게 되면 소프트웨어 ulimit 기준으로 출력이 되기 때문에 더 깊게 확인하기 위해서는 ulimit -aH를 통해서 확인을 할 수 있습니다.
    [root@LINUX01 ~]# cat /var/log/messages
    Jun 21 13:59:10 LINUX01 named[3699]: isc_socket_create: fcntl/reserved: Too many open files
    Jun 21 15:29:08 LINUX01 named[3699]: isc_socket_create: fcntl/reserved: Too many open files
    ▶ 설정 파일을 봤을 때 계속해서 에러가 발생하게 되면 /etc/security/limits.conf 파일의 Config 값을 확인 후 수정해야 합니다.
    [client@LINUX01 ~]# 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) 49152
    max locked memory       (kbytes, -l) 32
    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) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 49152
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    ▶ root 계정이 아닌 유저 계정에 대한 open files 값이 1024인 것을 확인할 수 있습니다.
    [root@LINUX01 ~]# cat /proc/sys/fs/file-max
    77400
    ▶ ulimit의 설정 값을 변경하기 전에 시스템에서 전체 limit의 설정값을 확인해야 합니다.
    즉 limit 값의 경우 system 전체 limit보다 작아야 합니다.
    [root@LINUX01 ~]# vi /etc/security/limits.conf
    # /etc/security/limits.conf
    #
    #Each line describes a limit for a user in the form:
    #
    #<domain>        <type>  <item>  <value>
    #
    #Where:
    #<domain> can be:
    #        - an user name
    #        - a group name, with @group syntax
    #        - the wildcard *, for default entry
    #        - the wildcard %, can be also used with %group syntax,
    #                 for maxlogin limit
    #
    #<type> can have the two values:
    #        - "soft" for enforcing the soft limits
    #        - "hard" for enforcing hard limits
    #
    #<item> can be one of the following:
    #        - core - limits the core file size (KB)
    #        - data - max data size (KB)
    #        - fsize - maximum filesize (KB)
    #        - memlock - max locked-in-memory address space (KB)
    #        - nofile - max number of open files
    #        - rss - max resident set size (KB)
    #        - stack - max stack size (KB)
    #        - cpu - max CPU time (MIN)
    #        - nproc - max number of processes
    #        - as - address space limit
    #        - maxlogins - max number of logins for this user
    #        - maxsyslogins - max number of logins on the system
    #        - priority - the priority to run user process with
    #        - locks - max number of file locks the user can hold
    #        - sigpending - max number of pending signals
    #        - msgqueue - max memory used by POSIX message queues (bytes)
    #        - nice - max nice priority allowed to raise to
    #        - rtprio - max realtime priority
    #
    #<domain>      <type>  <item>         <value>
    #
    
    #*               soft    core            0
    #*               hard    rss             10000
    #@student        hard    nproc           20
    #@faculty        soft    nproc           20
    #@faculty        hard    nproc           50
    #ftp             hard    nproc           0
    #@student        -       maxlogins       4
    
    root            hard    nofile          65535
    root            soft    nofile          65535
    client          hard    nofile          65535 (추가) -> 특정 유저계정에 지정하기 위함.
    client          soft    nofile          65535 (추가) -> 특정 유저계정에 지정하기 위함.
    *               hard    nofile          65535 (추가) -> 모든 유저계정에 지정하기 위함.
    *               soft    nofile          65535 (추가) -> 모든 유저계정에 지정하기 위함.
    
    
    # End of file
    ▶ /etc/security/limits.conf 파일에 root의 설정 값 외에 Client에 대한 설정 값을 추가해주도록 합니다. limits.conf 파일에 설정을 하게 되면 영구적으로 설정이 되기 때문에 현재 상태에서 설정을 하는 경우라면 ulimit 명령어로 즉시 수행을 해야 합니다.
    또는 특정 계정에 수행 말고 모든 유저 계정에 수행을 하기 위해서는 * 표시를 통해서 적용을 할 수 있습니다. 
    ulimit -n 65535
    ▶ ulimit  명령어를 통해서 해당 필드 n이 open files이기 때문에 65535를 입력하여 즉시 적용할 수 있습니다.
    [client@LINUX01 ~] 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) 49152
    max locked memory       (kbytes, -l) 32
    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) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 49152
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    ▶ 유저 계정에서 ulimit -a를 확인하게 되면 유저계정에 대한 open files가 65535로 변경된 것을 확인할 수 있습니다. 변경이 완료 되면 세션을 재접속하셔서 확인을 하면 변경된 limit 값으로 유지가 된것을 확인할 수 있습니다.
    # ulimit -a         // Soft 설정 보기
    # ulimit -aH        // Hard 설정 보기
    core file size          (blocks, -c) 0                       : 코어파일의 최대크기
    data seg size           (kbytes, -d) unlimited               : 프로세스의 데이터 세그먼트 최대크기
    scheduling priority             (-e) 0                  
    file size               (blocks, -f) unlimited               : 쉘에서 생성되는 파일일 최대크기              
    pending signals                 (-i) 14943
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited               : resident set size의 최대 크기(메모리 최대크기)
    open files                      (-n) 1024                    : 한 프로세스에서 열 수 있는 open file descriptor의 최대 숫자(열수 있는 최대 파일 수)  ,Too many open files error 발생시 해당값 조절해주면됨
    pipe size            (512 bytes, -p) 8                       : 512-바이트 블럭의 파이프 크기
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 10240
    cpu time               (seconds, -t) unlimited               : 총 누적된 CPU 시간(초)
    max user processes              (-u) 1024                    : 단일 유저가 사용가능한 프로세스의 최대 갯수
    virtual memory          (kbytes, -v) unlimited               : 쉘에서 사용가능 한 가상 메모리의 최대 용량
    file locks                      (-x) unlimited
    ▶ ulimit 각 항목의 설명
    -a : 모든 제한 사항을 보여줌.
    -c : 최대 코어 파일 사이즈
    -d : 프로세스 데이터 세그먼트의 최대 크기
    -f : shell에 의해 만들어질 수 있는 파일의 최대 크기
    -s : 최대 스택 크기
    -p : 파이프 크기
    -n : 오픈 파일의 최대수
    -u : 오픈파일의 최대수
    -v : 최대 가상메모리의 양
    -S : soft 한도
    -H : hard 한도
    ▶ ulimit  설정 값

     

    PS. 포스팅의 내용은 제 기준으로 작성한 것이기 때문에 참고해서 보시면 감사하겠습니다.

    포스팅 과정의 오류 및 오타 그리고 궁금한 점에 대해서는 댓글 남겨주세요.

    반응형

    댓글

Designed by Tistory.