티스토리 뷰

ElasticSearch

Elasticsearch 연동

따강아지 2023. 8. 15. 18:16

Elasticsearch는 속도, 수평적 확장성, 안정성 및 간편한 관리를 위해 설계된 선도적인 분산형 RESTful 무료 오픈 소스 검색 및 분석 엔진으로 오픈 소스로 Elasticsearch를 SpringBoot와 연동을 설명 합니다.

참고 : https://www.elastic.co/guide/index.html

 

Welcome to Elastic Docs | Elastic

 

www.elastic.co

 

1.  Elasticsearch 환경 수정

Elasticsearch를 최초 설치 하면 localhost만 접근이 되어지므로 "/bin/elasticsearch.yml"파일에 있는 Network영역의 network.host를 수정 합니다. ( 모든 ip를 받기 위해서 0.0.0.0 으로 수정 )

# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
#network.host: xxx.xxx.xxx
network.host: 0.0.0.0

2. Virtual Memory 오류 수정 

Elasticsearch를 재 실행 하면 다음과 같은 오류가 발생 합니다. 해당 오류는 가상 메모리 부족 오류

RROR: [2] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]


sudo vi /etc/sysctl.conf 으로 확인을 하면 "vm.max_map_count = 65530" 으로 확인이 됩니다. 이 값을 변경 하면 해결을 할 수 있습니다.

sudo sysctl -w vm.max_map_count=262144

 

3. Springboot의 사용자 정의 파일에 등록 

resource 폴더 밑에 사용자 정의 파일을 생성 하고 다음과 같은 속성을 정의 합니다. ( 예제 : /config/custom/el.yml )

es:									# 사용자 정의 root 
  host: 192.168.210.52				# ElasticSearch에 할당 당 ip (or 도메인 주소 )
  port: 9200						# ElasticSearch에 할당 port
  username: elastic					# ElasticSearch에 접근 할 사용자 아이디
  password: =dq2XKtp_p2DF_2QiLys 	# ElasticSearch에 접근 할 사용자 비밀번호
  schemeName: https					# ElasticSearch에 접근 할 스키마
  ssl: pwd  						# pwd, fingerprint, ca ( 인증 방법 )
  fingerprint: 190f95778c4f9b2d5247d940b9665c3494b6f930914796cc4274c432150440a7
  cadrt: C:\PRJ\xxxx\elk\http_ca.crt

사용자 아이디, 비밀번호, fingerprint와 ca 파일은 Elasticsearch 최초 설치시 나오는 메세지로 해당 부분에 있는 값을 사용자 정의 파일에 기재 합니다.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  =dq2XKtp_p2DF_2QiLys

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  190f95778c4f9b2d5247d940b9665c3494b6f930914796cc4274c432150440a7

ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjkuMCIsImFkciI6WyIxOTIuMTY4LjIxMC41Mjo5MjAwIl0sImZnciI6IjE5MGY5NTc3OGM0ZjliMmQ1MjQ3ZDk0MGI5NjY1YzM0OTRiNmY5MzA5MTQ3OTZjYzQyNzRjNDMyMTUwNDQwYTciLCJrZXkiOiJpREl6MDRrQnNoZVpNMzMxZHFzWDpYcDREZnRhLVEyMi1sejljOTNtMHJ3In0=

ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

 

'ElasticSearch' 카테고리의 다른 글

ElasticSearch Query - Aggregation  (0) 2023.09.02
ElasticSearch Query-DSL Compound queries  (0) 2023.08.30
ElasticSearch Query DSL - match, term  (0) 2023.08.30
검색 API  (0) 2023.08.29
Elasticsearch 문서 색인 / 조회  (0) 2023.08.29