[Elasticsearch] Elasticsearch 설치

Jaewon Lim·2025년 4월 13일

Elasticsearch

목록 보기
2/12

[버전]
8.17.4 tar
[서버]
192.168.219.159 (master) : Elasticsearch, Kibana, Logstash, CA 인증서
192.168.219.157 (data) : Elasticsearch, Metricbeat
192.168.219.158 (data) : Elasticsearch

.tar vs .rpm

리눅스에서는 실행 파일 확장자가 없다. 대신 리눅스에서 실행은 권한(permission) rwx중에 x에 해당하는 권한을 주어야한다.

tar

  • 간단하게 tar파일이란 여러 파일들을 하나의 파일로 만들어 놓은 것 이며, 이러한 tar 파일을 압축해 놓은 것이 tar.gz 이다. 따라서 .tar 파일을 풀 때에는 tar -xzvf~ 명령어를 사용하고, tar.gz를 사용하려면 먼저 압축을 풀어주고 tar -xzvf~ 명령어로 tar 파일을 풀어주면 된다.

rpm

  • 우분투에서 rpm 파일을 사용하기 위해서는 변환과정을 거쳐야하는데, 이러한 변환 과정을 ‘alien’이란 패키지를 통해 할 수 있다.
  • RPM은 별도의 컴파일 과정 없이 같은 종류의 시스템에서 패치한 부분까지를 포함한 바이너리 프로그램을 그래도 다른 시스템에서 사용하게 한다.

설치 전 환경 설정(Linux)

root 계정으로 접속 후, elastic 사용자 계정을 생성한다.
(Elasticsearch는 root 계정으로 동작하지 않지만 연습을 위함. 추가로 rpm은 tar 와 다르게 root 계정 내에서 진행 가능)

[root@localhost ~]# useradd elastic   
[root@localhost ~]# passwd elastic   // 패스워드 설정

리눅스 nano 텍스트 편집기 설치 이후 진행(sudo yum install nano)

성능 안정성 확보 및 실행 오류 방지

  1. etc/sysctl.conf수정
[root@localhost ~]# vi /etc/sysctl.conf

# sysctl.conf
vm.max_map_count=262144
vm.swappiness=1
# 커널 매개변수 적용
[root@localhost ~]# sysctl -p

vm.max_map_count = 262144
vm.swappiness = 1
  1. /etc/security/limits.conf
vi /etc/security/limits.conf

# limits.conf
elastic soft nofile 65535   
elastic hard nofile 65535
elastic soft nproc 4096
elastic hard nproc 4096
elastic soft memlock unlimited
elastic hard memlock unlimited
  1. 방화벽 포트 설정
[root@localhost ~]# firewall-cmd --list-all # 방화벽 포트 목록 확인
firewall-cmd --permanent --add-port=9200/tcp # kibana, logstash 등이 ES와 통신 클라이언트와의 통신용
firewall-cmd --permanent --add-port=9300/tcp # 노드끼리 클러스터 통신
firewall-cmd --permanent --add-port=5601/tcp # 브라우저에서 kibana 접속 
firewall-cmd --permanent --add-port=5044 # metricbeat -> logstash 데이터 수신
firewall-cmd --reload   # 방화벽 설정 재로드

❓리눅스 etc 폴더 이해하기

/etc 와 /usr/etc 디렉토리는 시스템의 부팅, 셧다운 시에 필요한 파일들과 시스템의 전반에 걸친 설정 파일들 및 초기 스크립트 파일들이 있다. 시스템에 어떠한 문제가 발생한다거나, 시스템 전체 환경에 관한 설정을 바꾸기 위해서는 이들 디렉토리 내에 포함되어 있는 파일들에 대하여 잘 알아야한다.

Elasticsearch-8.17.4(tar 설치)

  1. Elasticsearch 운영 사용자 계정 접속
[root@localhost ~]$ su - elastic
[elastic@local ~]$
  1. Elasticsearch 설치
[elastic@localhost ~]$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.17.4-linux-x86_64.tar.gz
[elastic@localhost ~]$ tar -xzf elasticsearch-8.17.4-linux-x86_64.tar.gz
[elastic@localhost ~]$ cd elasticsearch-8.17.4
  1. config/elasticsearch.yml 수정 (159 서버)
