Connect your first client
Set up client credentials, then publish and subscribe with an MQTT client. See Getting started.
We use cookies
We use cookies for site analytics, to remember the campaign or partner link you arrived from and, if you allow it, to load the site search from Google. Nothing optional is set until you choose. You can change your choice anytime in Your Privacy Choices at the bottom of every page. Cookie Policy
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.gitcd tbmq/dockerRun every command in this guide from this tbmq/docker directory.
Create 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 | 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.
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.
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.
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.envtb-mqtt-broker/conf/ → tbmq/conf/cache-redis-cluster.env and cache-redis-sentinel.env → cache-valkey-cluster.env and cache-valkey-sentinel.envCACHE in .env: redis, redis-cluster, redis-sentinel → valkey, valkey-cluster, valkey-sentinelThen proceed with the upgrade.
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 falseOnce the file is verified, proceed with the upgrade.
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:
./scripts/docker-create-volumes.shYou should see output similar to:
user@user:~/tbmq/docker$ ./scripts/docker-create-volumes.sh
tbmq-ie1-logstbmq-ie2-logstbmq-ie-configUpdate 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.
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 - PATH_TO_CERTS:/config/certificates tbmq2: volumes: - tbmq-config:/config - tbmq2-logs:/var/log/thingsboard-mqtt-broker - 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?