Install ElasticSearch with docker

By | 2020년 8월 22일
Table of Content

Install ElasticSearch with docker

참조

두 개 이상의 서버 인스턴스간의 클러스터 구성은 Docker Swarm 을 이용해야 한다고 합니다.

선행작업

Install ElasticSearch

mkdir elasticsearch
cd elasticsearch

# docker v19 부터 volume 명령 사용가능
docker volume create --name=es01_data
docker volume create --name=es02_data
docker volume ls

sudo sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" | sudo tee -a /etc/sysctl.conf

vi docker-compose.yml
version: '2.2'

volumes:
  es01_data:
    external: true
  es02_data:
    external: true

services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-cluster
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01
      - network.host=0.0.0.0
      - http.cors.enabled=true
      - http.cors.allow-origin=*
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es01_data:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300
    restart: always

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=es-cluster
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01
      - network.host=0.0.0.0
      - http.cors.enabled=true
      - http.cors.allow-origin=*
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    depends_on:
      - es01
    volumes:
      - es02_data:/usr/share/elasticsearch/data
    ports:
      - 9201:9200
      - 9301:9300
    restart: always
docker-compose up -d

docker container logs es01
docker container logs es02

# docker-compose stop
# docker-compose start
# docker-compose down

curl -X GET "localhost:9200"
curl -X GET "localhost:9201"
curl -XGET "localhost:9200/_cat/health?v&pretty"

댓글 남기기