Elasticsearch 외부와 통신 가능하게 하기

magnae2016·2021년 11월 7일

작심삼일 ELK Stack

목록 보기
2/5

elasticsearch.yml 설정 파일

elasticsearch.yml 파일은 Elasticsearch 구축에 가장 중요한 환경 설정 파일이다.

elasticsearch.yml 파일 위치

elasticsearch-7.15.1/config/elasticsearch.yml

elasticsearch.yml 파일 내 Network 영역 살펴보기

# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
#network.host: 192.168.0.1
#
# 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.
#

Network 영역은 Elasticsearch 애플리케이션이 외부 혹은 노드 간의 통신에서 사용하게 될 IP주소를 설정할 수 있는 항목이다.

network.host에는 Elasticsearch 애플리케이션이 사용하게 될 IP 주소를 설정한다.

network.host는 network.bind_hostnetwork_publish_host 두개로 나눌 수 있다.
network.host에 설정하면 내부적으로는 network.bind_host와 network_publish_host 두 개가 같은 값으로 설정되는 관계라고 보면 된다.

  • network.bind_host: 클라이언트의 요청을 처리하기 위한 IP 설정
  • network.publish_host: 클러스터 내부의 노드 간의 통신에 사용하기 위한 IP 설정

elasticsearch.yml 파일 수정

외부와의 통신을 위해 노드 내에 있는 모든 IP를 사용할 수 있도록 설정해보자.

# ---------------------------------- 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 # 변경
# CORS 설정 추가
http.cors.enabled: true
http.cors.allow-origin: "*"
#
# 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 영역에 추가로 설정한다.

# --------------------------------- 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"]
discovery.type: single-node # 추가
#
# 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.
#

단일 노드 클러스터 실행 시, discovery.typesingle-node 로 설정하지 않으면 아래와 같은 에러와 함께 Elasticsearch를 실행할 수 없다.

ERROR: [2] bootstrap checks failed.
bootstrap check failure [2] of [2]: 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

Elasticsearch 재실행

./bin/elasticsearch

curl 명령으로 접속 확인하기

curl 명령으로 접속 확인하기


참고 자료

profile
작심삼일 무한 루프 ♾️

0개의 댓글