Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load the site search from Google. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics).

Remember the campaign or partner link you arrived from, so we know which campaign or partner brought you when you sign up or contact us (partner program). We do not use it to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

Stand with Ukraine flag

Docker Compose

This guide covers setting up TBMQ in cluster mode using Docker Compose.

The scripts run two TBMQ nodes, two Integration Executors, PostgreSQL, Kafka, and Valkey on one host, with HAProxy in front of the TBMQ nodes. Clients connect to HAProxy, which listens on these host ports:

One host · Docker Compose

  • HAProxy
  • TBMQ × 2
  • Integration Executor × 2
  • PostgreSQL
  • Kafka
  • Valkey

HAProxy ports

  • 80 HTTP TBMQ UI and REST API
  • 443 HTTPS TBMQ UI and REST API over HTTPS; see Generate certificate for HTTPS
  • 1883 MQTT MQTT clients
  • 8084 MQTT over WebSockets MQTT clients that connect over WebSockets
  • 8883 MQTTS MQTT clients that connect over TLS, once you enable MQTTS
  • 8085 MQTT over secure WebSockets MQTT clients that connect over secure WebSockets, once you enable the TBMQ WSS listener (LISTENER_WSS_ENABLED)
  • Docker installed.
  • Git installed.
Terminal window
git clone -b release-2.4.2 https://github.com/thingsboard/tbmq.git
cd tbmq/docker

Run every command in this guide from this tbmq/docker directory.

  1. Create the Docker volumes.

    The script creates the volumes and copies the TBMQ, Integration Executor, and HAProxy configuration into them:

    Terminal window
    ./scripts/docker-create-volumes.sh
  2. Install the database.

    Terminal window
    ./scripts/docker-install-tbmq.sh

    The script finishes with Installation finished successfully!.

  1. Start all services.

    Terminal window
    ./scripts/docker-start-services.sh
  2. Open the UI.

    Once all services have started, open http://{your-host-ip} in your browser (e.g., http://localhost). You should see the TBMQ login page. MQTT clients connect on port 1883.

  3. Sign in as System Administrator.

    Use the default System Administrator credentials:

    Username
    sysadmin@thingsboard.org
    Password
    sysadmin
  4. Change the default password.

    On first login, you are prompted to change the default password and re-login with the new credentials.

View TBMQ node logs
docker compose logs -f tbmq1
View the state of all containers
docker compose ps
View the logs of all services
docker compose logs -f

See the docker compose logs reference for more details.

Stop the services
./scripts/docker-stop-services.sh
Stop only the TBMQ nodes and Integration Executors
./scripts/docker-stop-tbmq.sh
Start the TBMQ nodes and Integration Executors
./scripts/docker-start-tbmq.sh

These two scripts leave PostgreSQL, Kafka, Valkey, and HAProxy running. docker-start-tbmq.sh also recreates the TBMQ containers when their image or tbmq.env settings changed.

Stop and remove the containers
./scripts/docker-remove-services.sh

The data stays in the Docker volumes, so ./scripts/docker-start-services.sh brings the cluster back.

Remove the Docker volumes (deletes all data)
./scripts/docker-remove-volumes.sh

To apply changes to the configuration files (e.g., haproxy.cfg or logback.xml), copy them into the volumes:

Copy the configuration into the volumes
./scripts/docker-refresh-config.sh

TBMQ re-reads logback.xml within 10 seconds. To reload the HAProxy configuration without restarting the container, send it a HUP signal:

Reload HAProxy
docker exec -it haproxy-certbot sh -c "kill -HUP 1"
  1. Check the version-specific notes below for any preparation your target version requires.
  2. Back up your database (optional but recommended).
  3. Run the upgrade commands.

For full version history and supported upgrade paths, see the upgrade instructions page. If the documentation does not cover your specific upgrade path, contact us for guidance.

What each upgrade needs before you run the upgrade — select a version for its full notes:

Upgrade to Before running the upgrade
2.4.2 Nothing. Check SCRAM-only authentication and Kafka integrations
2.4.1 Nothing. If you set MQTT_TOPIC_MAX_SEGMENTS_COUNT, raise it by 1
2.4.0 Nothing. If you scrape metrics, update queries for the renamed Prometheus metrics
2.3.0 Plan the third-party component migration, and carry your settings over to the renamed files
2.2.0 Check the authentication settings in tb-mqtt-broker.env
2.1.0 Create the Integration Executor volumes and upgrade the third-party services

Backing up your PostgreSQL database before upgrading is highly recommended but optional. For guidance, follow the backup and restore instructions.

This is a standard upgrade from v2.4.1. No third-party component changes are required, and the upgrade only records the new schema version — no table is created or altered and no data is migrated.

Then proceed with the upgrade.

This is a standard upgrade from v2.4.0.

No third-party component changes are required, and the upgrade only records the new schema version — no table is created or altered and no data is migrated.

Then proceed with the upgrade.

This is a standard upgrade from v2.3.0.

No third-party component changes are required, and the upgrade only records the new schema version — no table is created or altered and no data is migrated.

Then proceed with the upgrade.

This release migrates all third-party components from Bitnami images to official open-source alternatives.

Review the third-party component updates for full details.

The 2.3.0 scripts also rename several files. Carry your own settings over to the new names:

  • tb-mqtt-broker.env → tbmq.env
  • tb-mqtt-broker/conf/ → tbmq/conf/
  • cache-redis-cluster.env and cache-redis-sentinel.env → cache-valkey-cluster.env and cache-valkey-sentinel.env
  • CACHE in .env: redis, redis-cluster, redis-sentinel → valkey, valkey-cluster, valkey-sentinel

Then proceed with the upgrade.

This release migrates MQTT authentication from YAML/env configuration into the database.

The upgrade runs with the tbmq1 service settings, so it reads the authentication settings from the tb-mqtt-broker.env file. Make sure this file reflects your active configuration.

Supported variables in tb-mqtt-broker.env

  • SECURITY_MQTT_BASIC_ENABLED (true|false)
  • SECURITY_MQTT_SSL_ENABLED (true|false)
  • SECURITY_MQTT_SSL_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT (true|false) — usually false

Once the file is verified, proceed with the upgrade.

This release adds the Integration Executor microservice and updates third-party service versions.

Add Integration Executor microservice

This release adds support for external integrations via the new Integration Executor microservice (full example).

Pull the updates from the release branch by following the Run upgrade steps up to (but not including) the upgrade script. Then create the required Docker volumes:

Terminal window
./scripts/docker-create-volumes.sh

You should see output similar to:

user@user:~/tbmq/docker$ ./scripts/docker-create-volumes.sh
tbmq-ie1-logs
tbmq-ie2-logs
tbmq-ie-config

Update third-party services

This release updates third-party dependency versions (pull request):

Service Previous version Updated version
Redis 7.0 7.2.5
PostgreSQL 15.x 16.x
Kafka 3.5.1 3.7.0

After addressing third-party service versions, proceed with the upgrade.

  1. Switch to the new release branch.

    Terminal window
    git fetch origin release-2.4.2
    git checkout -m release-2.4.2

    git checkout -m switches to the release branch and keeps your own edits to files such as .env, tbmq.env, and haproxy.cfg. Make sure TBMQ_VERSION in the .env file is set to the target version (e.g., 2.4.2).

  2. Run the upgrade.

    Terminal window
    ./scripts/docker-stop-tbmq.sh
    ./scripts/docker-upgrade-tbmq.sh
    ./scripts/docker-start-tbmq.sh

    The first command stops only the TBMQ nodes and Integration Executors; PostgreSQL, Kafka, Valkey, and HAProxy keep running. The upgrade script pulls the new TBMQ image and upgrades the database. The last command starts the TBMQ nodes and Integration Executors on the new version.

    If the notes for your target version change third-party services, run ./scripts/docker-stop-services.sh and ./scripts/docker-start-services.sh instead of the first and last commands, so that every service is restarted.

HAProxy handles traffic proxying and serves the web UI on ports 80 and 443 by default. To enable HTTPS with a valid certificate, run:

Terminal window
docker exec haproxy-certbot certbot-certonly --domain your_domain --email your_email
docker exec haproxy-certbot haproxy-refresh

MQTTS allows clients to connect over an encrypted TLS/SSL channel. There are two common approaches:

  • Two-way MQTTS (Mutual TLS) — TBMQ terminates TLS; clients must present valid certificates.
  • One-way MQTTS (TLS termination at load balancer) — HAProxy handles TLS termination and forwards plain MQTT to TBMQ over the internal network.

Both approaches encrypt external connections. Two-way MQTTS adds client certificate verification for higher security; one-way MQTTS simplifies broker configuration and can reuse existing HTTPS certificates.

In this configuration, TBMQ handles TLS termination and (optionally) client certificate authentication directly. This approach is suitable when you want the broker to fully control SSL/TLS and mutual authentication without relying on a load balancer for security. The default haproxy.cfg already forwards port 8883 to port 8883 of the TBMQ nodes without terminating TLS.

For supported certificate formats and options, see the MQTT over SSL guide.

  1. Provide SSL certificates.

    Obtain a valid SSL certificate and private key:

    • mqttserver.pem — public certificate (may include the full chain)
    • mqttserver_key.pem — private key
  2. Mount the certificates into both TBMQ nodes.

    In docker-compose.yml, uncomment the certificates volume mount in both the tbmq1 and tbmq2 services and replace PATH_TO_CERTS with the path to your certificate files:

    docker-compose.yml
    services:
    tbmq1:
    volumes:
    - tbmq-config:/config
    - tbmq1-logs:/var/log/thingsboard-mqtt-broker
    - PATH_TO_CERTS:/config/certificates
    tbmq2:
    volumes:
    - tbmq-config:/config
    - tbmq2-logs:/var/log/thingsboard-mqtt-broker
    - PATH_TO_CERTS:/config/certificates

    Keep the other volume lines of each service as they are.

  3. Let TBMQ read the certificate files.

    TBMQ runs as the thingsboard user (UID 799) inside the container and must be able to read both files. Private keys are usually readable only by their owner, so give that user ownership of the files:

    Terminal window
    sudo chown 799:799 PATH_TO_CERTS/mqttserver.pem PATH_TO_CERTS/mqttserver_key.pem

    If TBMQ cannot read a file, it fails to start and logs Permission denied for that file.

  4. Configure environment variables.

    Edit the tbmq.env file and uncomment/configure the following lines:

    tbmq.env
    LISTENER_SSL_ENABLED=true
    LISTENER_SSL_PEM_CERT=/config/certificates/mqttserver.pem
    LISTENER_SSL_PEM_KEY=/config/certificates/mqttserver_key.pem
    LISTENER_SSL_PEM_KEY_PASSWORD=server_key_password

    Leave LISTENER_SSL_PEM_KEY_PASSWORD empty if your private key has no password.

  5. Restart services.

    Terminal window
    ./scripts/docker-start-services.sh

    Once restarted, MQTT clients can connect securely on port 8883.

TLS is terminated at HAProxy. Clients connect to HAProxy on port 8883, which forwards plain MQTT to TBMQ on port 1883. You can reuse the same certificate used for HTTPS.

  1. Provide the certificate bundle.

    HAProxy needs one PEM file with the full certificate chain followed by the private key.

    • If you reuse the certificate from Generate certificate for HTTPS, haproxy-refresh already saved this bundle as /usr/local/etc/haproxy/certs.d/your_domain.pem.

    • Otherwise, copy your bundle into the HAProxy container:

      Terminal window
      docker cp fullchain-and-key.pem haproxy-certbot:/usr/local/etc/haproxy/certs.d/
  2. Point the MQTTS listener at the bundle.

    In haproxy/config/haproxy.cfg, replace the mqtts-in section with:

    haproxy.cfg
    listen mqtts-in
    bind *:${MQTTS_PORT} ssl crt /usr/local/etc/haproxy/certs.d/fullchain-and-key.pem
    mode tcp
    option clitcpka # For TCP keep-alive
    timeout client 3h
    timeout server 3h
    option tcplog
    balance leastconn
    server tbMqtt1 tbmq1:1883 check inter 5s resolvers docker_resolver resolve-prefer ipv4
    server tbMqtt2 tbmq2:1883 check inter 5s resolvers docker_resolver resolve-prefer ipv4

    Replace fullchain-and-key.pem with the actual filename of your certificate bundle.

  3. Apply the configuration.

    Terminal window
    ./scripts/docker-refresh-config.sh
    docker exec -it haproxy-certbot sh -c "kill -HUP 1"

    MQTT clients can now connect securely on port 8883.

Connect your first client

Set up client credentials, then publish and subscribe with an MQTT client. See Getting started.

Secure the broker

Choose the authentication provider that fits your clients. See Security overview.

Watch the broker

Track sessions, throughput, and resource usage as traffic grows. See Monitoring.