Connect your first client
Set up client credentials, then publish and subscribe with an MQTT client. See Getting started.
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 ports
LISTENER_WSS_ENABLED)
git clone -b release-2.4.2 https://github.com/thingsboard/tbmq-pe-docker-compose.gitcd tbmq-pe-docker-compose/clusterRun every command in this guide from this tbmq-pe-docker-compose/cluster directory.
Before proceeding, ensure you have an active TBMQ license. If you don’t have one yet, visit the Pricing page, choose a pay-as-you-go subscription or a perpetual license, and use the calculator to size your deployment — session and throughput limits, production and development instances, and any add-ons — to obtain your license key.
Open the tbmq.env file.
nano tbmq.envSet your license key.
Find TBMQ_LICENSE_SECRET and replace YOUR_LICENSE_KEY_HERE with your actual license key:
# License infoTBMQ_LICENSE_SECRET=YOUR_LICENSE_KEY_HERECreate the Docker volumes.
The script creates the volumes and copies the TBMQ, Integration Executor, and HAProxy configuration into them:
./scripts/docker-create-volumes.shInstall the database.
./scripts/docker-install-tbmq.shThe script finishes with Installation finished successfully!.
Start all services.
./scripts/docker-start-services.shOpen 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.
Sign in as System Administrator.
Use the default System Administrator credentials:
sysadmin@thingsboard.orgsysadminChange the default password.
On first login, you are prompted to change the default password and re-login with the new credentials.
docker compose logs -f tbmq1docker compose psdocker compose logs -fSee the docker compose logs reference for more details.
./scripts/docker-stop-services.sh./scripts/docker-stop-tbmq.sh./scripts/docker-start-tbmq.shThese 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.
./scripts/docker-remove-services.shThe data stays in the Docker volumes, so ./scripts/docker-start-services.sh brings the cluster back.
./scripts/docker-remove-volumes.shTo apply changes to the configuration files (e.g., haproxy.cfg or logback.xml), copy them into the volumes:
./scripts/docker-refresh-config.shTBMQ re-reads logback.xml within 10 seconds. To reload the HAProxy configuration without restarting the container,
send it a HUP signal:
docker exec -it haproxy-certbot sh -c "kill -HUP 1"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 | Nothing |
| TBMQ to TBMQ PE | Move to the PE repository and set the license key; this path has its own commands |
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.
Proceed with the upgrade.
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.
Proceed with the upgrade.
No third-party component changes are required.
The upgrade creates the dropped_msg table used by dropped message analytics; no existing table is altered and no data
is migrated.
Proceed with the upgrade.
No third-party component changes are required — the official images are already in use since v2.2.0.
Proceed with the upgrade.
CE-to-PE migration is supported for the same version only. If you are on an earlier CE version, upgrade TBMQ CE to the latest version first. For all supported paths, see the upgrade instructions.
TBMQ PE uses its own repository, so the migration moves your cluster from the TBMQ tbmq/docker directory to the PE
tbmq-pe-docker-compose/cluster directory. The Docker volumes, and the data in them, stay the same.
Clone the TBMQ PE repository.
Clone it next to your TBMQ directory, as described in Clone TBMQ Docker Compose repository.
Set the license key and carry over your settings.
In the PE tbmq.env, set TBMQ_LICENSE_SECRET to your license key from the license step,
and keep TBMQ_LICENSE_INSTANCE_DATA_FILE as it is. Then copy your own changes from the TBMQ directory into the
matching PE files, such as tbmq.env, .env, docker-compose.yml, and haproxy/config/haproxy.cfg.
Remove the TBMQ containers.
In the TBMQ tbmq/docker directory, run:
./scripts/docker-remove-services.shThe PE services use the same container names, so the TBMQ containers must be removed first. The data stays in the Docker volumes.
Migrate the database and start TBMQ PE.
In the PE tbmq-pe-docker-compose/cluster directory, run:
./scripts/docker-upgrade-tbmq.sh --fromVersion=ce./scripts/docker-start-services.shThe upgrade script also creates the tbmq1-data and tbmq2-data volumes that TBMQ PE adds.
Switch to the new release branch.
git fetch origin release-2.4.2git checkout -m release-2.4.2git 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).
Run the upgrade.
./scripts/docker-stop-tbmq.sh./scripts/docker-upgrade-tbmq.sh./scripts/docker-start-tbmq.shThe 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:
docker exec haproxy-certbot certbot-certonly --domain your_domain --email your_emaildocker exec haproxy-certbot haproxy-refreshMQTTS allows clients to connect over an encrypted TLS/SSL channel. There are two common approaches:
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.
Provide SSL certificates.
Obtain a valid SSL certificate and private key:
mqttserver.pem — public certificate (may include the full chain)mqttserver_key.pem — private keyMount 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:
services: tbmq1: volumes: - tbmq-config:/config - tbmq1-logs:/var/log/thingsboard-mqtt-broker - tbmq1-data:/data - PATH_TO_CERTS:/config/certificates tbmq2: volumes: - tbmq-config:/config - tbmq2-logs:/var/log/thingsboard-mqtt-broker - tbmq2-data:/data - PATH_TO_CERTS:/config/certificatesKeep the other volume lines of each service as they are.
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:
sudo chown 799:799 PATH_TO_CERTS/mqttserver.pem PATH_TO_CERTS/mqttserver_key.pemIf TBMQ cannot read a file, it fails to start and logs Permission denied for that file.
Configure environment variables.
Edit the tbmq.env file and uncomment/configure the following lines:
LISTENER_SSL_ENABLED=trueLISTENER_SSL_PEM_CERT=/config/certificates/mqttserver.pemLISTENER_SSL_PEM_KEY=/config/certificates/mqttserver_key.pemLISTENER_SSL_PEM_KEY_PASSWORD=server_key_passwordLeave LISTENER_SSL_PEM_KEY_PASSWORD empty if your private key has no password.
Restart services.
./scripts/docker-start-services.shOnce 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.
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:
docker cp fullchain-and-key.pem haproxy-certbot:/usr/local/etc/haproxy/certs.d/Point the MQTTS listener at the bundle.
In haproxy/config/haproxy.cfg, replace the mqtts-in section with:
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 ipv4Replace fullchain-and-key.pem with the actual filename of your certificate bundle.
Apply the configuration.
./scripts/docker-refresh-config.shdocker exec -it haproxy-certbot sh -c "kill -HUP 1"MQTT clients can now connect securely on port 8883.
Set up client credentials, then publish and subscribe with an MQTT client. See Getting started.
Choose the authentication provider that fits your clients. See Security overview.
Change broker settings through environment variables in tbmq.env.
See How to change configuration.
Track sessions, throughput, and resource usage as traffic grows. See Monitoring.
Was this helpful?