TechNote

일라스틱서치 설치하기

참조 링크

https://www.elastic.co/guide/en/elasticsearch/reference/current/targz.html

실행화일 직접 다운로드하여 설치

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.15.2-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.15.2-linux-x86_64.tar.gz.sha512
shasum -a 512 -c elasticsearch-8.15.2-linux-x86_64.tar.gz.sha512 
tar -xzf elasticsearch-8.15.2-linux-x86_64.tar.gz
cd elasticsearch-8.15.2/ 

압축을 풀고 실행하기

./bin/elasticsearch

데비안 패키지로 설치

다운로드 한다.

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

Installing from the APT repository

sudo apt-get install apt-transport-https
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
sudo apt-get update && sudo apt-get install elasticsearch
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
sudo systemctl status elasticsearch

확인하기

curl http://localhost:9200

{
  "name" : "ji4197-B648",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "MHe_7itvTNO_Y-d-I7ZALQ",
  "version" : {
    "number" : "7.17.24",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "fcf25fff740db6ab3ed5d145c58d70e4c3528ea7",
    "build_date" : "2024-09-05T07:34:51.812485320Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.3",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

이렇게 나오면 성공
그렇지만 도커이면 실패

sudo nano /etc/elasticsearch/elasticsearch.yml

network.host
network.bind_host <- 이부분을 추가해야할지도 모름.

호스트를 찾지 못해서 시작이 않됨. 에러.
그렇다고 fscrowler를 도커가 아닌 것으로 실행하면
자바호환성이 문제가 됨.

도커와 로컬서버를 혼용할 경우 엘라스틱에서 문제가 생김
엘라스틱을 도커로 실행하고
터미널에서 localhost:9200하면 Access Denied됨
도커안에서의 localhost와 터미널에서 알아먹는 localhost는 다른 것임.

127.0.0.1 도 마찬가지

도커안의 /etc/elasticsearch/elasticsearch.yaml 화일안에서 network.host를 바꾸어도 오로지 localhost나 127.0.0.1만 허용될 뿐 않됨.

차라리 전부다 도커로 하는 것이 나을 수도 있음.

도커로 진행하는 경우를 찾아봄

일단 docker-compose up 진행하면 잘 되는 것 같음.

이곳에 있는 샘플 소스를 가져와서 살펴보면

https://github.com/dadoonet/fscrawler/tree/master

이것을 변형해서 nginx-lucee로 검색환경을 만들어야 함.

폴더 구조는 이곳에서 설명하고 있음

https://fscrawler.readthedocs.io/en/latest/installation.html#using-docker

설치화일 다운로드하여 실행

참고: https://www.elastic.co/guide/en/elasticsearch/reference/current/run-elasticsearch-locally.html

다른 것 다 필요없고 그냥 공식싸이트에서 제공하는 스크립트로 다운로드하여 실행하면 패스워드도 랜덤으로 자동으로 만들고 도커 컴포즈로 일리스틱과 키바나를 띄운다. 시간이 좀 걸린다.

curl -fsSL https://elastic.co/start-local | sh

실행한 폴더 아래 elstic-start-local이라는 폴더가 생기고 이 곳에 .env화일 docker-composer.yml이 생긴다.
그리고 도커펌포즈를 실행하고 여러 폴더를 만든다음 컨테이너 마다 세팅이 들어간다.
키바나 세팅이 시간이 의외로 많이 걸린다.

실행이 끝나면 .env 화일이 생기고 그 곳안에 “elatic” 유저의 비번과 키바나 비전이 적혀 있다.

curl 사용하려면 API KEY 가 필요하다.

.env 화일에 있는 내용을 메모리에 올리려면

source .env 

그리고 다음과 같이 curl을 실행할 수 있다.

curl $ES_LOCAL_URL -H "Authorization: ApiKey ${ES_LOCAL_API_KEY}"
{
  "name" : "8ce5f8a04d1b",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "NjktVDYSTYKzE9PfjCVB5Q",
  "version" : {
    "number" : "8.15.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "98adf7bf6bb69b66ab95b761c9e5aadb0bb059a3",
    "build_date" : "2024-09-19T10:06:03.564235954Z",
    "build_snapshot" : false,
    "lucene_version" : "9.11.1",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

그 다음 크롤러가 9200 포트로 자료를 보낼 수 있도록 세팅해야 한다.

한국어 가이드 북

https://esbook.kimjmin.net/

Elastic Search multinode with Docker

https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.