安装

ThingsBoard安装和配置文档。

基于CentOS服务器安装ThingsBoard

先决条件

本指南描述了如何在CentOS7/8上安装ThingsBoard。

硬件要求取决于选择的数据库和连接到系统的设备数量。

需要一台1G内存的服务器运行ThingsBoard和PostgreSQL。

需要一台8G内存的服务器运行ThingsBoard和Cassandra。

在继续安装之前请执行以下命令以安装必要的工具:

CentOS 7:

# Install wget
sudo yum install -y nano wget
# Add latest EPEL release for CentOS 7
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

CentOS 8:

# Install wget
sudo yum install -y nano wget
# Add latest EPEL release for CentOS 8
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

步骤1. 安装Java 8(OpenJDK)

ThingsBoard服务正在Java 8上运行请按照以下说明安装OpenJDK 8:

sudo yum install java-1.8.0-openjdk

请不要忘记将操作系统配置为默认使用OpenJDK 8。

您可以使用以下命令配置哪个版本是默认版本:

sudo update-alternatives --config java

您可以使用以下命令检查安装:

java -version

命令输出结果:

openjdk version "1.8.0_xxx"
OpenJDK Runtime Environment (...)
OpenJDK 64-Bit Server VM (build ...)

步骤2. 安装服务

下载安装包。

wget https://github.com/thingsboard/thingsboard/releases/download/v3.1.1/thingsboard-3.1.1.rpm

安装服务

sudo rpm -Uvh thingsboard-3.1.1.rpm

步骤3. 配置数据库

ThingsBoard能够使用SQL或hybrid数据库方式。 有关更多详细信息请参见相应的体系结构页面

将PostgreSQL用于开发和生产环境ThingsBoard团队建议负载(<5000消息/秒)。

使用托管的PostgreSQL服务器对于ThingsBoard实例而言都是一种经济高效的解决方案。

PostgreSQL安装

下面列出的说明将帮助您安装PostgreSQL。

# Update your system
sudo yum update

CentOS 7:

# Install the repository RPM (for CentOS 7):
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install packages
sudo yum -y install epel-release yum-utils
sudo yum-config-manager --enable pgdg12
sudo yum install postgresql12-server postgresql12
# Initialize your PostgreSQL DB
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl start postgresql-12
# Optional: Configure PostgreSQL to start on boot
sudo systemctl enable --now postgresql-12

CentOS 8:

# Install the repository RPM (for CentOS 8):
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install packages
sudo dnf -qy module disable postgresql
sudo dnf -y install postgresql12 postgresql12-server
# Initialize your PostgreSQL DB
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl start postgresql-12
# Optional: Configure PostgreSQL to start on boot
sudo systemctl enable --now postgresql-12

一旦安装了PostgreSQL您可能想要创建一个新用户或为主要用户设置密码。

以下说明帮助你设置PostgreSQL用户密码

sudo su - postgres
psql
\password
\q

然后,按”Ctrl+D”返回主用户控制台。

配置密码后,编辑pg_hba.conf以对postgres用户使用MD5认证。

编辑pg_hba.conf文件:

sudo nano /var/lib/pgsql/12/data/pg_hba.conf

找到以下几行:

# IPv4 local connections:
host    all             all             127.0.0.1/32            ident

替换identmd5:

host    all             all             127.0.0.1/32            md5

最后,您应该重新启动PostgreSQL服务以初始化新配置:

sudo systemctl restart postgresql-12.service

连接到数据库并创建Thingsboard:

psql -U postgres -d postgres -h 127.0.0.1 -W

执行数据库创建数据库语句

CREATE DATABASE thingsboard;
\q

ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

将“PUT_YOUR_POSTGRESQL_PASSWORD_HERE”替换postgres用户真实密码

# DB Configuration 
export DATABASE_ENTITIES_TYPE=sql
export DATABASE_TS_TYPE=sql
export SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect
export SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
export SPRING_DATASOURCE_USERNAME=postgres
export SPRING_DATASOURCE_PASSWORD=PUT_YOUR_POSTGRESQL_PASSWORD_HERE
export SPRING_DATASOURCE_MAXIMUM_POOL_SIZE=5
# Specify partitioning size for timestamp key-value storage. Allowed values: DAYS, MONTHS, YEARS, INDEFINITE.
export SQL_POSTGRES_TS_KV_PARTITIONING=MONTHS

如果生产环境超过100万个数据采集频率(>5000消息/秒)ThingsBoard团队建议使用Hybrid数据库方式。

建议使用Cassandra存储时间序列数据同时将PostgreSQL用于主要实体(设备/资产/仪表板/客户)存储。

