[Elasticsearch] Docker Compose 구성 하기

Elastic/Elasticsearch 2020. 4. 2. 07:49

Elasticsearch 를 Single Node 로 구성 하기 위한 docker-compose.yml 내용을 살펴 봅니다.

 

참고문서)

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

 

docker-compose.yml)

version: '2.2'
services:
  ${ES-SERVICE-NAME}:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
    container_name: ${ES-SERVICE-NAME}
    environment:
      - node.name=${NODE-NAME}
      - cluster.name=${CLUSTER-NAME}
      - discovery.type=single-node
      - discovery.seed_hosts=${NODE-NAME}
      - path.data=/usr/share/elasticsearch/data
      - path.logs=/usr/share/elasticsearch/logs
      - bootstrap.memory_lock=true
      - http.port=9200
      - transport.port=9300
      - transport.compress=true
      - network.host=0.0.0.0
      - http.cors.enabled=false
      - http.cors.allow-origin=/https?:\/\/localhost(:[0-9]+)?/
      - gateway.expected_master_nodes=1
      - gateway.expected_data_nodes=1
      - gateway.recover_after_master_nodes=1
      - gateway.recover_after_data_nodes=1
      - action.auto_create_index=true
      - action.destructive_requires_name=true
      - cluster.routing.use_adaptive_replica_selection=true
      - xpack.monitoring.enabled=false
      - xpack.ml.enabled=false
      - http.compression=true
      - http.compression_level=3
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nproc:
        soft: 1024000
        hard: 1024000
      nofile:
        soft: 1024000
        hard: 1024000
    sysctls:
      net.core.somaxconn: 65000
    healthcheck:
      test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cat/health || exit 1"]
      interval: 30s
      timeout: 30s
      retries: 3
    restart: always
    volumes:
      - ${NAMED-VOLUME-DATA}:/usr/share/elasticsearch/data:rw
      - ${NAMED-VOLUME-LOG}:/usr/share/elasticsearch/logs:rw
#      - ${FULL-PATH-DATA}:/usr/share/elasticsearch/data:rw
#      - ${FULL-PATH-LOG}:/usr/share/elasticsearch/logs:rw
    ports:
      - 9200:9200
      - 9300:9300
    expose:
      - 9200
      - 9300
    networks:
      - ${NETWORK-NAME}

volumes:
  ${NAMED-VOLUME-DATA}:
    driver: local
  ${NAMED-VOLUME-LOG}:
    driver: local

networks:
  ${NETWORK-NAME}:
    driver: bridge

 

Single Node 로 구성 하기 위해 중요한 설정은

- environment: 섹션에서 discovery.type=single-node 

입니다.

 

만약, Clustering 구성을 하고 싶다면 위 설정을 제거 하고 아래 세개 설정을 작성 하시면 됩니다.

- cluster.initial_master_nodes=# node 들의 private ip 를 등록 합니다.
- discovery.seed_hosts=# node 들의 private ip 를 등록 합니다.

- network.publish_host=# 컨테이너가 떠 있는 host 의 private ip 를 등록 합니다.

 

path.data 에 대한 구성을 복수로 하고 싶으실 경우

- volumes: 섹션에서 named volume 을 여러개 설정 하시거나

- bind mount 설정을 구성 하셔서 

적용 하시면 됩니다.

 

위 docker-compose.yml 을 기준으로 single node 구성과 cluster 구성을 모두 하실 수 있습니다.

 

  • ${....} 는 변수명 입니다.
    • 본인의 환경에 맞춰 작명(?) 하셔서 변경 하시면 됩니다.
: