Skip to content
Stand with Ukraine flag

ThingsBoard Edge cluster setup with Docker Compose

ThingsBoard Edge clustering connects multiple Edge nodes to a shared database and syncs aggregated data to ThingsBoard Server or Cloud. It is designed for large-scale deployments — factories, smart cities, or any site with thousands of devices in one region.

Key properties of an Edge cluster:

  • All Edge nodes connect to the same database.
  • Devices connect to any node based on load balancing.
  • Edge nodes share workload and maintain local failover.
  • The cluster syncs aggregated data to ThingsBoard Server or Cloud.

For details about microservices architecture, see the microservices architecture page.

ThingsBoard Edge microservices run in a Dockerized environment. Install Docker CE and Docker Compose before continuing.

You also need an active ThingsBoard Community Edition account with an Edge instance created on the server.

You can use a self-hosted ThingsBoard CE server.

WorkloadRAM per nodeDescription
Light2 GBFewer than 1,000 devices per node
Heavy4 GB+1,000+ devices or high data ingestion rates
Terminal window
docker pull thingsboard/tb-edge:4.3.1.1
Terminal window
git clone -b release-4.3 https://github.com/thingsboard/thingsboard-edge.git --depth 1
cd thingsboard-edge/docker-edge

Open the .env file:

Terminal window
nano .env

Set at minimum the following variables:

VariableDescription
DATABASE

postgres — PostgreSQL only.
hybrid — PostgreSQL for entities, Cassandra for time-series data.

TB_QUEUE_TYPEUse kafka. The In Memory queue does not support cluster deployments.
CLOUD_ROUTING_KEYYour Edge key
CLOUD_ROUTING_SECRETYour Edge secret
CLOUD_RPC_HOSTHostname or IP address of the ThingsBoard CE server.
CACHE

redis — Redis standalone (one node, one master).
redis-cluster — Redis cluster (six nodes, three masters, three replicas).
redis-sentinel — Redis Sentinel (three nodes, one master, one replica, one sentinel).

MONITORING_ENABLEDSet to true to deploy Prometheus and Grafana alongside the cluster containers.
JAVA_OPTSJVM memory settings. Adjust -Xmx and -Xms based on available RAM.

Full .env file reference:

.env
# Cache type: redis | redis-cluster | redis-sentinel
CACHE=redis
DOCKER_REPO=thingsboard
TB_EDGE_NODE_DOCKER_NAME=tb-edge-node
TB_EDGE_VERSION=latest
# Database: postgres (PostgreSQL) or hybrid (PostgreSQL + Cassandra for time-series)
DATABASE=postgres
TB_QUEUE_TYPE=kafka
CLOUD_ROUTING_KEY=PUT_YOUR_EDGE_KEY_HERE
CLOUD_ROUTING_SECRET=PUT_YOUR_EDGE_SECRET_HERE
CLOUD_RPC_HOST=PUT_YOUR_THINGSBOARD_SERVER_DOMAIN_OR_IP_HERE
CLOUD_RPC_PORT=7070
LOAD_BALANCER_NAME=haproxy-certbot
# Set to true to deploy Prometheus and Grafana containers
MONITORING_ENABLED=false
# JVM memory limits
JAVA_OPTS="-Xmx2048M -Xms2048M -Xss384k -XX:+AlwaysPreTouch"

Create the log folders and set correct ownership:

Terminal window
./docker-create-log-folders.sh

Verify that all required volume folders exist with correct ownership:

Terminal window
./docker-check-log-folders.sh

Step 5. Install and start ThingsBoard Edge

Section titled “Step 5. Install and start ThingsBoard Edge”

Run the installation script:

Terminal window
./docker-install-tb.sh

Start all services:

Terminal window
./docker-start-services.sh

To view Edge node logs:

Terminal window
docker compose logs -f tb-edge1 tb-edge2 tb-edge3

To check the status of all containers:

Terminal window
docker compose ps

To view logs for all running services:

Terminal window
docker compose logs -f

To stop all services:

Terminal window
./docker-stop-services.sh

To stop and remove all deployed containers:

Terminal window
./docker-remove-services.sh

To update one or more services (pulls a newer Docker image and rebuilds the container):

Terminal window
./docker-update-service.sh [SERVICE...]

Omit [SERVICE...] to update all services.

To upgrade the database:

Terminal window
./docker-stop-services.sh
./docker-upgrade-tb.sh
./docker-start-services.sh

ThingsBoard Edge uses HAproxy for traffic proxying, with ports 80 and 443 for the web UI. To obtain a valid TLS certificate via Certbot:

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