ElasticStack

Centos7에 ElasticSearch 설치하기

Centos7에 엘라스틱 서치를 설치한다.

내가 가진 의문점은 엘라스틱 서치가 구성하고 있는 Primay shard 와 Replica Shard가 어떻게 구성되어있고 어떻게 작동하는지이다.

이부분을 해결하기 위해 ES를 설치해보고 확인해본다! 직접 실행도 해볼 것이다.

  1. java -version
    ES는 자바 기반으로 개발되어있어서 자바가 설치되어있어야 한다.

    java -version
  2. yum 을 이용해 설치할 경우에는, 저장소를 따로 추가해줘야 한다.

    sudo vi /etc/yum.repos.d/elasticsearch.repo

    파일을 생성하고, 그리고 내용을 편집해준다.

    [elasticsearch-7.x]
    name=Elasticsearch repository for 7.x packages
    baseurl=https://artifacts.elastic.co/packages/7.x/yum
    gpgcheck=1
    gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
    enabled=1
    autorefresh=1
    type=rpm-md
  3. 이후, yum을 이용해 설치해준다.

    yum install -y elasticsearch
  4. 설치완료

    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
    Creating elasticsearch group... OK
    Creating elasticsearch user... OK
    Installing : elasticsearch-7.13.2-1.x86_64                                1/1 
    ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
    sudo systemctl daemon-reload
    sudo systemctl enable elasticsearch.service
    ### You can start elasticsearch service by executing
    sudo systemctl start elasticsearch.service
    Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore
    Verifying  : elasticsearch-7.13.2-1.x86_64                                1/1 
    

Installed:
elasticsearch.x86_64 0:7.13.2-1


5. 로그 메세지에 있는 그대로 명령어를 실행해준다.

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service


 6. 에러가 발생했다.

[irteamsu@localhost ~]$ sudo systemctl start elasticsearch.service
Job for elasticsearch.service failed because the control process exited with error code. See "systemctl status elasticsearch.service" and "journalctl -xe" for details.

  1. 정말 열심히 검색하다가 알게되었다... 초기에 설정해줘야 할 파일이 있다. /etc/elasticsearch/jvm.options 파일을 찾아서
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms128m
-Xmx128m

이 내용이 보이는 곳에 상단의 2줄을 기재해준다.
메모리 관련된 파일인데, 나는 가상머신의 램 크기를 1GB를 할당해줘서 이렇게 수정했다.
관련된 내용은 하단의 링크에서 확인해보고, 본인 환경을 확인 후 수정해주자.
https://stackoverflow.com/questions/58656747/elasticsearch-job-for-elasticsearch-service-failed

  1. 이후,
    sudo nano /etc/elasticsearch/elasticsearch.yml
    파일을 수정한다.
    다음의 5가지 항목의 주석을 해제 후
node.name:node-1
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
cluster.initial_master_nodes: ["node-1"]

이렇게 수정해줬다.
관련된 항목에 대한 설명은 이후 게시글에서 하겠다!
사실 조금 더 상세한 설정이 필요하다.

  1. 서비스 시작

    sudo systemctl start elasticsearch.service
  2. 설치 확인 !!

    [irteamsu@localhost ~]$ curl -X GET 'localhost:9200'
    {
    "name" : "localhost.localdomain",
    "cluster_name" : "elasticsearch",
    "cluster_uuid" : "_na_",
    "version" : {
    "number" : "7.13.2",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "4d960a0733be83dd2543ca018aa4ddc42e956800",
    "build_date" : "2021-06-10T21:01:55.251515791Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
    },
    "tagline" : "You Know, for Search"
    }

완료했다. ES까지 설치하는데, 2~3시간 정도는 걸린 것 같다.