基于Docker(Windows)安装ThingsBoard (2023)

基于Docker(Windows)安装ThingsBoard (1)

IoT PaaS演示


我们建议使用ThingsBoard专业版在线演示了解并体验最新功能!

使用云端默认提供的设备、仪表板和邮件服务可以节省你的安装和配置时间来创建新客户和用户。

  • 先决条件
  • 运行
  • 步骤4. 选择消息队列服务
  • 分离、停止和启动
  • 升级
  • 故障排除
    • DNS问题
  • 下一步

本指南将帮助你在Windows上使用Docker安装和启动ThingsBoard。

先决条件

运行

根据所使用的数据库有三种类型的ThingsBoard单实例docker映像:

  • thingsboard/tb-postgres - ThingsBoard与PostgreSQL数据库的单实例

    对于具有至少1GB内存的小型服务器的推荐选项。建议使用2-4GB。

  • thingsboard/tb-cassandra - 具有Cassandra数据库的ThingsBoard的单个实例。

    最高性能和推荐的选项,但至少需要4GB的RAM。建议使用8GB。

  • thingsboard/tb - 具有嵌入式HSQLDB数据库的ThingsBoard的单个实例。

    注意: 不建议用于任何评估或生产用途,仅用于开发目的和自动测试。

在此说明中,将使用thingsboard/tb-postgres镜像。你可以选择其他具有不同数据库的镜像(请参见上文)。

Windows用户应将Docker托管卷用于ThingsBoard数据库。

在执行docker run命令之前创建docker卷(例如mytb-data):

打开”Docker Quickstart Terminal”。执行以下命令以创建Docker卷:

docker volume create mytb-datadocker volume create mytb-logs

执行以下命令以直接运行docker:

$ docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp -v mytb-data:/data -v ~/mytb-logs:/var/log/thingsboard --name mytb --restart always thingsboard/tb-postgres

步骤4. 选择消息队列服务

选择下面消息中间件代理服务之前的通信。

  • 内存 默认队列适用于开发环境很有用请勿用于生产环境。

  • Kafka 对于本地和私有云部署可以独立于云服务供应商生产环境中使用。

  • RabbitMQ 如果没有太多负载并且已经具备一定的使用经验建议使用此方式。

  • AWS SQS 如是你打算在AWS上使用ThingsBoard则可以使用此消息队列。

  • Google发布/订阅 如果你打算在Google Cloud上部署ThingsBoard则可以使用此消息队列。

  • Azure服务总线 如果你打算在Azure上部署ThingsBoard则可以使用此消息队列。

  • Confluent云 基于Kafka的完全托管的事件流平台。

参见相应的架构页面和规则引擎页面以获取更多详细信息。

ThingsBoard默认使用内存队列服务无需额外设置。

创建docker compose文件:

docker-compose.yml

将以下行添加到yml文件:

version: '2.2'services: mytb: restart: always image: "thingsboard/tb-postgres" ports: - "8080:9090" - "1883:1883" - "5683:5683/udp" environment: TB_QUEUE_TYPE: in-memory volumes: - mytb-data:/data - mytb-logs:/var/log/thingsboardvolumes: mytb-data: external: true mytb-logs: external: true

Kafka

Apache Kafka是一个开放源代码的流处理软件平台。

创建docker compose文件:

docker-compose.yml

将以下行添加到yml文件。

version: '2.2'services: zookeeper: restart: always image: "zookeeper:3.5" ports: - "2181:2181" environment: ZOO_MY_ID: 1 ZOO_SERVERS: server.1=zookeeper:2888:3888;zookeeper:2181 kafka: restart: always image: wurstmeister/kafka depends_on: - zookeeper ports: - "9092:9092" environment: KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_LISTENERS: INSIDE://:9093,OUTSIDE://:9092 KAFKA_ADVERTISED_LISTENERS: INSIDE://:9093,OUTSIDE://kafka:9092 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE volumes: - /var/run/docker.sock:/var/run/docker.sock mytb: restart: always image: "thingsboard/tb-postgres" depends_on: - kafka ports: - "8080:9090" - "1883:1883" - "5683:5683/udp" environment: TB_QUEUE_TYPE: kafka TB_KAFKA_SERVERS: kafka:9092 volumes: - mytb-data:/data - mytb-logs:/var/log/thingsboardvolumes: mytb-data: external: true mytb-logs: external: true

AWS SQS配置

首先需要创建一个AWS账户然后访问AWS SQS服务。

要使用AWS SQS服务您将需要使用此说明创建下一个凭证。

  • Access key ID
  • Secret access key

创建docker compose文件:

docker-compose.yml