PostgreSQL安装

下面列出的说明将帮助您安装PostgreSQL。

# Update your system
sudo yum update

CentOS 7:

# Install the repository RPM (for CentOS 7):
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install packages
sudo yum -y install epel-release yum-utils
sudo yum-config-manager --enable pgdg12
sudo yum install postgresql12-server postgresql12
# Initialize your PostgreSQL DB
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl start postgresql-12
# Optional: Configure PostgreSQL to start on boot
sudo systemctl enable --now postgresql-12

CentOS 8:

# Install the repository RPM (for CentOS 8):
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install packages
sudo dnf -qy module disable postgresql
sudo dnf -y install postgresql12 postgresql12-server
# Initialize your PostgreSQL DB
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl start postgresql-12
# Optional: Configure PostgreSQL to start on boot
sudo systemctl enable --now postgresql-12

一旦安装了PostgreSQL您可能想要创建一个新用户或为主要用户设置密码。

以下说明帮助你设置PostgreSQL用户密码

sudo su - postgres
psql
\password
\q

然后,按”Ctrl+D”返回主用户控制台。

配置密码后,编辑pg_hba.conf以对postgres用户使用MD5认证。

编辑pg_hba.conf文件:

sudo nano /var/lib/pgsql/12/data/pg_hba.conf

找到以下几行:

# IPv4 local connections:
host    all             all             127.0.0.1/32            ident

替换identmd5:

host    all             all             127.0.0.1/32            md5

最后,您应该重新启动PostgreSQL服务以初始化新配置:

sudo systemctl restart postgresql-12.service

连接到数据库并创建Thingsboard:

psql -U postgres -d postgres -h 127.0.0.1 -W

执行数据库创建数据库语句

CREATE DATABASE thingsboard;
\q

Cassandra配置

下面列出的说明将帮助您安装Cassandra。

# Add cassandra repository
sudo touch /etc/yum.repos.d/datastax.repo
echo '[datastax]' | sudo tee --append /etc/yum.repos.d/datastax.repo > /dev/null
echo 'name = DataStax Repo for Apache Cassandra' | sudo tee --append /etc/yum.repos.d/datastax.repo > /dev/null
echo 'baseurl = http://rpm.datastax.com/community' | sudo tee --append /etc/yum.repos.d/datastax.repo > /dev/null
echo 'enabled = 1' | sudo tee --append /etc/yum.repos.d/datastax.repo > /dev/null
echo 'gpgcheck = 0' | sudo tee --append /etc/yum.repos.d/datastax.repo > /dev/null

# Cassandra installation
sudo yum install dsc30
# Tools installation
sudo yum install cassandra30-tools
# Start Cassandra
sudo service cassandra start
# Configure the database to start automatically when OS starts.
sudo chkconfig cassandra on
ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

将“PUT_YOUR_POSTGRESQL_PASSWORD_HERE”替换postgres用户真实密码

# DB Configuration 
export DATABASE_ENTITIES_TYPE=sql
export DATABASE_TS_TYPE=cassandra
export SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect
export SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
export SPRING_DATASOURCE_USERNAME=postgres
export SPRING_DATASOURCE_PASSWORD=PUT_YOUR_POSTGRESQL_PASSWORD_HERE
export SPRING_DATASOURCE_MAXIMUM_POOL_SIZE=5

您可以选择添加以下参数来重新配置ThingsBoard实例以连接到外部Cassandra节点:

export CASSANDRA_CLUSTER_NAME=Thingsboard Cluster
export CASSANDRA_KEYSPACE_NAME=thingsboard
export CASSANDRA_URL=127.0.0.1:9042
export CASSANDRA_USE_CREDENTIALS=false
export CASSANDRA_USERNAME=
export CASSANDRA_PASSWORD=

建议已经在生产环境中使用TimescaleDB的场景使用Timescale方式。

这种情况下使用TimescaleDB Hypertable存储时间序列数据同时将PostgreSQL用于主要实体(设备/资产/仪表板/客户)存储。

PostgreSQL安装

下面列出的说明将帮助您安装PostgreSQL。

# Update your system
sudo yum update

CentOS 7:

# Install the repository RPM (for CentOS 7):
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install packages
sudo yum -y install epel-release yum-utils
sudo yum-config-manager --enable pgdg12
sudo yum install postgresql12-server postgresql12
# Initialize your PostgreSQL DB
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl start postgresql-12
# Optional: Configure PostgreSQL to start on boot
sudo systemctl enable --now postgresql-12

CentOS 8:

