elasticsearch cluster and traefik

개요

빅데이터 관리를 위하여 elasticsearch를 이용하던중, 기존 데이터 모델링이 1개의 인덱스 기반이여서 어쩔수 없이 노드 구성을 위해 클러스터와 traefik proxy 를 이용하여 분산 처리 하였다.

작업내용

docker-compose 파일로 간단하게 클러스터 구성을 진행 하였다.
docker-compose up -d

docker-compose.yaml

version: '3'

services:
    elasticsearch:
        restart: always
        image: elasticsearch:6.8.5
        container_name: elasticsearch
        environment:
            - node.name=elasticsearch
            - cluster.name=es-docker-cluster
            - TZ=Asia/Seoul
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - "discovery.zen.ping.unicast.hosts=elasticsearch2,elasticsearch3"
        ulimits:
            memlock:
                soft: -1
                hard: -1
            nofile:
                soft: 65536
                hard: 65536
        volumes:
            - ./elasticsearch/data:/usr/share/elasticsearch/data
        cap_add:
            - IPC_LOCK
        labels:
            - stack=elasticsearch6
            - traefik.http.routers.elasticsearch.rule=PathPrefix(`/`)
            - traefik.http.services.elasticsearch.loadbalancer.server.port=9200
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.path=/_cluster/health?local=true
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.interval=15s
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.timeout=10s
    elasticsearch2:
        restart: always
        image: elasticsearch:6.8.5
        container_name: elasticsearch2
        environment:
            - node.name=elasticsearch2
            - cluster.name=es-docker-cluster
            - TZ=Asia/Seoul
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - "discovery.zen.ping.unicast.hosts=elasticsearch,elasticsearch3"
            - "node.master=false"
        ulimits:
            memlock:
                soft: -1
                hard: -1
            nofile:
                soft: 65536
                hard: 65536
        volumes:
            - ./elasticsearch/data2:/usr/share/elasticsearch/data
        cap_add:
            - IPC_LOCK
        labels:
            - stack=elasticsearch6
            - traefik.http.routers.elasticsearch.rule=PathPrefix(`/`)
            - traefik.http.services.elasticsearch.loadbalancer.server.port=9200
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.path=/_cluster/health?local=true
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.interval=15s
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.timeout=10s
    elasticsearch3:
        restart: always
        image: elasticsearch:6.8.5
        container_name: elasticsearch3
        environment:
            - node.name=elasticsearch3
            - cluster.name=es-docker-cluster
            - TZ=Asia/Seoul
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - "discovery.zen.ping.unicast.hosts=elasticsearch,elasticsearch2"
            - "node.master=false"
        ulimits:
            memlock:
                soft: -1
                hard: -1
            nofile:
                soft: 65536
                hard: 65536
        volumes:
            - ./elasticsearch/data3:/usr/share/elasticsearch/data
        cap_add:
            - IPC_LOCK
        labels:
            - stack=elasticsearch6
            - traefik.http.routers.elasticsearch.rule=PathPrefix(`/`)
            - traefik.http.services.elasticsearch.loadbalancer.server.port=9200
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.path=/_cluster/health?local=true
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.interval=15s
            - traefik.http.services.elasticsearch.loadbalancer.healthcheck.timeout=10s
    traefik:
        image: traefik:2.3
        command:
            - --entrypoints.web.address=:9200
            - --providers.docker=true
            - --providers.docker.constraints=Label(`stack`,`elasticsearch6`)
            - --api.insecure
            - --accesslog=true
        depends_on:
            - elasticsearch
            - elasticsearch2
            - elasticsearch3
        ports:
            - 9200:9200
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
    kibana:
        image: kibana:6.8.5
        container_name: log-kibana
        environment:
            - TZ=Asia/Seoul
            - ELASTICSEARCH_HOSTS="http://elasticsearch:9200"
        links:
            - "elasticsearch"
        ports:
            - "5601:5601"

결과

노드3개로 분할되어 분산 저장된다.

localhost:5601

좋은 웹페이지 즐겨찾기