-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] Elasticsearch Full Cluster + Node Encryption พร้อมตั้งรหัสผ่าน …
…Generate Cert
- Loading branch information
1 parent
1177105
commit 4283f65
Showing
4 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ถ้า set ตัวนี้จะทำการ ovver default name ทันที | ||
#COMPOSE_PROJECT_NAME=es | ||
CERTS_DIR=/usr/share/elasticsearch/config/certificates | ||
ELASTIC_PASSWORD=PleaseChangeMe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
version: '3.3' | ||
|
||
services: | ||
create_certs: | ||
container_name: create_certs | ||
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0 | ||
# bash -c คือการสั่งรัน command ที่อยู่ใน string single quote ทั้งหมด | ||
# เขียน command หลายบรรทัด้วย fold > symbol ซึ่งใน step แรกคือการเช็คว่าถ้ายังไม่เคย gen cert มาก่อน | ||
# จะทำการสั่ง gen cert ทั้ง pack ให้ใหม่โดยตำแหน่งที่เก็บ cert นั้นอยู่ที่ /certs/bundle.zip | ||
# bin/elasticsearch-certutil cert --silent --pem --in config/certificates/instances.yml -out /certs/bundle.zip; | ||
# สั่งทำการ gen cert แบบ silent mode ไม่มี interactive ใดๆทั้งนั้นทำให้สามารถทำเป้น script ได้เเพียงแต่ต้องกรอกข้อมูลให้ครบ | ||
# โดยเลือกการ gen แบบเป็น pem ไฟล์และนำ --in คือ input file script มาจาก config/certificates/instances.yml ซึ่่งการเจนแบบ cert | ||
# จะทำการสร้าง CA ให้อัตโนมัติด้วยถ้าหากระบุเอาไว้ตั้งแต่ตอนแรก และ output cert + ca ที่ gen ไปวางที่ /certs/bundle.zip | ||
# ดังนั้นเมื่อ Gen เสร็จแล้วครั้งหน้าก้จะไม่ gen อีกเพราะเราเขียน logic | ||
# --in ถ้าไม่มีก็จะได้ default templte ใช้ได้กับทุกอย่าง | ||
command: > | ||
bash -c ' | ||
if [[ ! -f /certs/bundle.zip ]]; then | ||
bin/elasticsearch-certutil cert --silent --pem -out /certs/bundle.zip; | ||
unzip /certs/bundle.zip -d /certs; | ||
fi; | ||
chown -R 1000:0 /certs | ||
' | ||
user: "0" | ||
working_dir: /usr/share/elasticsearch | ||
# สังเกตดุว่า volume นั้นถูก mount เอาไว้ทำให้เราสามารถนำไฟล์ cert + ca ที่ gen ออกมาไปวางที่ container อื่นที่ share volume ได้ | ||
# และตำแหน่งที่สองคือตำแหน่งของ instance.yml จาก local ถูกส่งเข้าไปวางที่ config/certificates/instances.yml นั่นเองจาก bind volume ! | ||
volumes: | ||
- certs:/certs | ||
- .:/usr/share/elasticsearch/config/certificates | ||
|
||
volumes: | ||
certs: | ||
driver: local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
instances: | ||
- name: es01 | ||
dns: | ||
- es01 | ||
- localhost | ||
ip: | ||
- 127.0.0.1 | ||
|
||
- name: es02 | ||
dns: | ||
- es02 | ||
- localhost | ||
ip: | ||
- 127.0.0.1 |