From f95e4fffa19e692767d016eb19eb2d5b44784fb7 Mon Sep 17 00:00:00 2001 From: Sherif Abdel-Naby Date: Thu, 28 Sep 2023 18:25:29 +0300 Subject: [PATCH] Fix ports in .env not affecting Elasticsearch and Kibana Ports (fixes #83) Signed-off-by: Sherif Abdel-Naby --- Makefile | 2 +- docker-compose.nodes.yml | 2 ++ docker-compose.yml | 8 +++++--- elasticsearch/config/elasticsearch.yml | 1 + elasticsearch/scripts/docker-healthcheck | 2 +- kibana/config/kibana.yml | 1 + 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index cba1ac3..851cd26 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ elk: ## Start ELK. up: @make elk - @echo "Visit Kibana: https://localhost:5601" + @echo "Visit Kibana: https://localhost:5601 (user: elastic, password: changeme) [Unless you changed values in .env]" monitoring: ## Start ELK Monitoring. $(DOCKER_COMPOSE_COMMAND) ${COMPOSE_MONITORING} up -d --build ${ELK_MONITORING} diff --git a/docker-compose.nodes.yml b/docker-compose.nodes.yml index e765924..70d737a 100644 --- a/docker-compose.nodes.yml +++ b/docker-compose.nodes.yml @@ -20,6 +20,7 @@ services: ELASTIC_NODE_NAME: ${ELASTIC_NODE_NAME_1} ELASTIC_INIT_MASTER_NODE: ${ELASTIC_INIT_MASTER_NODE} ELASTIC_DISCOVERY_SEEDS: ${ELASTIC_DISCOVERY_SEEDS} + ELASTICSEARCH_PORT: ${ELASTICSEARCH_PORT} ES_JAVA_OPTS: -Xmx${ELASTICSEARCH_HEAP} -Xms${ELASTICSEARCH_HEAP} -Des.enforce.bootstrap.checks=true bootstrap.memory_lock: "true" volumes: @@ -56,6 +57,7 @@ services: ELASTIC_NODE_NAME: ${ELASTIC_NODE_NAME_2} ELASTIC_INIT_MASTER_NODE: ${ELASTIC_INIT_MASTER_NODE} ELASTIC_DISCOVERY_SEEDS: ${ELASTIC_DISCOVERY_SEEDS} + ELASTICSEARCH_PORT: ${ELASTICSEARCH_PORT} ES_JAVA_OPTS: -Xmx${ELASTICSEARCH_HEAP} -Xms${ELASTICSEARCH_HEAP} -Des.enforce.bootstrap.checks=true bootstrap.memory_lock: "true" volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 4844380..3d895fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,6 +45,7 @@ services: ELASTIC_NODE_NAME: ${ELASTIC_NODE_NAME} ELASTIC_INIT_MASTER_NODE: ${ELASTIC_INIT_MASTER_NODE} ELASTIC_DISCOVERY_SEEDS: ${ELASTIC_DISCOVERY_SEEDS} + ELASTICSEARCH_PORT: ${ELASTICSEARCH_PORT} ES_JAVA_OPTS: "-Xmx${ELASTICSEARCH_HEAP} -Xms${ELASTICSEARCH_HEAP} -Des.enforce.bootstrap.checks=true -Dlog4j2.formatMsgNoLookups=true" bootstrap.memory_lock: "true" volumes: @@ -63,7 +64,7 @@ services: - source: elasticsearch.key target: /usr/share/elasticsearch/config/certs/elasticsearch.key ports: - - "9200:9200" + - "${ELASTICSEARCH_PORT}:${ELASTICSEARCH_PORT}" - "9300:9300" ulimits: memlock: @@ -73,7 +74,7 @@ services: soft: 200000 hard: 200000 healthcheck: - test: ["CMD", "sh", "-c", "curl -sf --insecure https://$ELASTIC_USERNAME:$ELASTIC_PASSWORD@localhost:9200/_cat/health | grep -ioE 'green|yellow' || echo 'not green/yellow cluster status'"] + test: ["CMD", "sh", "-c", "curl -sf --insecure https://$ELASTIC_USERNAME:$ELASTIC_PASSWORD@localhost:$ELASTICSEARCH_PORT/_cat/health | grep -ioE 'green|yellow' || echo 'not green/yellow cluster status'"] logstash: image: elastdocker/logstash:${ELK_VERSION} @@ -113,6 +114,7 @@ services: ELASTIC_USERNAME: ${ELASTIC_USERNAME} ELASTIC_PASSWORD: ${ELASTIC_PASSWORD} ELASTICSEARCH_HOST_PORT: https://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT} + KIBANA_PORT: ${KIBANA_PORT} env_file: - ./secrets/.env.kibana.token secrets: @@ -123,7 +125,7 @@ services: - source: kibana.key target: /certs/kibana.key ports: - - "5601:5601" + - "${KIBANA_PORT}:${KIBANA_PORT}" apm-server: image: elastdocker/apm-server:${ELK_VERSION} diff --git a/elasticsearch/config/elasticsearch.yml b/elasticsearch/config/elasticsearch.yml index ac0d2e2..edb0d66 100644 --- a/elasticsearch/config/elasticsearch.yml +++ b/elasticsearch/config/elasticsearch.yml @@ -5,6 +5,7 @@ cluster.name: ${ELASTIC_CLUSTER_NAME} node.name: ${ELASTIC_NODE_NAME} network.host: 0.0.0.0 transport.host: 0.0.0.0 +http.port: ${ELASTICSEARCH_PORT} ## Cluster Settings discovery.seed_hosts: ${ELASTIC_DISCOVERY_SEEDS} diff --git a/elasticsearch/scripts/docker-healthcheck b/elasticsearch/scripts/docker-healthcheck index 89f5820..6f0a223 100644 --- a/elasticsearch/scripts/docker-healthcheck +++ b/elasticsearch/scripts/docker-healthcheck @@ -3,7 +3,7 @@ set -eo pipefail host="$(hostname --ip-address || echo '127.0.0.1')" -if health="$(curl -fsSL "http://$ELASTIC_USERNAME:$ELASTIC_PASSWORD@$host:9200/_cat/health?h=status")"; then +if health="$(curl -fsSL "https://$ELASTIC_USERNAME:$ELASTIC_PASSWORD@$host:$ELASTICSEARCH_PORT/_cat/health?h=status" --insecure")"; then health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ") if [ "$health" = 'green' ] || [ "$health" = "yellow" ]; then exit 0 diff --git a/kibana/config/kibana.yml b/kibana/config/kibana.yml index b2adbf9..0299a99 100644 --- a/kibana/config/kibana.yml +++ b/kibana/config/kibana.yml @@ -4,6 +4,7 @@ # server.name: kibana server.host: "0.0.0.0" +server.port: ${KIBANA_PORT} # Elasticsearch Connection elasticsearch.hosts: [ "${ELASTICSEARCH_HOST_PORT}" ]