# Install the repository RPM (for CentOS 8):
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install packages
sudo dnf -qy module disable postgresql
sudo dnf -y install postgresql12 postgresql12-server
# Initialize your PostgreSQL DB
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl start postgresql-12
# Optional: Configure PostgreSQL to start on boot
sudo systemctl enable --now postgresql-12

一旦安装了PostgreSQL您可能想要创建一个新用户或为主要用户设置密码。

以下说明帮助你设置PostgreSQL用户密码

sudo su - postgres
psql
\password
\q

然后,按”Ctrl+D”返回主用户控制台。

配置密码后,编辑pg_hba.conf以对postgres用户使用MD5认证。

编辑pg_hba.conf文件:

sudo nano /var/lib/pgsql/12/data/pg_hba.conf

找到以下几行:

# IPv4 local connections:
host    all             all             127.0.0.1/32            ident

替换identmd5:

host    all             all             127.0.0.1/32            md5

最后,您应该重新启动PostgreSQL服务以初始化新配置:

sudo systemctl restart postgresql-12.service

连接到数据库并创建Thingsboard:

psql -U postgres -d postgres -h 127.0.0.1 -W

执行数据库创建数据库语句

CREATE DATABASE thingsboard;
\q

TimescaleDB安装

请参考CentOS发行版的官方TimescaleDB安装页面并按照说明进行操作已安装PostgreSQL版本。

ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

添加下面配置内容使用真正的postgres用户密码替换”PUT_YOUR_POSTGRESQL_PASSWORD_HERE”:

# DB Configuration 
export DATABASE_ENTITIES_TYPE=sql
export DATABASE_TS_TYPE=timescale
export SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect
export SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
export SPRING_DATASOURCE_USERNAME=postgres
export SPRING_DATASOURCE_PASSWORD=PUT_YOUR_POSTGRESQL_PASSWORD_HERE
export SPRING_DATASOURCE_MAXIMUM_POOL_SIZE=5
# Specify Interval size for data chunks storage. Please note that this value can be set only once.
export SQL_TIMESCALE_CHUNK_TIME_INTERVAL=604800000 # Number of miliseconds. The current value corresponds to one week.

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

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

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

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

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

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

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

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

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

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

默认使用内置的内存队列无需其他配置。

Kafka

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

安装Kafka

我们建议在Docker容器中使用Kafka并使用此说明进行安装。

ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

添加下面配置内容使用真正的Kafka启动地址替换”localhost:9092”:

export TB_QUEUE_TYPE=kafka
export TB_KAFKA_SERVERS=localhost:9092

AWS SQS配置

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

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

  • Access key ID
  • Secret access key
ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

添加配置文件将”YOUR_KEY”和”YOUR_SECRET”替换为真实的AWS用户凭证并将”YOUR_REGION”替换成AWS SQS帐户区域:

export TB_QUEUE_TYPE=aws-sqs
export TB_QUEUE_AWS_SQS_ACCESS_KEY_ID=YOUR_KEY
export TB_QUEUE_AWS_SQS_SECRET_ACCESS_KEY=YOUR_SECRET
export 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: 

export TB_QUEUE_CORE_POLL_INTERVAL_MS=1000
export TB_QUEUE_CORE_PARTITIONS=2
export TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_PARTITIONS=2
export TB_QUEUE_RE_HP_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_HP_PARTITIONS=1
export TB_QUEUE_RE_SQ_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_SQ_PARTITIONS=1
export TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS=1000

Google发布/订阅配置

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

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

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

ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

添加下面配置内容使用真正用户密码替换“YOUR_PROJECT_ID”, “YOUR_SERVICE_ACCOUNT”:

export TB_QUEUE_TYPE=pubsub
export TB_QUEUE_PUBSUB_PROJECT_ID=YOUR_PROJECT_ID
export TB_QUEUE_PUBSUB_SERVICE_ACCOUNT=YOUR_SERVICE_ACCOUNT

# These params affect the number of requests per second from each partitions per each queue!!!
export TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_CORE_POLL_INTERVAL_MS=1000
export REMOTE_JS_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_HP_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_SQ_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS=1000

# 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: 

export TB_QUEUE_CORE_POLL_INTERVAL_MS=1000
export TB_QUEUE_CORE_PARTITIONS=2
export TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_PARTITIONS=2
export TB_QUEUE_RE_HP_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_HP_PARTITIONS=1
export TB_QUEUE_RE_SQ_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_SQ_PARTITIONS=1
export TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS=1000

Azure服务总线配置

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

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

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

ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

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

export TB_QUEUE_TYPE=service-bus
export TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME=YOUR_NAMESPACE_NAME
export TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME=YOUR_SAS_KEY_NAME
export TB_QUEUE_SERVICE_BUS_SAS_KEY=YOUR_SAS_KEY

