[Elasticsearch] 엘라스틱 서치 환경설정(Bootstrap Checks)

안녕하세요.

 

지난 포스팅에서는 엘라스틱서치를 설치하여 curl 명령어로 내부 루프백 주소 키워드인 localhost로 요청하여 응답을 받아보았습니다.

https://sas-study.tistory.com/492

 

[Elasticsearch] 엘라스틱 서치 설치하기

안녕하세요. 이전 포스팅이 대부분 Google Cloud VM 인스턴스에 관한 내용이었을텐데요. 포스팅도 포스팅이지만 사실은 엘라스틱서치를 학습하기 위해서 (로컬에 해도됩니다만 지저분해지는걸 싫

sas-study.tistory.com

 

우선 위의 포스팅에서는 엘라스틱서치가 Development 모드로 동작하여 외부에서의 요청은 받지 못하는 상태입니다. 이번에는 외부에서 요청을 받을 수 있도록 설정을 해보고 그로 인해 진행하는 Bootstrap cheks에서 발생하는 실행 문제를 해결해나가보도록 하겠습니다.


 

 

Bootstrap Checks를 하는 이유

우선 Bootstap Checks를 하는 이유는 아래의 페이지에 잘 설명되어있습니다. 저는 이를 간단히 요약만하고 환경설정에 집중하고자 합니다.

https://www.elastic.co/guide/en/elasticsearch/reference/7.11/bootstrap-checks.html#bootstrap-checks

 

Bootstrap Checks | Elasticsearch Guide [7.11] | Elastic

Collectively, we have a lot of experience with users suffering unexpected issues because they have not configured important settings. In previous versions of Elasticsearch, misconfiguration of some of these settings were logged as warnings. Understandably,

www.elastic.co

이전 버전의 Elasticsearch에서는 중요한 설정을 구성하지 않아 예기치 않은 문제가 발생하는 사용자가 많았습니다. 그래서 Elasticsearch는 Bootstrap Checks를 제공하여 중요한 설정이 구성되지 않았을 때 Elasticsearch가 시작되지 않도록 보장합니다. 부트스트랩 체크는 Elasticsearch 및 시스템 설정을 검사하고 안전한 값과 비교하여 Elasticsearch 운영에 안전하지 않은 경우 경고 메시지를 로그에 남기거나 프로덕션 모드에서는 Elasticsearch가 시작되지 않도록합니다. 일부 부트스트랩 체크는 호환되지 않는 설정으로 Elasticsearch가 실행되지 않도록 항상 강제로 적용됩니다.

쉽게 풀자면, Elasticsearch를 운영하는 측에서는 이전에 elasticsearch 사용자로부터 어떠한 시스템 환경 이슈를 로그형태로써 보여줬지만 이를 알아채지 못하는 사용자로 인해서 운영환경에서 크리티컬한 이슈들을 마주쳤고 근본적으로 시스템 환경 이슈를 마주치지 않을만한 그들만의 허용 가능한 스펙을 정해 이를 사용자의 elasticsearch 실행 환경과 비교하는 로직을 elasticsearch를 production 모드로 실행할 때 체크하도록 하고 이를 통과해야만 실행이 가능하도록 하였다는 것 같습니다.

 


위의 내용을 토대로 알 수 있는 것은 현재 설치된 elasticsearch는 development 모드로 실행중이니 외부에서 네트워크 호출을 통해 호출할 수 없습니다. 그런데 이를 production 모드로 변경하면 bootstrap checks를 통해 실행을 할 수 없는 상태가 됩니다. 따라서 이를 실행 가능한 상태로 서버 시스템 설정을 변경해주어야 합니다. 

뭔가 좀 내용이 많이 복잡하니 우선 production 모드로 실행되도록 해보겠습니다.

 

우선 elasticsearch 가 설치된 서버에 접속하여 elasticsearch가 설치된 디렉토리로 접근해보겠습니다. 그 중 config 폴더 안에 elasticsearch.yml 이라는 파일을 한번 열어보겠습니다.

 

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

위의 여러가지 섹션들 중에서 Network 섹션을 살펴볼 필요가 있어보입니다. 

여러가지 환경변수들이 설정될 수 있겠지만 주석처리되어있는 두가지 옵션을 한번 살펴보겠습니다.

- network.host : 엘라스틱서치가 바인딩할 주소를 설정합니다. 기본적으로 루프팩 주소인 127.0.0.1로 바인딩 됩니다.

- http.port : http 통신을 할 port 번호를 지정합니다. 설정되지 않았다면 9200 포트로 설정됩니다.

 

 

http.port 옵션은 9200 포트로 사용할 것이기 때문에 별도로 custom하지는 않겠습니다.(운영하는 목적으로 설치한다면 당연히 다른 포트로 설정하셔야 합니다.)

 

network.host는 엘라스틱 서치가 루프백 주소가 아닌 GCP의 내부 IP로 호출이 가능하도록 GCP의 내부 IP를 등록해보겠습니다.

network.host: 10.178.0.9

이렇게 설정을 하고 저장한뒤 elasticsearch를 실행해보겠습니다.

 

[2023-03-04T07:41:57,815][INFO ][o.e.b.BootstrapChecks    ] [blackdog-elastic-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /home/wsh0821/elasticsearch-7.11.1/logs/elasticsearch.log
[2023-03-04T07:41:57,869][INFO ][o.e.n.Node               ] [blackdog-elastic-1] stopping ...
[2023-03-04T07:41:57,887][INFO ][o.e.n.Node               ] [blackdog-elastic-1] stopped
[2023-03-04T07:41:57,887][INFO ][o.e.n.Node               ] [blackdog-elastic-1] closing ...
[2023-03-04T07:41:57,905][INFO ][o.e.n.Node               ] [blackdog-elastic-1] closed

 실행이 잘 되는듯 싶었으나 위와 같은 에러메시지를 만나게 되었습니다. 이제 elasticsearch를 development 모드가 아닌 production 모드로 실행하게 된 것입니다.

내용을 찬찬히 보면 세가지 체크사항에서 걸린 것을 확인할 수 있습니다.

1. max file descriptors 4096 is too low, increase to at least 65535 :

 -> max file descriptors 라는 설정이 너무 낮으니 올려라.

2. max virtual memory areas vm.max_map_count 65530 is too low, increase to at least 262144 :

 -> 최대 가상메모리 영역의 vm.max_map_count 설정이 너무 낮으니 올려라.

3. the default discovery settings are unsuitable for production use; at least one of[discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured :

 -> 기본 설정이 미흡하니 세가지 옵션중 하나는 설정해놔라


여러 Bootstrap Checks 중에서 3가지에 걸려버렸습니다. 이 세가지만 해결하면 일단 production 모드로 실행하여 외부에서도 elasticsearch에 요청할 수 있도록 만들 수 있을 것 같습니다.

 

1번부터 차례대로 해결해나가 보겠습니다.

 

Max File Descriptors 옵션 값 증가시키기

해당 옵션을 elasticsearch 공식 레퍼런스에서 서칭하여 아래의 링크를 찾았습니다.

https://www.elastic.co/guide/en/elasticsearch/reference/7.11/setting-system-settings.html#limits.conf

 

Configuring system settings | Elasticsearch Guide [7.11] | Elastic

Ubuntu and limits.conf Ubuntu ignores the limits.conf file for processes started by init.d. To enable the limits.conf file, edit /etc/pam.d/su and uncomment the following line: # session required pam_limits.so

www.elastic.co

그중 /etc/security/limits.conf 파일에 어떤 설정값을 넣어주면 된다는 내용이 있습니다. 이는 공식문서에서 서버 설정을 영구적으로 변경하는 부분이라고 나와있으니 이를 따라가보도록 하겠습니다.

 

아래의 내용을 해당 파일에 기재하라고 합니다.

elasticsearch  -  nofile  65535

이중에서 elasticsearch라는 이름은 서버에 접속한 유저 이름이니 이는 각자 확인해주시기 바랍니다.

 

/etc/security/limits.conf 파일은 관리자 파일이니 sudo 명령어로 수정해줍니다.

sudo vi /etc/security/limits.conf

명령어 입력 후, 파일에 아래 내용 기재

wsh0821  -  nofile  65535

이제 설정이 마무리됐는지 확인하기위해 elasticsearch를 실행해보려고 하였으나 해당 설정은 서버를 재시작하여야 적용이 된다길래 우선 아래의 내용들을 다 설정해놓고 재시작하도록 하겠습니다.

 

vm.max_map_count 옵션 값 증가시키기

해당 옵션에 관한 내용은 아래의 공식문서에서 확인이 가능합니다.

https://www.elastic.co/guide/en/elasticsearch/reference/7.11/vm-max-map-count.html

 

Virtual memory | Elasticsearch Guide [7.11] | Elastic

Elasticsearch uses a mmapfs directory by default to store its indices. The default operating system limits on mmap counts is likely to be too low, which may result in out of memory exceptions. On Linux, you can increase the limits by running the following

www.elastic.co

file descriptors 처럼 서버에 영구적으로 반영하기 위해서는 /etc/sysctl.conf 파일을 수정해주어야 합니다. 해당 파일을 열어서 아래의 내용을 기재해주도록 하겠습니다. 해당 파일은 역시 관리자 권한이기 때문에 sudo 명령어로 열겠습니다.

 

sudo vi /etc/sysctl.conf

명령어 입력 후, 파일에 아래 내용 기재

vm.max_map_count=262144

마찬가지로 해당 내용도 서버에 영구적으로 반영하기 위해서는 서버를 재시작해야합니다. 따라서 우선 아래의 내용을 먼저 설정한 뒤 재시작하겠습니다.

 

discovery 설정하기

해당 설정을 하기 위해서는 엘라스틱서치의 config 폴더내에 elasticsearch.yml 파일을 수정해야합니다. 위에서 이미 network.host 옵션을 통해서 ip 설정을 해놓았을텐데요. 여기에 추가적으로 아래의 설정들을 추가해주어야 합니다.

 

cluster.name: "blackdog-elastic"
node.name: "blackdog-elastic-node-1"
network.host: ["10.178.0.9"]
discovery.seed_hosts: ["blackdog-elastic-1"]
cluster.initial_master_nodes: ["blackdog-elastic-node-1"]

network.host 옵션을 제외한 네가지 옵션을 추가해줍니다.

- cluster.name : cluster란 엘라스틱서치의 실행 그룹입니다. 어떤 실행 그룹에 종속될지 기재합니다. 실행중인 cluster가 없으면 스스로 cluster를 구성하여 single node로 구동합니다.

- node.name : node란 엘라스틱 서치 어플리케이션 하나를 의미합니다. node 단위로 실행되긴하지만 운영단위는 cluster이기 때문에 node의 이름을 기재하여 cluster가 자신의 하위 노드들을 알 수 있도록 합니다.

- discovery.seed_hosts : 엘라스틱서치가 실행할 때 Discovery라는 과정을 거쳐 실행하는데, 이는 클러스터가 될 노드들을 찾아다니는 행위입니다. 여기에 클러스터링할 노드를 최소한 기재해주어야 production 모드로 실행할 수 있습니다. 저는 현재 single node로 실행할 것이기 때문에 현재 엘라스틱 서치가 실행중인 서버의 hostname을 적어주겠습니다.(hostname을 알 수 있는 방법은 명령어로 hostname을 치면 됩니다.)

- cluster.initial_master_nodes : 엘라스틱 서치는 n개의 노드를 클러스터링을 할 때, 마스터 노드와 데이터 노드로 구분됩니다. 이때 여기에 기재되는 노드들이 마스터 노드 후보가되어 노드 클러스터링을 관리합니다. 따라서 single node cluster로 실행할 예정이기 때문에 node.name 옵션에 설정된 노드 이름을 적어주도록 하겠습니다.

 

 

모든 설정을 마쳤으니 시스템 설정이 반영되도록 서버를 재시작하도록 하겠습니다. 재시작은 관리자 권한으로 아래의 명령어로 수행하였습니다.

sudo shutdown -r

이제 다시 엘라스틱서치를 시작하고 제 맥북 터미널로 해당 서버의 9200번포트에 curl로 요청을 하나 넣어보겠습니다.

 

 

외부에서 elasticsearch 정보 요청 성공

 

성공적으로 elasticsearch가 설치된 외부에서도 요청을 받아들이는 것을 확인할 수 있습니다.

 

감사합니다.


해당 스터디는 아래의 채널에서 제공해주시는 정보를 토대로 스터디하고 있음을 명시합니다.

https://www.youtube.com/@elastic7014

 

한국 Elastic 사용자 그룹

 

www.youtube.com

 

댓글

Designed by JB FACTORY