-
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 TLS เฉพาะ Cluster ที่ Transport Layer ส่วน Traffi…
…c ข้างนอกใช้ HTTP
- Loading branch information
1 parent
d0a0bc9
commit e47cd4c
Showing
5 changed files
with
231 additions
and
12 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,19 @@ | ||
#!/bin/bash | ||
curl -X POST -v -k --cacert /usr/share/elasticsearch/config/certificates/ca/ca.crt "https://elasticsearch1:9200/_security/user/kibana/_password?pretty" -u elastic:PleaseChangeMe -H 'Content-Type: application/json' -d' { "password" : "PleaseChangeMe" } ' | ||
|
||
if [[ $? == 51 ]] | ||
then | ||
echo "Connect but it not secure So fail to change Password" | ||
else | ||
echo "Skip SSL Secure Connection by -k argument so Change password Success" | ||
fi | ||
|
||
echo "=======" | ||
echo "Variable two sign : $$?" | ||
echo "Variable single sign: $?" | ||
|
||
#!/bin/bash | ||
|
||
curl -k https://elasticsearch1:9200 | ||
|
||
echo "Yeah $?" |
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,179 @@ | ||
version: '3.3' | ||
services: | ||
elasticsearch1: | ||
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0 | ||
container_name: elasticsearch1 | ||
restart: always | ||
environment: | ||
- node.name=elasticsearch1 | ||
# จะทำให้มันไม่ยอมเข้าไปอยู่ใน 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=-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 ไม่ผ่าน | ||
- ELASTIC_PASSWORD=$ELASTIC_PASSWORD | ||
- xpack.security.enabled=true | ||
- xpack.security.http.ssl.enabled=false | ||
# - xpack.security.http.ssl.key=$CERTS_DIR/instance/instance.key | ||
# - xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt | ||
# - xpack.security.http.ssl.certificate=$CERTS_DIR/instance/instance.crt | ||
- xpack.security.transport.ssl.enabled=true | ||
- xpack.security.transport.ssl.verification_mode=certificate | ||
- xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt | ||
- xpack.security.transport.ssl.certificate=$CERTS_DIR/instance/instance.crt | ||
- xpack.security.transport.ssl.key=$CERTS_DIR/instance/instance.key | ||
# จำเป็นต้องปิดการ swap memory เมื่อทำ cluster node เพราะว่า | ||
ulimits: | ||
memlock: | ||
soft: -1 | ||
hard: -1 | ||
volumes: | ||
- data01:/usr/share/elasticsearch/data | ||
# volume certs นี้ยังแชร์กับ create-cert.yml service อีกด้วยเพราะว่า namespace ชื่อเดียวกัน | ||
# ทำให้ทำการ mount cert เข้าไปหาทุกๆ node ได้อีกด้วย !!! | ||
- certs:$CERTS_DIR | ||
networks: | ||
- elastic | ||
ports: | ||
- 9200:9200 | ||
# healthcheck: | ||
# test: curl -k https://elasticsearch1:9200; if [[ $? == 0 ]]; then echo 0; else echo 1; fi | ||
# interval: 30s | ||
# timeout: 10s | ||
# retries: 5 | ||
|
||
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 ไม่ผ่าน | ||
- ELASTIC_PASSWORD=$ELASTIC_PASSWORD | ||
- xpack.security.enabled=true | ||
- xpack.security.http.ssl.enabled=false | ||
# - xpack.security.http.ssl.key=$CERTS_DIR/instance/instance.key | ||
# - xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt | ||
# - xpack.security.http.ssl.certificate=$CERTS_DIR/instance/instance.crt | ||
- xpack.security.transport.ssl.enabled=true | ||
- xpack.security.transport.ssl.verification_mode=certificate | ||
- xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt | ||
- xpack.security.transport.ssl.certificate=$CERTS_DIR/instance/instance.crt | ||
- xpack.security.transport.ssl.key=$CERTS_DIR/instance/instance.key | ||
# จำเป็นต้องปิดการ swap memory เมื่อทำ cluster node เพราะว่า | ||
ulimits: | ||
memlock: | ||
soft: -1 | ||
hard: -1 | ||
volumes: | ||
- data02:/usr/share/elasticsearch/data | ||
- certs:$CERTS_DIR | ||
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_ | ||
# ด้วยสาม parameter นี้จะทำให้ Elasticsearch Node นี้เป็นแค่ Coordinate ใช้ประสานคำสั่งเฉยๆ | ||
# จะไม่มีการเก้บข้อมูลใดๆที่ตัวมันดังนั้น Volume จึงไม่ทำงานและห้ามใช้ด้วยนั่นเอง ถ้าใช้ก็จะบึ้มเพราะเป็น Coordinate Node | ||
- node.master=false | ||
- node.data=false | ||
- node.ingest=false | ||
# หลังติดตั้งเสร็จแล้วต้องรันคำสั่ง bin/elasticsearch-setup-passwords interactive | ||
# เพื่อให้ xpack module ที่ลงไว้ทำการตั้ง password ตามที่เราตั้งด้วยนั่นเอง | ||
# ถ้าใช้ xpack บน cluster mode จะโดน bootstrap สั่งให้ทำ TLS ด้วยทันทีไม่งั้นจะ bootstrap ไม่ผ่าน | ||
- ELASTIC_PASSWORD=$ELASTIC_PASSWORD | ||
- xpack.security.enabled=true | ||
- xpack.security.http.ssl.enabled=false | ||
# - xpack.security.http.ssl.key=$CERTS_DIR/instance/instance.key | ||
# - xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt | ||
# - xpack.security.http.ssl.certificate=$CERTS_DIR/instance/instance.crt | ||
- xpack.security.transport.ssl.enabled=true | ||
- xpack.security.transport.ssl.verification_mode=certificate | ||
- xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt | ||
- xpack.security.transport.ssl.certificate=$CERTS_DIR/instance/instance.crt | ||
- xpack.security.transport.ssl.key=$CERTS_DIR/instance/instance.key | ||
# จำเป็นต้องปิดการ swap memory เมื่อทำ cluster node เพราะว่า | ||
ulimits: | ||
memlock: | ||
soft: -1 | ||
hard: -1 | ||
volumes: | ||
- certs:$CERTS_DIR | ||
# - data03:/usr/share/elasticsearch/data | ||
networks: | ||
- elastic | ||
|
||
kibana: | ||
image: docker.elastic.co/kibana/kibana:7.7.0 | ||
container_name: kibana | ||
restart: always | ||
environment: | ||
# env ที่อยู่ตรงนี้คือตัวเดียวกับใน kibana.yml แต่จะเขียนด้วย format KEY_PROPERTY: value | ||
# ซึ่งถ้าเป้นใน kibana.yml จะเขียนด้วย key.property: value แทนนั่นเอง มีค่าเท่ากัน | ||
# SERVER_NAME: localhost | ||
# ELASTICSEARCH_URL: http://elasticsearch:9200 | ||
- ELASTICSEARCH_PASSWORD=$ELASTIC_PASSWORD | ||
ports: | ||
- 5601:5601 | ||
volumes: | ||
- ./kibana.yml:/usr/share/kibana/config/kibana.yml | ||
- certs:$CERTS_DIR | ||
networks: | ||
- elastic | ||
# command: > | ||
# bash -c ' | ||
# curl -X POST -v -k --cacert /usr/share/elasticsearch/config/certificates/ca/ca.crt "https://elasticsearch1:9200/_security/user/kibana/_password?pretty" -u elastic:PleaseChangeMe -H 'Content-Type: application/json' -d' { "password" : "PleaseChangeMe" } ' | ||
|
||
# if [[ $? == 51 ]] | ||
# then | ||
# echo "Connect but it not secure So fail to change Password" | ||
# else | ||
# echo "Skip SSL Secure Connection by -k argument so Change password Success" | ||
# fi | ||
# ' | ||
# depends_on: {"elasticsearch1": {"condition": "service_healthy"}} | ||
|
||
networks: | ||
elastic: | ||
|
||
volumes: # volume แบบใช้ในตัว dcoker machine ให้จัดการเอง | ||
data01: | ||
driver: local | ||
data02: | ||
driver: local | ||
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,3 @@ | ||
#!/bin/bash | ||
sysctl -w vm.max_map_count=262144 | ||
|
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