ThingsBoard Server Installation¶
This guide provides step-by-step instructions to set up a ThingsBoard server for this project.
Prerequisites¶
A server running Linux, e.g. Ubuntu 22.04 LTS
using a cloud hosting provider (e.g., DigitalOcean, AWS, Azure, GCP)
minimum specifications 1 vCPU (2 recommended), 2GB RAM
Optional: A domain name pointing to the server’s IP address
e.g., subdomain.example.com
choose from a paid domain name provider (e.g. namecheap.com) or use a subdomain of an existing domain (e.g. from within your institution)
point the domain’s DNS A record to the server’s IP address (A <domain> <IP>)
optional: create a trusted certificate for the domain using Let’s Encrypt (e.g. using
certbot certonly -d <domain>) and add an automatic renewal cron job (e.g.0 0 * * * certbot renew --quiet)
Optional: Familiarize yourself with the ThingsBoard documentation.
Installation¶
Optional: Update system packages and reboot
sudo apt update sudo apt upgrade -y sudo apt auto-remove -y sudo reboot
Optional: Set up a swapfile if your server has less than 2GB of RAM
sudo fallocate -l 4G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Install dependencies (
docker,git,jq,curl,ca-certificates,nginx-full,ufw)sudo apt install docker.io git jq curl ca-certificates nginx-full ufw
Install
docker-compose(plugin)# Add Docker's official GPG key: sudo apt update sudo apt install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc # Add the repository to Apt sources: echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # Install docker-compose sudo apt update sudo apt install docker-compose-plugin
Add your user to the
dockergroup (log out/in afterwards)sudo groupadd docker || true sudo usermod -aG docker $USER
Create data folders for ThingsBoard
mkdir -p ~/data/thingsboard_data/data mkdir -p ~/data/thingsboard_data/logs mkdir -p ~/data/kafka sudo chmod -R a+rw ~/data/
Generate a self-signed certificate for ThingsBoard SSL (skip if using a trusted certificate)
Run
gen_certs.shin a temporary directory on your local machine (script available in this repository undersetup/ThingsBoard/gen_certs.sh).
Copy files to the server
docker-compose.yml→~/docker-compose.ymlself_signed_cert.crt→/etc/ssl/certs/self_signed_cert.crtself_signed_cert.key→/etc/ssl/certs/self_signed_cert.keynginx_thingsboard.conf→/etc/nginx/sites-available/thingsboard.confnginx.conf→/etc/nginx/nginx.conf(overwrite existing file)
Remove default NGINX configuration
sudo rm /etc/nginx/sites-enabled/default
Set up firewall using
ufwsudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw allow 8843 sudo ufw enable
Reload NGINX and start Docker containers
sudo service nginx reload cd ~ docker compose -f docker-compose.yml up -d
Watch live logs of ThingsBoard (initial startup takes several minutes)
docker logs -f thingsboard
Wait until the following message appears:
[main] INFO o.t.s.ThingsboardServerApplication - Started ThingsBoard in x secondsOpen the ThingsBoard web UI and log in with default credentials
Open
<your-domain>in a web browserLog in with: - username:
sysadmin@thingsboard.org- password:sysadmin
Connect MQTT devices to ThingsBoard
Use the following MQTT broker settings:
host:
<your-domain>port:
8843(SSL)username:
<access-token>(see below)
See the ThingsBoard MQTT API documentation for details.