[elastic@localhost elasticsearch-8.17.4]$ vi 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: test-cluster       // 클러스터 명 지정
#
# ------------------------------------ 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 -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 0.0.0.0           // 사용할 수 있는 네트워크 인터페이스 (all)
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
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.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false

Elasticsearch 실행

  1. Elasticsearch 실행

[elastic@localhost elasticsearch-8.17.4]$ ./bin/elasticsearch -d
  • -d : 백그라운드 실행 옵션
    • -d 는 tar 설치 환경에서 ES를 서버처럼 실행하기 위한 필수 옵션
    • 로그는 logs/디렉토리 파일로 기록 - 터미널을 닫아도 프로세스 계속 실행
    • 포그라운드 실행시(-d 없음) 터미널에 로그가 계속 출력. 터미널 닫으면 프로세스 종료
    • tail -f logs/test-cluster.log
      • 백그라운드 실행 시 로그 확인 가능
  1. 초기 비밀번호 및 토큰
  • Elastic 사용자 초기 비밀번호(superuser 계정용)
bin/elasticsearch-reset-password -u elastic -i
>>> elastic
  • HTTP CA 인증서 SHA-256 지문(Kibana, Logstash, Beats 등과 통신 TLS 인증용)
  • Kibana 설정을 위한 등록 토큰(Kibana 최초 연동 시 1회 사용, 30분)
    추가 노드 클러스터에 추가하기 위한 등록 토큰(다른 노드가 클러스터 참여 시, 30분)
  • 노드 붙일 때 토큰 재발급 명령어
bin/elasticsearch-create-enrollment-token -s node 
  1. Elasticsearch 상태 확인
  • HTTP 통해 확인
# Elasticsearch -> https를 통해 통신
https://192.168.219.159:9200
  • curl
curl --cacert config/certs/http_ca.crt -u elastic:{$password} https://localhost:9200/_cluster/health?pretty
# {$password}에 Elasticsearch 비밀번호 입력

{
  "cluster_name" : "test-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 3,
  "active_shards" : 3,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "unassigned_primary_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
}
  • 프로세스 확인
ps -ef | grep elasticsearch

클러스터링(Clustering)

192.168.219.159 마스터노드(node-1) 설치 이후,
192.168.219.157, 192.168.219.158 데이터노드(node-2, node-3) 설치를 같은 방식으로 진행한다.

  1. node-2 클러스터 연결하여 ES 실행
./bin/elasticsearch --enrollment-token <token>   
# 데이터노드 서버(192.168.219.159)에서 발급 받은 토큰
  • 만료 시 토큰 재발급
[elastic@localhost elasticsearch-8.17.4] $ bin/elasticsearch-create-enrollment-token -s node 
  1. Elasticsearch cluster 와 node health 체크
  • cluster check(클러스터 전체의 상태 체크)
    - 클러스터가 잘 연결 되었는지?
    - 노드 간 통신/인증 문제가 없는지?
    - 샤드가 제대로 배포되었는지?
    - 구성 완료 + 안정적인 상태인지 최종 검증

    curl --cacert config/certs/http_ca.crt -u elastic:elastic https://localhost:9200/_cluster/health?pretty
    {
     "cluster_name" : "test-cluster",
     "status" : "green",
     "timed_out" : false,
     "number_of_nodes" : 3,
     "number_of_data_nodes" : 3,
     "active_primary_shards" : 3,
     "active_shards" : 6,
     "relocating_shards" : 0,
     "initializing_shards" : 0,
     "unassigned_shards" : 0,
     "unassigned_primary_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
    }
  • node check(클러스터에 참여 중인 모든 노드의 상세 목록)

    • 모든 노드가 실제로 연결 되었는지 확인

    • IP 주소 확인 → 어떤 서버가 어떤 노드인지 매칭

    • 어떤 노드가 마스터인지 확인(* 로 확인가능)

      curl --cacert config/certs/http_ca.crt -u elastic:elastic https://localhost:9200/_cat/nodes?v
      ip              heap.percent ram.percent cpu load_1m load_5m load_15m node.role   master name
      192.168.219.159           10          84   0    0.00    0.00     0.00 cdfhilmrstw *      node-1
      192.168.219.157            4          86   0    0.05    0.02     0.00 cdfhilmrstw -      node-3
      192.168.219.158           11          85  30    0.56    0.14     0.05 cdfhilmrstw -      node-2
      

0개의 댓글