ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • elasticsearch 에러 - FileNotFoundException, too many open file (열린 파일이 너무 많음)]; "}},
    프로그래밍/검색 2014. 7. 22. 23:42
    반응형

     

    elasticsearch를 깔고 bulk 색인을 돌렸는데 아래와 같은 색인 에러가 나타났습니다.


     

    {"index":{"_index":"a001470","_type":"2014","_id":"5","status":500,"error":"IndexFailedEngineException[[a001470][1] Index failed for [2014#5]]; nested: FileNotFoundException[/elasticsearch-1.2.1/data/elasticsearch/nodes/0/indices/a001470/1/index/_0.fdx (열린 파일이 너무 많음)]; "}},

     

    검색해보니 elasticsearch의 open file의 개수가 작아서 생기는 일인 것 같습니다.

    elasticsearch의 max_file_descriptors( open file )개수를 확인해 보니 1024라니 확실히 작네요 -_-;

     

    #curl localhost:9200/_nodes/process?pretty
    {
      "cluster_name" : "elasticsearch",
      "nodes" : {
        "h68AFCOMQT-PF4tejfDCrA" : {
          "name" : "Crooked Man",
          "version" : "1.2.1",
          "build" : "6c95b75",
          "process" : {
            "refresh_interval_in_millis" : 1000,
            "id" : 20860,
            "max_file_descriptors" : 1024,
            "mlockall" : false
          }
        }
      }
    }

     

     

    리눅스 기본 설정도 확인해보았습니다.

    ulimit는 쉘이 실행한 프로세스에 대하여 시스템 상의 사용 자원을 설정할 수 있도록 해주는 명령어 입니다.

     

    # 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) 4095
    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) 4095
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited

     

     

    기본 open file 세팅도 1024로 되어있으니 일단 ulimit -n32000 명령어를 주어  프로세스 당 open file개수를 변경합니다.

    http://www.elasticsearch.org/guide/reference/setup/installation/

    엘라스틱 서치에서는 기본적으로 오픈 파일 값을 32K나 64K 로 설정하는 것을 권장하고 있습니다.

     

    Make sure to increase the number of open files descriptors on the machine (or for the user running elasticsearch). Setting it to 32k or even 64k is recommended.

    In order to test how many open files the process can open, start it with -Des.max-open-files set to true. This will print the number of open files the process can open on startup.

     

     

    제대로 설정이 되었는지 확인해 봅니다.

     

    #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) 4095
    max locked memory       (kbytes, -l) 32
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 32000
    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) 4095
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited

     

     



    ulimit -n의 변경값은 일시적이기 때문에 이 값을 계속 유지하고 싶으면 /etc/security/limits.conf 파일의 내용을 수정해야 합니다.. 

    nofile은 해당 사용자(그룹)이 오픈할 수 있는 최대 파일 개수를 의미합니다. 

    /etc/security/limits.conf 값은 새로운 session 부터 영향을 끼치기 때문에

    파일 설정을 변경하고 재로그인을하거나 새로운 세션으로 다시 접속하면 해당 설정이 변경된 것을 확인할 수 있습니다. 


    # 전체 user에게 같은 설정을 하려면 * 을 사용한다


    * hard nofile 64000

    * soft nofile 64000


    # 특정 user (예: mysql)에기만 설정을 하려면


    mysql hard nofile 64000

    mysql soft nofile 64000




     

    이제 엘라스틱 서치 실행시 해당 설정이 반영될 수 있도록 시작 스크립트를 아래와 같이 수정합니다.

    참고로 위의 설정을 변경한 쉘에서 스크립트 실행을 해야 변경 사항이 반영이 됩니다.

     

    ./elasticsearch -Des.max-open-files=true -d

     

    마지막으로 엘라스틱 서치에 해당 설정이 반영되었나 다시 한번 확인해 봅니다.

    정상적으로 max_file_descriptors 설정이 변경된 것을 확인할 수 있습니다.

     

     curl localhost:9200/_nodes/process?pretty
    {
      "cluster_name" : "elasticsearch",
      "nodes" : {
        "l4v0yXMrRbON7YY2AU9NGg" : {
          "name" : "Khaos",
          "version" : "1.2.1",
          "build" : "6c95b75",
          "process" : {
            "refresh_interval_in_millis" : 1000,
            "id" : 22055,
            "max_file_descriptors" : 32000,
            "mlockall" : false
          }
        }
      }
    }

     

    만약 위와 같이 수정했는데도 ulimit -a에서 변경되지 않았다면 

    limits.conf는 pam_limits.so에 의해 읽히기 때문에 이 모듈이 enable되었는지 확인해 보자. 


    /etc/pam.d/su 에서 pam_limits.so가 아래와 같이 주석처리 되어있으면 주석 처리를 제거한다. 


    # Sets up user limits, please uncomment and read /etc/security/limits.conf

    # to enable this functionality.

    # (Replaces the use of /etc/limits in old login)

    # session    required   pam_limits.so


     

     

    참고:

     

    http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html

     

    http://stackoverflow.com/questions/15903105/too-many-open-files-warning-from-elasticsearch

     

     




     


     

    728x90
    반응형
Designed by Tistory.