elasticsearch 7 설정


설치 자체는 쉬우나 OS level의 환경설정이나 jvm 관련 설정 내용들이 잘 정리되어 있는 문서가 없어 별도로 정리 합니다

centOS 환경에 root 권한을 가지고 있고 RPM 설치 기준으로 설명 하였습니다
.zip and .tar.gz으로 설치 했을 경우 부분적으로 설정이 적용되지 않을 수 있습니다


환경설정

  1. vi /etc/elasticsearch/elasticsearch.yml - elasticsearch.yml 파일 수정

     cluster.name: search-dev
      
     node.name: search-dev-master
     node.roles: [master, ingest]
        
     path.data: /var/lib/elasticsearch
     path.logs: /var/log/elasticsearch
        
     network.host: 0.0.0.0
     http.port: 9200
     transport.port: 9300
     transport.compress: true
        
     discovery.seed_hosts:
       - 127.0.0.1
        
     cluster.initial_master_nodes:
       - 127.0.0.1
        
     xpack.security.enabled: false
        
     # _all api index
     action.destructive_requires_name: true
        
     # 서버에 system call filter 가 설치 되지 않았을 경우 해당 filter 사용 안함으로 설정
     bootstrap.system_call_filter: false
        
     # 메모리 스왑 방지 옵션
     bootstrap.memory_lock: true
    
     # xpack security 설정 disable - 해당 설정을 하지 않으면 kibana dev tool 사용시 경고 메세지 지속적으로 나타남
     xpack.security.enabled: false
    
  2. vi /etc/elasticsearch/jvm.options - jvm.options 파일 수정

    보통 master, coordinating node 는 8GB, data node는 30GB(zero based) 설정으로 운영합니다

     ################################################################
     ## IMPORTANT: JVM heap size
     ################################################################
     ##
     ## The heap size is automatically configured by Elasticsearch
     ## based on the available memory in your system and the roles
     ## each node is configured to fulfill. If specifying heap is
     ## required, it should be done through a file in jvm.options.d,
     ## and the min and max should be set to the same value. For
     ## example, to set the heap to 4 GB, create a new file in the
     ## jvm.options.d directory containing these lines:
     ##
        
     -Xms8g
     -Xmx8g
    
  3. vi /etc/fstab - centOS swap 설정 확인 (root 권한 필요)

    elasticsearch 전용으로 운영하는 서버가 아닐 경우 swap 설정에 대한 인프라 담당자와 협의 필요

     # 명령어 입력 후 /etc/fstab 내용에 swap 관련 설정이 없어야 함
     vi /etc/fstab
    

    /etc/fstab - swap 설정이 없는 경우

     #
     # /etc/fstab
     # Created by anaconda on Sat Feb 29 12:05:47 2020
     #
     # Accessible filesystems, by reference, are maintained under '/dev/disk'
     # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
     #
     UUID=388a99ed-9486-4a46-aeb6-06eaf6c47675 /                       xfs     defaults        0 0
     ~
    
  4. vi /usr/lib/systemd/system/elasticsearch.service - elasticsearch.service Systemd 파일 수정

    LimitNPROC 항목 주석 제거 or 65535 값 변경, [Service] LimitMEMLOCK=infinity [Install] 위에 추가

     # Specifies the maximum number of processes
     LimitNPROC=65535   
    
     # Allow a slow startup before the systemd notifier module kicks in to extend the timeout
     TimeoutStartSec=75
        
     [Service]
     LimitMEMLOCK=infinity
        
     [Install]
     WantedBy=multi-user.target
    
  5. elasticsearch Systemd 파일 수정 후 서비스 reload

     # elasticsearch.service 수정 사항 시스템에 반영
     systemctl daemon-reload
        
     # [선택사항] 재부팅시 elasticsearch daemon 자동 실행 옵션 활성화
     systemctl enable elasticsearch.service
    
  6. vi /etc/sysctl.conf - /etc/sysctl.conf virtual memory, swap file, tcp 통신 복구 횟수 설정

     # swap file 설정
     vm.swappiness=1
        
     # virutal memory 설정
     vm.max_map_count=262144
        
     # [선택사항] - 클러스터 복구를 위한 TCP 통신 retry 횟수 설정 : 5번까지 시도하며, 완료시간은 6초 이내 이므로 빠르게 장애 상황을 인지 할 수 있음
     # 기본 설정은 15회이며 15회를 모두 수행하는 시간은 900초이다, 즉 클러스터 장애 상황을 900초 이후에 인지 할 수 있음
     net.ipv4.tcp_retries2=5
    
  7. /etc/sysctl.conf 수정 후 reboot

    elasticsearch 전용으로 운영하는 서버가 아닐 경우 리부팅시 인프라 담당자와 협의 필요

     reboot
    

Reference