Elastic Search 엘라스틱 서치 7 설치 및 Cluster 구성하기

 

Elastic Search 란?

현재 세계에서 가장 인기 있는 오픈소스 검색엔진으로 가장 널리 사용되고 있는 솔루션중 하나입니다. 이걸 데이터베이스라고 불러도 되는지는 잘 모르겠지만, 현재 DB-engines Ranking에 8위에 올라와 있을 정도로 현재는 많이 기업과 개발자들이 선택하고 있습니다. 

엘라스틱 서치는 각종 애플리케이션이나 웹의 검색 목적으로 사용을 하고, log 등을 쌓고 분석 및 시각화 하는데도 많이 사용되고 있습니다.

엘라스틱 서치에서 말하는 장점은 다음과 같습니다.

  • 빠르다
  • 분산처리
  • 다양한 기능
  • 시각화 및 분석의 간소화

 

Elastic Search 설치 및 Cluster 구성하기

엘라스틱 서치의 클러스터를 구성하면서 주의해야 할 점이 몇가지 있습니다. Master – Master 구조의 멀티 마스터 구조는 불가능하며, 액티브 마스터는 오직 1대만 가능합니다. 마스터 노드의 장애 발생시 마스터를 대체할 수 있는 마스터 후보들을 여러 대 구성할 수 있습니다. 역시 여느 오픈소스 데이터베이스들처럼 홀수로 구성하는 것을 추천합니다. 첫번째 이유는 2대만 가지고 구성한 경우 다수결에 의한 마스터 선출이 불가하기 때문입니다. 두번째, 2대만 가지고 구성한 경우 다른 오픈소스 데이터베이스들과 마찬가지로 스플릿 브레인 현상이 발생할 수 있습니다. 따라서 3대 이상 홀수로 두는 것이 바람직합니다.

 

JAVA 업그레이드

최신버전의 엘라스틱 서치를 이용하기 위해서는 JAVA 업그레이드를 우선 해야합니다.

yum install java-1.8.0-openjdk-devel.x86_64 -y

 

yum을 이용한 설치

CentOS 기준 yum을 이용한 엘라스틱 서치의 설치 과정입니다.

vi /etc/yum.repos.d/elasticsearch.repo

repo 설정

[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md

Install elasticsearch

yum install --enablerepo=elasticsearch elasticsearch

이렇게 간단한게 설치가 끝납니다.

클러스터 구성은 kibana가 같이 설치될 Master 노드 1대, Data 노드 3대로 구성했습니다.

selinux/config 는 disabled 처리 해주시구요. 클러스터를 구성할 것이니 특별히 외부망에 접속되는 서버가 아니라면 firewalld도 죽이고 작업합니다.

엘라스틱 서치가 설치되고 나면 config 파일을 손을 봐야합니다.

config 파일의 경로는 /etc/elasticsearch/ 밑에 존재합니다.

root@es-master01:~]# ls -l /etc/elasticsearch/
total 40
-rw-rw----. 1 root elasticsearch   199 Mar 10 12:26 elasticsearch.keystore
-rw-rw----. 1 root elasticsearch  2956 Mar 10 15:58 elasticsearch.yml
-rw-rw----. 1 root elasticsearch  3176 Mar 10 12:50 jvm.options
drwxr-s---. 2 root elasticsearch     6 Feb 15 22:55 jvm.options.d
-rw-rw----. 1 root elasticsearch 18535 Feb 15 22:52 log4j2.properties
-rw-rw----. 1 root elasticsearch   473 Feb 15 22:52 role_mapping.yml
-rw-rw----. 1 root elasticsearch   197 Feb 15 22:52 roles.yml
-rw-rw----. 1 root elasticsearch     0 Feb 15 22:52 users
-rw-rw----. 1 root elasticsearch     0 Feb 15 22:52 users_roles

메인이 되는 설정파일은 elasticsearch.yml 이고, 메모리를 조정하기 위해 수정하는 파일은 jvm.options 입니다.