将以下行添加到yml文件用真实的AWS用户凭证替换”YOUR_KEY”, “YOUR_SECRET”并用“AWS SQS帐户区域”替换”YOUR_REGION”:

version: '2.2'services: mytb: restart: always image: "thingsboard/tb-postgres" ports: - "9090:9090" - "1883:1883" - "5683:5683/udp" environment: TB_QUEUE_TYPE: aws-sqs TB_QUEUE_AWS_SQS_ACCESS_KEY_ID: YOUR_KEY TB_QUEUE_AWS_SQS_SECRET_ACCESS_KEY: YOUR_SECRET TB_QUEUE_AWS_SQS_REGION: YOUR_REGION # These params affect the number of requests per second from each partitions per each queue. # Number of requests to particular Message Queue is calculated based on the formula: # ((Number of Rule Engine and Core Queues) * (Number of partitions per Queue) + (Number of transport queues) # + (Number of microservices) + (Number of JS executors)) * 1000 / POLL_INTERVAL_MS # For example, number of requests based on default parameters is: # Rule Engine queues: # Main 10 partitions + HighPriority 10 partitions + SequentialByOriginator 10 partitions = 30 # Core queue 10 partitions # Transport request Queue + response Queue = 2 # Rule Engine Transport notifications Queue + Core Transport notifications Queue = 2 # Total = 44 # Number of requests per second = 44 * 1000 / 25 = 1760 requests #  # Based on the use case, you can compromise latency and decrease number of partitions/requests to the queue, if the message load is low. # Sample parameters to fit into 10 requests per second on a "monolith" deployment:  TB_QUEUE_CORE_POLL_INTERVAL_MS: 1000 TB_QUEUE_CORE_PARTITIONS: 2 TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_PARTITIONS: 2 TB_QUEUE_RE_HP_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_HP_PARTITIONS: 1 TB_QUEUE_RE_SQ_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_SQ_PARTITIONS: 1 TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS: 1000 volumes: - ~/.mytb-data:/data - ~/.mytb-logs:/var/log/thingsboardvolumes: mytb-data: external: true mytb-logs: external: true
(Video) Windows10开发环境搭建(3) | 在WSL2里安装Docker

Google发布/订阅配置

创建一个Google云帐户并访问发布/订阅服务。

使用此说明创建一个项目并使用发布/订阅服务。

使用此说明创建服务帐户凭据并编辑角色管理员后保存json凭据步骤9的文件此处

创建docker compose文件:

docker-compose.yml

将以下行添加到yml文件用真实的帐户信息替换 “YOUR_PROJECT_ID”, “YOUR_SERVICE_ACCOUNT”**

version: '2.2'services: mytb: restart: always image: "thingsboard/tb-postgres" ports: - "8080:9090" - "1883:1883" - "5683:5683/udp" environment: TB_QUEUE_TYPE: pubsub TB_QUEUE_PUBSUB_PROJECT_ID: YOUR_PROJECT_ID TB_QUEUE_PUBSUB_SERVICE_ACCOUNT: YOUR_SERVICE_ACCOUNT # These params affect the number of requests per second from each partitions per each queue. # Number of requests to particular Message Queue is calculated based on the formula: # ((Number of Rule Engine and Core Queues) * (Number of partitions per Queue) + (Number of transport queues) # + (Number of microservices) + (Number of JS executors)) * 1000 / POLL_INTERVAL_MS # For example, number of requests based on default parameters is: # Rule Engine queues: # Main 10 partitions + HighPriority 10 partitions + SequentialByOriginator 10 partitions = 30 # Core queue 10 partitions # Transport request Queue + response Queue = 2 # Rule Engine Transport notifications Queue + Core Transport notifications Queue = 2 # Total = 44 # Number of requests per second = 44 * 1000 / 25 = 1760 requests #  # Based on the use case, you can compromise latency and decrease number of partitions/requests to the queue, if the message load is low. # Sample parameters to fit into 10 requests per second on a "monolith" deployment:  TB_QUEUE_CORE_POLL_INTERVAL_MS: 1000 TB_QUEUE_CORE_PARTITIONS: 2 TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_PARTITIONS: 2 TB_QUEUE_RE_HP_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_HP_PARTITIONS: 1 TB_QUEUE_RE_SQ_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_SQ_PARTITIONS: 1 TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS: 1000 volumes: - mytb-data:/data - mytb-logs:/var/log/thingsboardvolumes: mytb-data: external: true mytb-logs: external: true

Azure服务总线配置

创建一个Azure帐户并访问Azure服务总线。

通过使用说明了解并使用总线服务。

使用说明创建共享访问签名。

创建docker compose文件:

docker-compose.yml

添加下面配置内容使用真正服务总线名称空间替换”YOUR_NAMESPACE_NAME”和”YOUR_SAS_KEY_NAME”及”YOUR_SAS_KEY”:

