Skip to content

Commit

Permalink
[REFACTOR] Docker-compose Elasticsearch 7.7 แบบ Clustering และ XPACK
Browse files Browse the repository at this point in the history
  • Loading branch information
wdrdres3qew5ts21 committed May 30, 2020
1 parent 54c212f commit f473d77
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ HELP.md
*.iml
*.ipr

/nodes

## firebase
/Microservice/UserService/meetu-firebase-key.json
/Microservice/**/meetu-firebase-key.json
Expand Down
45 changes: 45 additions & 0 deletions docker-compose-elastic-old.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3.3'
services:
elasticsearch:
# Project MeetU ใช้ Version นี้ซึ่งเป้นตัวเก่า
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
container_name: elasticsearch1
restart: always
environment:
- node.name=elasticsearch1
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms256M -Xmx256M"
- http.cors.enabled=true
- http.cors.allow-origin=*
- network.host=_eth0_
volumes:
- .:/usr/share/elasticsearch/data
networks:
- elastic
# - ingress
ports:
- 9200:9200
- 9300:9300

kibana:
image: docker.elastic.co/kibana/kibana:7.2.0
container_name: kibana
restart: always
environment:
SERVER_NAME: localhost
ELASTICSEARCH_URL: http://elasticsearch1:9200/
ports:
- 5601:5601
volumes:
- .:/your/local/path
networks:
- elastic
# - ingress

networks:
elastic:
#ingress:

volumes: # volume แบบใช้ในตัว dcoker machine ให้จัดการเอง
esdata:
106 changes: 91 additions & 15 deletions docker-compose-elastic.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,120 @@
version: '3.3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch1
restart: always
environment:
- node.name=elasticsearch1
- discovery.type=single-node
# จะทำให้มันไม่ยอมเข้าไปอยู่ใน cluster และเอาตัวเองเป้น master เสมอเลย
# - discovery.type=single-node
- cluster.name=es-docker-cluster
# เวลา scan Elasticsearch จะเช็ค Auto internal Transport Layer บน Port 9300-9305 ทันทีและรวบเข้า Cluster
# ระหว่างทางสามารถเพิ่มลดได้ตามใจชอบระบบจะ Detect เองอัตโนมัติ
- discovery.seed_hosts=elasticsearch1,elasticsearch2,elasticsearch3
- cluster.initial_master_nodes=elasticsearch1,elasticsearch2,elasticsearch3
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms256M -Xmx256M"
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- http.cors.enabled=true
- http.cors.allow-origin=*
# ผูกเข้ากับ interface คอมเราผ่าน ifconfig
- network.host=_eth0_
# หลังติดตั้งเสร็จแล้วต้องรันคำสั่ง bin/elasticsearch-setup-passwords interactive
# เพื่อให้ xpack module ที่ลงไว้ทำการตั้ง password ตามที่เราตั้งด้วยนั่นเอง
# ถ้าใช้ xpack บน cluster mode จะโดน bootstrap สั่งให้ทำ TLS ด้วยทันทีไม่งั้นจะ bootstrap ไม่ผ่าน
# - xpack.security.enabled=true
# จำเป็นต้องปิดการ swap memory เมื่อทำ cluster node เพราะว่า
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata:/usr/share/elasticsearch/data
- data01:/usr/share/elasticsearch/data
networks:
- elastic
- ingress
ports:
- 9200:9200
- 9300:9300

elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch2
restart: always
environment:
- node.name=elasticsearch2
- cluster.name=es-docker-cluster
- discovery.seed_hosts=elasticsearch1,elasticsearch2,elasticsearch3
- cluster.initial_master_nodes=elasticsearch1,elasticsearch2,elasticsearch3
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- http.cors.enabled=true
- http.cors.allow-origin=*
- network.host=_eth0_
# หลังติดตั้งเสร็จแล้วต้องรันคำสั่ง bin/elasticsearch-setup-passwords interactive
# เพื่อให้ xpack module ที่ลงไว้ทำการตั้ง password ตามที่เราตั้งด้วยนั่นเอง
# ถ้าใช้ xpack บน cluster mode จะโดน bootstrap สั่งให้ทำ TLS ด้วยทันทีไม่งั้นจะ bootstrap ไม่ผ่าน
# - xpack.security.enabled=true
# จำเป็นต้องปิดการ swap memory เมื่อทำ cluster node เพราะว่า
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic


elasticsearch3:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch3
restart: always
environment:
- node.name=elasticsearch3
- cluster.name=es-docker-cluster
- discovery.seed_hosts=elasticsearch1,elasticsearch2,elasticsearch3
- cluster.initial_master_nodes=elasticsearch1,elasticsearch2,elasticsearch3
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- http.cors.enabled=true
- http.cors.allow-origin=*
- network.host=_eth0_
# หลังติดตั้งเสร็จแล้วต้องรันคำสั่ง bin/elasticsearch-setup-passwords interactive
# เพื่อให้ xpack module ที่ลงไว้ทำการตั้ง password ตามที่เราตั้งด้วยนั่นเอง
# ถ้าใช้ xpack บน cluster mode จะโดน bootstrap สั่งให้ทำ TLS ด้วยทันทีไม่งั้นจะ bootstrap ไม่ผ่าน
# - xpack.security.enabled=true
# จำเป็นต้องปิดการ swap memory เมื่อทำ cluster node เพราะว่า
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic

kibana:
image: docker.elastic.co/kibana/kibana:7.2.0
image: docker.elastic.co/kibana/kibana:7.7.0
container_name: kibana
restart: always
environment:
SERVER_NAME: localhost
ELASTICSEARCH_URL: http://elasticsearch1:9200/
# environment:
# env ที่อยู่ตรงนี้คือตัวเดียวกับใน kibana.yml แต่จะเขียนด้วย format KEY_PROPERTY: value
# ซึ่งถ้าเป้นใน kibana.yml จะเขียนด้วย key.property: value แทนนั่นเอง มีค่าเท่ากัน
# SERVER_NAME: localhost
# ELASTICSEARCH_URL: http://elasticsearch:9200
ports:
- 5601:5601
volumes:
- .:/your/local/path
- ./kibana.yml:/usr/share/kibana/config/kibana.yml
networks:
- elastic
- ingress

networks:
elastic:
ingress:

volumes: # volume แบบใช้ในตัว dcoker machine ให้จัดการเอง
esdata:
data01:
driver: local
data02:
driver: local
data03:
driver: local
11 changes: 11 additions & 0 deletions kibana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# โดยปกติ Kibana จะ Compliance ตาม Elasticsearch อยู่แล้วแต่เขียนเอาไว้อุ่นใจกว่าให้แน่ใจ
# xpack.security.audit.enabled: true
# ถ้าไม่ระบุ host จะเข้าไม่ได้ถึงแม้ default จะระบุเป็น localhost ก็ตาม
server.host: 0.0.0.0
# hostname ที่อยู่ของ elasticsearch
elasticsearch.hosts: [ "http://elasticsearch1:9200","http://elasticsearch2:9200" ,"http://elasticsearch3:9200" ]
# user ต้องเป้น user ชื่อ kibana เท่านั้นเพราะเงื่อนไขการติดต่อคือ
# user ต้องตรงกับ app เช่น apm ต้องใช้ apm ไม่งั้นจะเข้าไมไ่ด้ !!!
# ส่วน user elastic มีไว้ใช้ login กับ elastic ไม่เกีย่วกับ user ของ kibana !!!
elasticsearch.username: "kibana"
elasticsearch.password: "hellomyproduction"

0 comments on commit f473d77

Please sign in to comment.