- Prerequisites
- Step 1. Pull ThingsBoard PE Images
- Step 2. Clone ThingsBoard PE Docker Compose scripts
- Step 3. Obtain your license key
- Step 4. Configure your license key
- Step 5. Configure deployment type
- Step 6. Configure ThingsBoard database
- Step 7. Choose ThingsBoard queue service
- Step 8. Enable monitoring (optional)
- Step 9. Running
- 升级
- HTTPS证书
- Next steps
This guide will help you to setup ThingsBoard in cluster mode with Docker Compose. For this purpose, we will use docker container images available on Docker Hub.
Prerequisites
ThingsBoard Microservices are running in dockerized environment. Before starting please make sure Docker CE and Docker Compose are installed in your system.
Step 1. Pull ThingsBoard PE Images
Run the following commands to verify that you can pull the images from the Docker hub.
1
2
3
4
5
6
7
8
9
docker pull thingsboard/tb-pe-node:3.5.1PE
docker pull thingsboard/tb-pe-web-report:3.5.1PE
docker pull thingsboard/tb-pe-web-ui:3.5.1PE
docker pull thingsboard/tb-pe-js-executor:3.5.1PE
docker pull thingsboard/tb-pe-http-transport:3.5.1PE
docker pull thingsboard/tb-pe-mqtt-transport:3.5.1PE
docker pull thingsboard/tb-pe-coap-transport:3.5.1PE
docker pull thingsboard/tb-pe-lwm2m-transport:3.5.1PE
docker pull thingsboard/tb-pe-snmp-transport:3.5.1PE
Step 2. Clone ThingsBoard PE Docker Compose scripts
1
2
git clone -b release-3.5.1 https://github.com/thingsboard/thingsboard-pe-docker-compose.git tb-pe-docker-compose
cd tb-pe-docker-compose
Step 3. Obtain your license key
We assume you have already chosen your subscription plan or decided to purchase a perpetual license. If not, please navigate to pricing page to select the best license option for your case and get your license. See How-to get pay-as-you-go subscription or How-to get perpetual license for more details.
IMPORTANT NOTE: if you decide to use an advanced deployment type, make sure you have purchased a license key for at least four instances of ThingsBoard PE. Otherwise, you need to modify the local copy of docker-compose.yml) to use the number of ThingsBoard instances that you’ve purchased. We will reference the license key you have obtained during this step as PUT_YOUR_LICENSE_SECRET_HERE later in this guide.
Step 4. Configure your license key
1
nano tb-node.env
and put the license secret parameter instead of “PUT_YOUR_LICENSE_SECRET_HERE”:
1
2
3
# ThingsBoard server configuration
...
TB_LICENSE_SECRET=PUT_YOUR_LICENSE_SECRET_HERE
Step 5. Configure deployment type
Starting ThingsBoard v2.2, it is possible to install ThingsBoard cluster using new microservices architecture and docker containers. See microservices architecture page for more details.
The docker compose scripts support three deployment modes. In order to set the deployment mode, change the value of TB_SETUP
variable in .env
file to one of the following:
basic
(recommended, set by default) - ThingsBoard Core and Rule Engine are launched inside one JVM (requires only one license). MQTT, CoAP and HTTP transports are launched in separate containers.monolith
- ThingsBoard Core and Rule Engine are launched inside one JVM (requires only one license). MQTT, CoAP and HTTP transports are also launched in the same JVM to minimize memory footprint and server requirements.advanced
- ThingsBoard Core and Rule Engine are launched in separate containers and are replicated one JVM (requires 4 licenses).
All deployment modes support separate JS executors, Redis, and different queues.
Step 6. Configure ThingsBoard database
在执行初始安装之前可以配置与ThingsBoard一起使用的数据库的类型。
设置数据库类型在.env
文件中的DATABASE
变量的值更改为以下值:
1
nano .env
postgres
- 使用PostgreSQL数据库;hybrid
- 使用PostgreSQL保存实体Cassandra时间序列数据;
注意:根据数据库类型将部署相应的docker服务(请参见docker-compose.postgres.yml
, docker-compose.hybrid.yml
)相关详细信息。
Step 7. Choose ThingsBoard queue service
ThingsBoard使用消息系统存储服务之间的通信,请正确选择队列?
-
内存 适用于开发环境(开发)
-
Kafka 适用于生产环境(集群)
-
RabbitMQ 适用生产环境(单体)
-
AWS SQS 适用生产环境(AWS公有云)
-
Google发布/订阅 适用生产环境(Google公有云)
-
Azure服务总线 适用生产环境(Azure公有云)
-
Confluent云 适用于生产环境(托管)
Apache Kafka是一个开源的流式数据处理平台。 配置环境变量文件:
检查下面行:
|
AWS SQS配置首先需要创建AWS账户然后访问AWS SQS服务。 使用此说明创建AWS SQS服务凭证。
配置环境变量文件:
检查下面行:
配置环境变量文件:
添加配置将”YOUR_KEY”和”YOUR_SECRET”替换为真实的AWS用户凭证并将”YOUR_REGION”替换成AWS SQS帐户区域:
可以使用UI更新默认规则引擎队列配置(轮询间隔和分区)有关ThingsBoard规则引擎队列的更多信息请参阅文档。 |
Google发布/订阅配置创建一个Google帐户并访问发布/订阅服务。 使用此说明创建一个项目并使用发布/订阅服务。 使用此说明创建服务帐户凭据并编辑角色或管理员后保存json凭据步骤9的文件此处。 配置环境变量文件:
检查下面行:
配置环境变量文件:
添加下面配置内容使用真正用户密码替换“YOUR_PROJECT_ID”, “YOUR_SERVICE_ACCOUNT”:
可以使用UI更新默认规则引擎队列配置(轮询间隔和分区)有关ThingsBoard规则引擎队列的更多信息请参阅文档。 |
Azure服务总线配置创建Azure帐户并访问Azure服务总线。 通过使用说明了解并使用总线服务。 使用说明创建共享访问签名。 配置环境变量文件:
检查下面行:
配置环境变量文件:
添加下面配置内容使用真正的服务总线名称空间替换”YOUR_NAMESPACE_NAME”和”YOUR_SAS_KEY_NAME”及”YOUR_SAS_KEY”:
|
你可以使用官方文档安装RabbitMQ或按照以下说明: 配置环境变量文件:
检查下面行:
配置环境变量文件:
将以下行添加到配置文件将“YOUR_USERNAME”和“YOUR_PASSWORD”替换为真实的信息将“localhost”和“5672”替换为真实的RabbitMQ主机和端口:
|
Confluent配置你应该创建一个帐户后访问Confluent云然后创建一个Kafka集群和 API Key。 配置环境变量文件:
检查下面行:
配置环境变量文件:
添加下面配置内容使用真正的Confluent云服务器地址替换”CLUSTER_API_KEY”, “CLUSTER_API_SECRET”和”localhost:9092”:
可以使用UI更新默认规则引擎队列配置(轮询间隔和分区)有关ThingsBoard规则引擎队列的更多信息请参阅文档。 |
Step 8. Enable monitoring (optional)
配置文件启用Grafana和Prometheus服务:
1
nano .env
MONITORING_ENABLED
变量值为true
:
1
MONITORING_ENABLED=true
部署后能够通过Prometheus:http://localhost:9090
和Grafana:http://localhost:3000
(默认用户admin
和密码foobar
)访问。
Step 9. Running
在启动Docker容器之前请运行以下命令以创建用于存储数据和日志的目录然后将其所有者更改为Docker容器用户,以便能够更改用户使用chown命令该命令需要sudo权限(该命令将要求sudo访问的密码):
1
./docker-create-log-folders.sh
执行以下命令以运行安装:
1
./docker-install-tb.sh --loadDemo
说明:
--loadDemo
-可选参数用于是否加载演示数据。
执行以下命令以启动服务:
1
./docker-start-services.sh
执行完命令后你可以http://{your-host-ip}
在浏览器中打开(例如http://localhost
)。
使用以下默认凭据:
- System Administrator: sysadmin@thingsboard.org / sysadmin
如果使用演示数据(使用--loadDemo
标志)安装了数据库则还可以使用以下凭据:
- Tenant Administrator: tenant@thingsboard.org / tenant
- Customer User: customer@thingsboard.org / customer
如有任何问题可以检查服务日志中是否有错误。 例如要查看ThingsBoard节点日志请执行以下命令:
1
docker compose -f $TB_SETUP/docker-compose.yml logs -f tb-core1 tb-rule-engine1
查看所有容器的状态:
1
docker compose -f $TB_SETUP/docker-compose.yml ps
查看运行的服务的日志:
1
docker compose -f $TB_SETUP/docker-compose.yml logs -f
请参阅docker-compose命令详细信息。
执行服务停止命令:
1
./docker-stop-services.sh
删除已部署的docker容器:
1
./docker-remove-services.sh
执行服务更新命令:
1
./docker-update-service.sh [SERVICE...]
说明
[SERVICE...]
- 更新的服务列表(docker-compose文件中定义的服务)如果未指定会更新所有服务。
升级
如果需要升级数据库请编辑.env文件以将“TB_VERSION”设置为目标版本(例如升级到最新版本请将其设置为3.5.13.4.3)然后执行以下命令:
1
2
3
./docker-stop-services.sh
./docker-upgrade-tb.sh --fromVersion=[FROM_VERSION]
./docker-start-services.sh
FROM_VERSION
- 有关有效值为开始升级版本升级说明查看fromVersion
值。
HTTPS证书
我们使用HAproxy将流量代理到容器默认情况下使用Web UI的80和443端口,将HTTPS与有效证书一起使用请执行以下命令:
1
2
docker exec haproxy-certbot certbot-certonly --domain your_domain --email your_email
docker exec haproxy-certbot haproxy-refresh
注意:当在URL中通过域名访问Web UI时使用的有效证书,通过IP地址访问UI则使用自签名证书。
Next steps
-
入门指南 - 快速学习ThingsBoard相关功能。
-
连接设备 - 学习如何根据你的连接方式或解决方案连接设备。
-
可 视 化 - 学习如何配置复杂的ThingsBoard仪表板说明。
-
数据处理 - 学习如何使用ThingsBoard规则引擎。
-
数据分析 - 学习如何使用规则引擎执行基本的分析任务。
-
硬件样品 - 学习如何将各种硬件平台连接到ThingsBoard。
-
高级功能 - 学习高级ThingsBoard功能。
-
开发指南 - 学习ThingsBoard中的贡献和开发。