(Video) 树莓盘安装体验:远程访问不限速的私有网盘系统

version: '2.2'services: mytb: restart: always image: "thingsboard/tb-postgres" ports: - "8080:9090" - "1883:1883" - "5683:5683/udp" environment: TB_QUEUE_TYPE: service-bus TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME: YOUR_NAMESPACE_NAME TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME: YOUR_SAS_KEY_NAME TB_QUEUE_SERVICE_BUS_SAS_KEY: YOUR_SAS_KEY # These params affect the number of requests per second from each partitions per each queue. # Number of requests to particular Message Queue is calculated based on the formula: # ((Number of Rule Engine and Core Queues) * (Number of partitions per Queue) + (Number of transport queues) # + (Number of microservices) + (Number of JS executors)) * 1000 / POLL_INTERVAL_MS # For example, number of requests based on default parameters is: # Rule Engine queues: # Main 10 partitions + HighPriority 10 partitions + SequentialByOriginator 10 partitions = 30 # Core queue 10 partitions # Transport request Queue + response Queue = 2 # Rule Engine Transport notifications Queue + Core Transport notifications Queue = 2 # Total = 44 # Number of requests per second = 44 * 1000 / 25 = 1760 requests #  # Based on the use case, you can compromise latency and decrease number of partitions/requests to the queue, if the message load is low. # Sample parameters to fit into 10 requests per second on a "monolith" deployment:  TB_QUEUE_CORE_POLL_INTERVAL_MS: 1000 TB_QUEUE_CORE_PARTITIONS: 2 TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_PARTITIONS: 2 TB_QUEUE_RE_HP_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_HP_PARTITIONS: 1 TB_QUEUE_RE_SQ_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_SQ_PARTITIONS: 1 TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS: 1000 volumes: - mytb-data:/data - mytb-logs:/var/log/thingsboardvolumes: mytb-data: external: true mytb-logs: external: true

RabbitMQ安装

请使用此说明安装RabbitMQ。

创建docker compose文件:

docker-compose.yml

将以下行添加到yml文件用真实用户凭据替换”YOUR_USERNAME”和”YOUR_PASSWORD并修改”localhost”和”5672”为真实的RabbitMQ主机和端口:

version: '2.2'services: mytb: restart: always image: "thingsboard/tb-postgres" ports: - "8080:9090" - "1883:1883" - "5683:5683/udp" environment: TB_QUEUE_TYPE: rabbitmq TB_QUEUE_RABBIT_MQ_USERNAME: YOUR_USERNAME TB_QUEUE_RABBIT_MQ_PASSWORD: YOUR_PASSWORD TB_QUEUE_RABBIT_MQ_HOST: localhost TB_QUEUE_RABBIT_MQ_PORT: 5672 volumes: - mytb-data:/data - mytb-logs:/var/log/thingsboardvolumes: mytb-data: external: true mytb-logs: external: true

Confluent云配置

你应该创建一个帐户后访问Confluent云然后创建一个Kafka集群API Key

创建docker compose文件:

docker-compose.yml

将以下行添加到yml文件用真正的Confluent云服务器地址替换”CLUSTER_API_KEY”, “CLUSTER_API_SECRET”和”localhost:9092”:

version: '2.2'services: mytb: restart: always image: "thingsboard/tb-postgres" ports: - "8080:9090" - "1883:1883" - "5683:5683/udp" environment: TB_QUEUE_TYPE: kafka TB_KAFKA_SERVERS: localhost:9092 TB_QUEUE_KAFKA_REPLICATION_FACTOR: 3 TB_QUEUE_KAFKA_USE_CONFLUENT_CLOUD: true TB_QUEUE_KAFKA_CONFLUENT_SASL_JAAS_CONFIG: org.apache.kafka.common.security.plain.PlainLoginModule required username="CLUSTER_API_KEY" password="CLUSTER_API_SECRET";} # These params affect the number of requests per second from each partitions per each queue. # Number of requests to particular Message Queue is calculated based on the formula: # ((Number of Rule Engine and Core Queues) * (Number of partitions per Queue) + (Number of transport queues) # + (Number of microservices) + (Number of JS executors)) * 1000 / POLL_INTERVAL_MS # For example, number of requests based on default parameters is: # Rule Engine queues: # Main 10 partitions + HighPriority 10 partitions + SequentialByOriginator 10 partitions = 30 # Core queue 10 partitions # Transport request Queue + response Queue = 2 # Rule Engine Transport notifications Queue + Core Transport notifications Queue = 2 # Total = 44 # Number of requests per second = 44 * 1000 / 25 = 1760 requests #  # Based on the use case, you can compromise latency and decrease number of partitions/requests to the queue, if the message load is low. # Sample parameters to fit into 10 requests per second on a "monolith" deployment:  TB_QUEUE_CORE_POLL_INTERVAL_MS: 1000 TB_QUEUE_CORE_PARTITIONS: 2 TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_MAIN_PARTITIONS: 2 TB_QUEUE_RE_HP_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_HP_PARTITIONS: 1 TB_QUEUE_RE_SQ_POLL_INTERVAL_MS: 1000 TB_QUEUE_RE_SQ_PARTITIONS: 1 TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS: 1000 TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS: 1000 volumes: - mytb-data:/data - mytb-logs:/var/log/thingsboardvolumes: mytb-data: external: true mytb-logs: external: true
(Video) How to install ThingsBoard Professional edition on Windows machine?