elasticsearch.yml파일 안에 있는 파라미터들을 몇가지 살펴 보겠습니다.

  • cluster.name: 엘라스틱 서치 클러스터의 이름을 정합니다.
  • node.name: 엘라스틱 서치의 노드 이름을 나타냅니다. ${HOSTNAME} 으로 서버의 호스트네임을 가져다 쓸 수 있습니다.
  • path.data: 데이터가 저장 되는 경로입니다.
  • path.logs: 엘라스틱 서치의 로그가 기록되는 경로입니다.
  • bootstrap.memory_lock: 옵션의 주석을 제거하고 true로 설정하면 자바 가상 머신위에서 실행중인 엘라스틱 서치가 점유하는 메모리를 고정시킵니다. 메모리 부족을 방지 할 수 있기에 true 설정을 하는 것을 권장합니다.
  • network.bind_host: 엘라스틱 서치 서버의 내부 IP를 기입하는 곳입니다.
  • network.public_host: 엘라스틱 서치 서버의 외부 IP를 기입하는 곳입니다.
  • network.host: bind_host와 public_host를 동시에 설정에 적용할 수 있습니다.
  • discovery.seed_hosts: 엘라스틱 서치 클러스터에 포함 되는 노드들의 배열입니다. [“192.168.0.76”, “192.168.0.90”,”192.168.0.98″,”192.168.0.101″] 이런식으로 기입합니다.
  • cluster.initial_master_nodes: 엘라스틱 서치의 클러스터의 마스터 노드 그룹을 지정하는 배열을 삽입합니다. Master 노드와 후보 노드들을 기입합니다.
  • node.master: 해당 노드를 Master로 쓸 것인지 여부를 결정합니다. true or false
  • node.data: 해당 노드를 Data 노드로 쓸 것인지 여부를 결정합니다. true or false
  • node.ingest: 데이터 색인시 전처리 작업인 ingest pipleline 작업의 수행을 할 수 있는지 여부를 지정합니다. false인 경우 이 노드에서는 ingest pipeline 작업의 실행이 불가능합니다. true or false
  • node.ml: 해당 노드를 머신러닝에 쓸 것인지 여부를 결정합니다. true or false

jvm.options를 살펴보겠습니다.

################################################################
## 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:
##
-Xms4g
-Xmx4g

이렇게 생긴 부분이 있습니다. JVM heap 사이즈를 결정하는 부분인데, 값이 2개 있는 이유는 최소값과 최대값입니다.

저는 마스터 노드의 물리 램사이즈를 8G, 데이터 노드의 램 크기를 16G로 주고 생성했기 때문에

  • Master 노드 -Xmx4g
  • data 노드 -Xmx8g

이렇게 설정했습니다.

Master 노드의 config 설정 예제

# ======================== 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: es-test
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: ${HOSTNAME}
node.master: true
node.data: false
#
# 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: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- 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: 10.100.170.61
#
# Set a custom port for HTTP:
#
http.port: 9200
transport.tcp.port: 9300
#
# 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: ["10.100.170.61"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["10.100.170.61"]
#
# 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

Data 노드의 config 설정 예제

# ======================== 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: es-test
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: ${HOSTNAME}
node.master: false
node.data: true
#
# 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: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- 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: 10.100.170.62
#
# Set a custom port for HTTP:
#
http.port: 9200
transport.tcp.port: 9300
#http.enabled: false

#
# 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: ["10.100.170.61","10.100.170.62","10.100.170.73","10.100.170.76"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["10.100.170.61"]
#
# 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

 

이렇게 설정한 뒤에 systemctl start elasticsearch 명령으로 엘라스틱 서치를 구동합니다.

 

상태 확인

구동이 완료되면 노드의 상태와 클러스터의 상태를 체크해 봅니다.

노드 상태 확인

root@es-master01:~]# curl http://10.100.170.61:9200
{
  "name" : "es-master01",
  "cluster_name" : "es-cluster",
  "cluster_uuid" : "iVTgtDQ0T92Px4PHxXS3ow",
  "version" : {
    "number" : "7.11.1",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "ff17057114c2199c9c1bbecc727003a907c0db7a",
    "build_date" : "2021-02-15T13:44:09.394032Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

클러스터 상태 확인

root@es-master01:~]# curl http://10.100.170.61:9200/_cluster/health?pretty
{
  "cluster_name" : "es-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 4,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

이것으로 엘라스틱 서치의 클러스터 구성이 완료 되었습니다.

 

플러그인 설치

한글 형태소 검색을 위한 Nori 플러그인 설치

es-master-01:~]# elasticsearch-plugin install analysis-nori
-> Installing analysis-nori
-> Downloading analysis-nori from elastic
[=================================================] 100%   
-> Installed analysis-nori

 

ElasticSearch-head

ElasticSearch-head를 이용하여 Web 인터페이스로 엘라스틱 서치의 상태를 확인하고, Index를 생성할 수 있습니다. 6버전대까지는 plug-in으로 설치하여 사용할 수 있었습니다. 보안상의 문제로 7버전 부터는 제공되지 않는다고 하네요.

대신 크롬 확장팩으로 설치하여 사용할 수 있습니다.

ElasticSearch-head를 이용해서 엘라스틱에 접속하여, 5개의 샤드와 1개의 Replication을 가진 Index를 생성하면 아래와 같이 확인 할 수 있습니다.

이 것으로 엘라스틱 서치의 클러스터 구성을 완료하였네요. 다음 포스팅에서는 kibana의 설치 및 세팅을 진행해보겠습니다.

 

 

 

소셜 미디어로 공유하기

You may also like...

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

 

새 블로그로 이사갑니다.

 

rastalion.dev

 

도메인 변경했어요. 현재 지속적으로 개선 중입니다.

 

This will close in 10 seconds