다양한 OS에서 더 쉽게 설치, 테스트, 배포하기 쉽도록 Docker로 설치하는 법을 정리한다. 정리한 내용이 정확하지 않다면 공식 사이트를 참고해도 좋을 것 같다. https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
Install Elasticsearch with Docker | Elasticsearch Reference [7.4] | Elastic
The container runs Elasticsearch as user elasticsearch using uid:gid 1000:1000**. Bind mounted host directories and files must be accessible by this user, and the data and log directories must be writable by this user.
www.elastic.co
Ubuntu 18.04에 설치하는 방법이 궁금하다면 아래 링크를 참고하자. https://blog.ikay.cf/42
Elasticsearch 7.4.2를 Ubuntu Server 18.04에 설치하기
Elasticsearch 7.4.2를 Ubuntu Server 18.04에 설치할 일이 생겨서 정리해본다. 블로그 설명이 정확하지 않다면 설치 방법은 공식사이트(https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.ht..
blog.ikay.cf
1. Pull elasticsearch docker image
아래와 같이 입력해서 docker image를 pull 한다.
$ docker pull docker.elastic.co/elasticsearch/elasticsearch:7.4.2
2. docker로 node 1개 실행
아래와 같이 입력하면 elasticsearch가 1개 실행된다.
$ docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.4.2
3. Docker compose 해서 node 3개 실행
a. 아래와 같이 예제 `docker-compose.yml`을 만든다.
# docker-compose.yml
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /Users/kay/works/elasticsearch/data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /Users/kay/works/elasticsearch/data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /Users/kay/works/elasticsearch/data03:/usr/share/elasticsearch/data
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: bridge
이 예제 docker-compose로 3개의 node를 가진 elasticsearch cluster를 띄운다. docker-compose.yml에 대해 조금 설명을 하면 다음과 같다.
es01(node #1)은 localhost:9200를 listen 하고 es2(node #2), es3(node #3)과 Docker network(elastic)를 통해 통신한다.
es01는 volumes를 container '밖(맥북):안'을 '/Users/kay/works/elasticsearch/data01:/user/share/elestricsearch/data'로 연결하고 있다. es02, es03도 비슷하게 말이다.
b. Docker engine이 최소한 memory를 4GB를 사용하도록 할당한다.
c. docker-compose 실행
$ docker-compose up
d. node 상태 확인
아래와 같이 curl 해서 node 3개가 cluster에 정상적으로 올라왔는지 확인한다.
$ curl -X GET "localhost:9200/_cat/nodes?v&pretty"
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.22.0.2 14 80 1 0.02 0.05 0.07 dilm - es03
172.22.0.4 27 80 1 0.02 0.05 0.07 dilm * es01
172.22.0.3 14 80 1 0.02 0.05 0.07 dilm - es02
4. 결론
docker로 elasticsearch를 설치하는 것이 ubuntu에 직접 설치하는 것보다 더욱 쉽고 빠르다. 후에 배포 환경에서 elasticsearch를 사용해야 할 경우에도 docker를 이용해 쉽게 scale 확장/축소를 쉽게 할 수 있을 것으로 기대된다.
실제로 elasticsearch를 배포 환경에 사용하는 것을 고려하기 위해서는 docker 설정 등과 elasticsearch의 node, cluster 등의 구성 등을 많이 고민해야 할 것 같다.
일단 이것으로 multiple node를 갖는 elasticesearch cluster를 테스트할 수 있는 환경은 갖추게 된 것 같다.
'Elastic Stack' 카테고리의 다른 글
Elasticsearch, Cluster는 어떻게 구성돼 있을까? (0) | 2019.12.27 |
---|---|
Elasticsearch, 효율적인 index 보관을 위해 Hot-Warm architecture 도입 (0) | 2019.12.20 |
Elasticsearch-7.5.0, data backup, snapshot, restore (0) | 2019.12.16 |
Elasticsearch-7.4.2, Ubuntu Server-18.04에 설치하기 (0) | 2019.11.27 |