说明:

  • docker run - 运行容器
  • -it - 将终端会话与当前ThingsBoard进程输出连接
  • 8080:9090 - 将本地端口8080转发至HTTP端口9090
  • 1883:1883 - 将本地端口1883转发至MQTT端口1883
  • 5683:5683 - 将本地端口5683转发至MQTT端口5683
  • ~/.mytb-data:/data - 将主机的目录~/.mytb-data挂载到ThingsBoard数据目录
  • ~/.mytb-logs:/var/log/thingsboard - 将主机的目录~/.mytb-logs挂载到ThingsBoard日志目录
  • mytb - 计算机本地名称
  • restart: always - 在系统重新启动的情况下自动启动ThingsBoard在出现故障的情况下自动重新启动ThingsBoard。
  • image: thingsboard/tb-postgres - docker镜像也可以是thingsboard/tb-cassandrathingsboard/tb

执行以下命令以直接将此Docker组合起来:

注意:要运行docker compose命令你必须位于带有docker-compose.yml文件的目录中。

docker-compose pulldocker-compose up

为了从Windows计算机上的外部IP/主机访问必需的资源请执行以下命令:

set PATH=%PATH%;"C:\Program Files\Oracle\VirtualBox"VBoxManage controlvm "default" natpf1 "tcp-port8080,tcp,,8080,,9090" VBoxManage controlvm "default" natpf1 "tcp-port1883,tcp,,1883,,1883"VBoxManage controlvm "default" natpf1 "tcp-port5683,tcp,,5683,,5683"

说明:

  • C:\Program Files\Oracle\VirtualBox - VirtualBox安装目录的路径

执行完命令后你可以http://{your-host-ip}:9090在浏览器中打开(例如http://localhost:9090)。使用以下默认凭据:

  • 系统管理员: sysadmin@thingsboard.org / sysadmin
  • 租户管理员: tenant@thingsboard.org / tenant
  • 客户: customer@thingsboard.org / customer

你始终可以在帐户详情页面中更改每个帐户的密码。

(Video) customize thingsboard logo

分离、停止和启动

你可以使用Ctrl-p Ctrl-q - 与会话终端分离-容器将继续在后台运行.

要重新连接到终端(查看ThingsBoard日志),请运行:

分离容器:

如有任何问题你可以检查服务日志中是否有错误。

例如要查看ThingsBoard节点日志请执行以下命令:

docker-compose logs -f mytbpe

停止容器:

docker-compose stop

启动容器:

docker-compose start

升级

为了更新到最新的镜像请执行以下命令::

$ docker pull thingsboard/tb-postgres$ docker-compose stop$ docker run -it -v mytb-data:/data --rm thingsboard/tb-postgres upgrade-tb.sh$ docker rm mytb$ docker-compose up

注意: 如果你使用不同的数据库,则在所有命令中将映像名称从更改为thingsboard/tb-postgresthingsboard/tb-cassandrathingsboard/tb correspondingly.

注意: 将主机的目录替换为~/.mytb-data容器创建期间使用的目录.

故障排除

DNS问题

注意 如果你发现与DNS问题相关的错误,例如

127.0.1.1:53: cannot unmarshal DNS message

你可以配置系统以使用Google公用DNS服务

下一步

Videos

1. install thingsboard in ubuntu server
(riyo santo yosep)
2. Integrate The Things Stack with ThingsBoard - Alex Doan (ThingsBoard)
(The Things Network)
3. Thingsboard Step by Step Installation in Ubuntu.
(RKiLAB)
4. ThingsBoard IoT System Platform For Data Collection and Visualize Data
(Dev Insights)
5. ThingsBoard Professional Edition: How to purchase the perpetual license?
(ThingsBoard)
6. ThingsBoard CE education: Lesson 7. Simple ThingsBoard aliases
(ThingsBoard)
Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated: 05/03/2023

Views: 6519

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.