# These params affect the number of requests per second from each partitions per each queue!!!
export TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_CORE_POLL_INTERVAL_MS=1000
export REMOTE_JS_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_HP_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_SQ_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS=1000

# 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: 

export TB_QUEUE_CORE_POLL_INTERVAL_MS=1000
export TB_QUEUE_CORE_PARTITIONS=2
export TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_PARTITIONS=2
export TB_QUEUE_RE_HP_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_HP_PARTITIONS=1
export TB_QUEUE_RE_SQ_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_SQ_PARTITIONS=1
export TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS=1000

RabbitMQ安装

使用此说明安装RabbitMQ。

ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

添加下面配置内容使用真正用户凭据替换”YOUR_USERNAME”和”YOUR_PASSWORD”及”localhost”、”5672”:

export TB_QUEUE_TYPE=rabbitmq
export TB_QUEUE_RABBIT_MQ_USERNAME=YOUR_USERNAME
export TB_QUEUE_RABBIT_MQ_PASSWORD=YOUR_PASSWORD
export TB_QUEUE_RABBIT_MQ_HOST=localhost
export TB_QUEUE_RABBIT_MQ_PORT=5672

Confluent云配置

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

ThingsBoard配置

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

添加下面配置内容使用真正的Confluent云服务器地址替换”CLUSTER_API_KEY”, “CLUSTER_API_SECRET”和”localhost:9092”:

export TB_QUEUE_TYPE=kafka
export TB_QUEUE_KAFKA_USE_CONFLUENT_CLOUD=true
export TB_KAFKA_SERVERS=localhost:9092
export TB_QUEUE_KAFKA_REPLICATION_FACTOR=3
export 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: 

export TB_QUEUE_CORE_POLL_INTERVAL_MS=1000
export TB_QUEUE_CORE_PARTITIONS=2
export TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_MAIN_PARTITIONS=2
export TB_QUEUE_RE_HP_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_HP_PARTITIONS=1
export TB_QUEUE_RE_SQ_POLL_INTERVAL_MS=1000
export TB_QUEUE_RE_SQ_PARTITIONS=1
export TB_QUEUE_TRANSPORT_REQUEST_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS=1000
export TB_QUEUE_TRANSPORT_NOTIFICATIONS_POLL_INTERVAL_MS=1000

步骤5. [可选]低性能配置(1GB内存)

编辑ThingsBoard配置文件

sudo nano /etc/thingsboard/conf/thingsboard.conf

将以下行添加到配置文件。

# Update ThingsBoard memory usage and restrict it to 256MB in /etc/thingsboard/conf/thingsboard.conf
export JAVA_OPTS="$JAVA_OPTS -Xms256M -Xmx256M"

步骤6. 运行安装脚本

安装ThingsBoard服务并更新数据库配置后,您可以执行以下脚本:

# --loadDemo option will load demo data: users, devices, assets, rules, widgets.
sudo /usr/share/thingsboard/bin/install/install.sh --loadDemo

步骤7. 启动服务

ThingsBoard默认使用8080端口请执行以下命令确保正确打开:

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

执行以下命令以启动ThingsBoard:

sudo service thingsboard start

启动后,您将可以使用以下链接打开Web UI:

http://localhost:8080/

如果在安装脚本的执行过程中指定了-loadDemo则可以使用以下默认凭据:

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

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

如果是1-2核CPU或1-2G内存的计算机请等待90秒后启动界面。

安装完成并配置

配置HAProxy以启用HTTPS

您可能要使用HAProxy配置HTTPS访问。

如果您在云端托管ThingsBoard并为您的实例分配了有效的DNS名称,则可以这样做。

请按照此指南安装HAProxy并使用“让我们加密”生成有效的SSL证书。

故障排除

ThingsBoard日志存储在以下目录中:

/var/log/thingsboard

执行如下命令检查后面是否有错误:

cat /var/log/thingsboard/thingsboard.log | grep ERROR

下一步

  • 入门指南 - 这些指南提供了ThingsBoard主要功能的快速概述。

  • 设备连接 - 了解如何根据您的连接方式或解决方案连接设备。

  • 数据看板 - 这些指南包含有关如何配置复杂的ThingsBoard仪表板的说明。

  • 数据处理 - 了解如何使用ThingsBoard规则引擎。

  • 数据分析 - 了解如何使用规则引擎执行基本的分析任务。

  • 硬件样品 - 了解如何将各种硬件平台连接到ThingsBoard。

  • 高级功能 - 了解高级ThingsBoard功能。

  • 开发指南 - 了解ThingsBoard中的贡献和开发。