From 2eef9e74377b217c2ef6472df973365321f8cfa2 Mon Sep 17 00:00:00 2001 From: BEagle1984 Date: Mon, 27 Nov 2023 09:34:48 +0100 Subject: [PATCH] test: configure emqx cluster and load balancer in docker compose --- docker-compose.yaml | 59 ++++++++++++++++++++++++++++++++++++--------- haproxy.cfg | 18 ++++++++++++++ 2 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 haproxy.cfg diff --git a/docker-compose.yaml b/docker-compose.yaml index 3bdb9178e..8309f1a1e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,7 +3,7 @@ services: ### Database ### mssql: - container_name: s8k-mssql + container_name: silverback-mssql image: mcr.microsoft.com/mssql/server:2019-latest environment: ACCEPT_EULA: "Y" @@ -14,7 +14,7 @@ services: ### Apache Kafka ### zookeeper: - container_name: s8k-zookeeper + container_name: silverback-zookeeper image: confluentinc/cp-zookeeper:latest environment: ZOOKEEPER_CLIENT_PORT: 2181 @@ -22,7 +22,7 @@ services: ports: - "2181:2181" kafka: - container_name: s8k-kafka + container_name: silverback-kafka depends_on: - zookeeper image: confluentinc/cp-kafka:latest @@ -40,7 +40,7 @@ services: ports: - "9092:9092" schema-registry: - container_name: s8k-schema-registry + container_name: silverback-schema-registry depends_on: - zookeeper - kafka @@ -56,21 +56,58 @@ services: ### RabbitMQ ### # management console http://localhost:15672/#/ (login guest/guest) rabbit: - container_name: s8k-rabbit + container_name: silverback-rabbit image: rabbitmq:3-management ports: - "15672:15672" - "5672:5672" ### MQTT (emqx) - mqtt: - container_name: s8k-mqtt-emqx - image: emqx/emqx:4.2.14 # Fixed version because of crash at startup, probably related to https://github.com/emqx/emqx/issues/3996 + emqx1: + image: emqx:5.1.0 + container_name: silverback-emqx1 + environment: + - "EMQX_NODE_NAME=emqx@node1.emqx.io" + - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static" + - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io,emqx@node2.emqx.io]" + healthcheck: + test: ["CMD", "/opt/emqx/bin/emqx", "ctl", "status"] + interval: 5s + timeout: 25s + retries: 5 + networks: + default: + aliases: + - node1.emqx.io + + emqx2: + image: emqx:5.1.0 + container_name: silverback-emqx2 + environment: + - "EMQX_NODE_NAME=emqx@node2.emqx.io" + - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static" + - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io,emqx@node2.emqx.io]" + healthcheck: + test: ["CMD", "/opt/emqx/bin/emqx", "ctl", "status"] + interval: 5s + timeout: 25s + retries: 5 + networks: + default: + aliases: + - node2.emqx.io + + ### HA Proxy (used to load balance the emqx cluster nodes) + haproxy: + image: haproxy:latest + container_name: silverback-haproxy ports: - "1883:1883" - - "9001:9001" - environment: - EMQX_ZONE__EXTERNAL__RETRY_INTERVAL: "10s" + volumes: + - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro + depends_on: + - emqx1 + - emqx2 networks: default: diff --git a/haproxy.cfg b/haproxy.cfg new file mode 100644 index 000000000..3ffc2264e --- /dev/null +++ b/haproxy.cfg @@ -0,0 +1,18 @@ +global + log stdout format raw local0 + +defaults + log global + mode tcp + timeout connect 5000ms + timeout client 50000ms + timeout server 50000ms + +frontend mqtt-in + bind *:1883 + default_backend emqx_cluster + +backend emqx_cluster + balance roundrobin + server emqx1 emqx1:1883 check + server emqx2 emqx2:1883 check