在Linux系统中安装ThingsBoard

This guide describes how to install ThingsBoard on a Linux based server machine. Instructions below are provided for Ubuntu 16.04 and CentOS 7. These instructions can be easily adapted to other similar operating systems.

本指南描述了如何Linux的服务器上安装ThingsBoard。以下是Ubuntu 16.04和CentOS 7的安装说明。这些指令也可以适应其他类似的操作系统。

硬件需求

To run ThingsBoard and third-party components on a single machine you will need at least 1Gb of RAM.

要在一台机器上运行ThingsBoard和第三方组件,你至少需要1Gb RAM

第三方组件安装

Java

ThingsBoard service is running on Java 8. Although you are able to start the service using OpenJDK, the solution is actively tested on Oracle JDK.

ThingBoard在Java8环境中运行。虽然你可以使用OpenJDK启动ThingsBoard,但是测试验证ThingsBoard在Oracle JDK中运行较好。

Follow this instructions to install Oracle JDK 8:

请按照以下指令安装Oracle JDK 8:

Please don’t forget to configure your operating system to use Oracle JDK 8 by default. Corresponding instructions are in the same articles listed above.

请将默认操作系统配置为Oracle JDK 8。

[非必要] 外部数据库安装

ThingsBoard is able to use SQL or NoSQL(Cassandra) database layer. By default, ThingsBoard uses embedded HSQLDB instance which is very convenient for evaluation or development purposes. If this is your first experience with ThingsBoard we recommend to skip this step and use the embedded database.

ThingsBoard可以使用SQL或NoSQL(Cassandra)数据库。默认情况下,ThingsBoard使用内置的HSQLDB,HSQLDB方便评估和开发。如果您是第一次接触ThingsBoard,我们建议您跳过这一步,先使用内置数据库进行体验。

Alternatively, you can configure your platform to use either scalable Cassandra DB cluster or various SQL databases. If you prefer to use an SQL database, we recommend PostgreSQL.

或者,您可以使用可扩展的Cassandra DB集群或SQL数据库。如果您选择使用SQL数据库,我们推荐您使用PostgreSQL。

SQL数据库: PostgreSQL

NOTE: This is an optional step. It is required only for production usage. You can use embedded HSQLDB for platform evaluation or development

注意,此步骤仅供生产使用,可跳过。你可以使用HSQLDB来进行评估和开发。

Instructions listed below will help you to install PostgreSQL.

可根据以下指令安装PostgreSQL。

Ubuntu CentOS
resources/postgresql-ubuntu-installation.sh resources/postgresql-centos-installation.sh
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
sudo service postgresql start
# Update your system
sudo yum update
# Install packages
sudo yum install postgresql-server postgresql-contrib
# Initialize your PostgreSQL DB
sudo postgresql-setup initdb
sudo systemctl start postgresql
# Optional: Configure PostgreSQL to start on boot
sudo systemctl enable postgresql

Once PostgreSQL is installed you may want to create a new user or set the password for the the main user.

PostgreSQL安装完成后,请创建一个新用户或者为主用户设置密码。

See the following guides for more details: using postgresql roles and databases and changing the postgres user password

When it’s done, connect to the database and create thingsboard DB:

连接数据库创建thingsboard DB:

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

CREATE DATABASE thingsboard;
\q

NoSQL数据库: Cassandra

NOTE: This is an optional step. It is required only for production usage. You can use embedded HSQLDB for platform evaluation or development

注意,此步骤仅供生产使用,可跳过。你可以使用HSQLDB来评估和开发。

Instructions listed below will help you to install Cassandra.

请按照如下指令安装Cassandra。

Ubuntu CentOS
resources/cassandra-ubuntu-installation.sh resources/cassandra-centos-installation.sh
# Add cassandra repository
echo 'deb http://www.apache.org/dist/cassandra/debian 39x main' sudo tee --append/etc/apt/sources.list.d/cassandra.list > /dev/null
curl https://www.apache.org/dist/cassandra/KEYS sudo apt-key add -
sudo apt-get update
## Cassandra installation
sudo apt-get install cassandra
## Tools installation
sudo apt-get install cassandra-tools

