Server/Elastic Search

[Elastic Search] 외부에서 Elastic Search API 사용하기 (Production mode)

cjwoov 2019. 8. 20. 15:29
반응형

개요


 기본적인 설정 값으로는 Elastic Search API를 자기 자신의 호스트(loop back address: 127.0.0.1)에서만 사용 할 수 있도록 세팅되어있다.

 

 공식 레퍼런스 문서에서는 개발용 테스트 서버로 Elastic Search를 사용하기에는 127.0.0.1로 host를 설정해도 무리가 없다고 나와있지만, 다음과 같은 경우에 호스트 주소를 바꾸어 줄 필요가 있다.

 

  • VM환경에서 Elastic Search를 설치하고 외부에서 VM Elastic Search에 접근하고자 하는 경우
  • 상용 서비스를 운영할 경우

 

설정


설정은 간단하다. 자신의 Elastic Search 설정 폴더의 elasticsearch.yml를 연다.

필자의 경우 /etc/elasticsearch/elasticsearch.yml (Elastic Search를 어떻게 설치했느냐에 따라 다르다)
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
...
...
...
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# 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: ["127.0.0.1"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
node.name 자신의 노드 이름(사용자 마음대로)
network.host 0.0.0.0
http.port 9200(Elastic Search 기본 포트)
discover.seed_hosts ["127.0.0.1"]
cluster.initial_master_nodes ["자신의 노드 이름"]

 

network.host 주소를 loopback address가 아닌 다른 주소로 바꾸면 Development mode에서 Production mode로 인식하는데, 

Production mode에서는 discover.seed_hosts, cluster.initial_master_nodes와 같은 설정을 주석 해제하여 따로 설정해주어야 한다.

 

설정을 마쳤으면 다음과 같이 Elastic Search를 재시작한다.

 

$sudo service elasticsearch restart

 

참고자료


https://www.elastic.co/guide/en/elasticsearch/reference/7.3/network.host.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.3/system-config.html#dev-vs-prod
반응형