ThingsBoard服务安装

Download installation package or build it from source.

下载安装包或者build it from source.

Ubuntu CentOS
resources/thingsboard-ubuntu-download.sh resources/thingsboard-centos-download.sh
wget https://github.com/thingsboard/thingsboard/releases/download/v1.3/thingsboard-1.3.deb wget https://github.com/thingsboard/thingsboard/releases/download/v1.3/thingsboard-1.3.rpm

将ThingsBoard安装为服务

Ubuntu CentOS
resources/thingsboard-ubuntu-installation.sh resources/thingsboard-centos-installation.sh
sudo dpkg -i thingsboard-1.3.deb sudo rpm -Uvh thingsboard-1.3.rpm

[非必要] 配置ThingsBoard使用外部数据库

NOTE: This is an optional step. It is required only for production usage. You can use embedded HSQLDB for platform evaluation or development

注意,此步骤仅供生产使用,可跳过。你可以使用HSQLDB来评估和开发。

Edit ThingsBoard configuration file

编辑ThingsBoard配置文件

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

Comment ‘# HSQLDB DAO Configuration’ block.

注释‘# HSQLDB DAO Configuration’

# HSQLDB DAO Configuration
#spring:
#  data:
#    jpa:
#      repositories:
#        enabled: "true"
#  jpa:
#    hibernate:
#      ddl-auto: "validate"
#    database-platform: "org.hibernate.dialect.HSQLDialect"
#  datasource:
#    driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.hsqldb.jdbc.JDBCDriver}"
#    url: "${SPRING_DATASOURCE_URL:jdbc:hsqldb:file:${SQL_DATA_FOLDER:/tmp}/thingsboardDb;sql.enforce_size=false}"
#    username: "${SPRING_DATASOURCE_USERNAME:sa}"
#    password: "${SPRING_DATASOURCE_PASSWORD:}"
PostgreSQL:

Uncomment ‘# PostgreSQL DAO Configuration’ block.

去除‘# PostgreSQL DAO Configuration’注释

# PostgreSQL DAO Configuration
spring:
  data:
    jpa:
      repositories:
        enabled: "true"
  jpa:
    hibernate:
      ddl-auto: "validate"
    database-platform: "org.hibernate.dialect.PostgreSQLDialect"
  datasource:
    driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}"
    url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}"
    username: "${SPRING_DATASOURCE_USERNAME:postgres}"
    password: "${SPRING_DATASOURCE_PASSWORD:postgres}"
Cassandra DB:

Locate and set database type configuration parameter to ‘cassandra’.

定位数据类型参数并将该参数配置为‘cassandra’。

database:
  type: "${DATABASE_TYPE:cassandra}" # cassandra OR sql

slow machines (1GB of RAM)内存更新

We recommend to use embedded HSQLDB or PostgreSQL DB in this setup. We don’t recommend to use Cassandra on machines with less then 4GB of RAM.

在此设置中我们建议使用内置HSQLDB或者PostgreSQL DB。RAM少于4GB不建议使用Cassandra。

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

运行安装脚本

Once ThingsBoard service is installed, you can execute the following script:

ThingsBoard服务安装完成后可以执行以下脚本:

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

启动ThingsBoard服务

执行以下命令启动ThingsBoard:

sudo service thingsboard start

Once started, you will be able to open Web UI using the following link:

启动后,使用以下链接打开Web页面:

http://localhost:8080/

NOTE: Please allow up to 90 seconds for the Web UI to start

故障排除

ThingsBoard logs are stored in the following directory:

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

/var/log/thingsboard

You can issue the following command in order to check if there are any errors on the backend side:

您可以执行以下命令来检查后端是否发生错误:

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

results matching ""

    No results matching ""