本篇文章由 VeriMake 旧版论坛中备份出的原帖的 Markdown 源码生成
原帖标题为:在 Ubuntu 服务器上 (阿里云 VPS) 安装 ThingsBoard 及运行
原帖网址为:https://verimake.com/topics/177 (旧版论坛网址,已失效)
原帖作者为:hi(旧版论坛 id = 70,注册于 2020-09-23 11:08:34)
原帖由作者初次发表于 2021-03-24 17:12:46,最后编辑于 2021-03-24 17:12:46(编辑时间可能不准确)
截至 2021-12-18 14:27:30 备份数据库时,原帖已获得 1004 次浏览、1 个点赞、0 条回复
Step1 安装 putty
使用 putty 进行远程连接和控制操作系统,点我下载 如图,进行下载。
下载后就出现如下界面,在IP address下输入自己服务器的公网ip地址,点击open。
出现如下界面,输入用户名 root ,输入自己设置的服务器密码,如下图显示成功连接服务器。
Step2 安装 Java 8
在服务器上安装 OpenJDK 8:
sudo apt update
sudo apt install openjdk-8-jdk
将操作系统配置为默认使用 OpenJDK 8
sudo update-alternatives --config java
检查安装情况
java -version
出现以下情况表示安装成功
openjdk version "1.8.0_xxx"
OpenJDK Runtime Environment (...)
OpenJDK 64-Bit Server VM (build ...)
Step3 安装 Things Board
下载 Things Board 压缩包
wget https://github.com/thingsboard/thingsboard/releases/download/v3.2.1/thingsboard-3.2.1.deb
安装 Things Board
sudo dpkg -i thingsboard-3.2.1.deb
Step4 配置 Things Board 数据库—— PostgreSQL
依次执行如下代码安装 postgreSQL
sudo apt install -y wget
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
RELEASE=$(lsb_release -cs)
echo "deb http://apt.postgresql.org/pub/repos/apt/ ${RELEASE}"-pgdg main | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt -y install postgresql-11
sudo service postgresql start
创建一个表
sudo su - postgres
psql
\password #这一步执行完需要输入设定密码,建议输入posgres作为密码
\q #这一步操作完,按ctrl+D返回到原来的目录下
在数据库中建一个表
psql -U postgres -d postgres -h 127.0.0.1 -W #这一步执行完,输入上边设置的密码
CREATE DATABASE thingsboard;
\q
进入编辑器编辑 Things Board 配置文件
sudo nano /etc/thingsboard/conf/thingsboard.conf
进入后编辑器里如果有如下内容,说明前面操作没有错误,如果是空白的,那么说明前面有部分操作是错误的,建议回去复盘。
#
# Copyright © 2016-2021 The Thingsboard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
export JAVA_OPTS="$JAVA_OPTS -Dplatform=deb -Dinstall.data_dir=/usr/share/thing>
export JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/thingsboard/gc.log -XX:+IgnoreUnr>
export JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution >
export JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=10M -XX:-UseBiasedLocking -XX:+U>
export JAVA_OPTS="$JAVA_OPTS -XX:CMSWaitDuration=10000 -XX:+UseParNewGC -XX:+Us>
export JAVA_OPTS="$JAVA_OPTS -XX:+CMSEdenChunksRecordAlways -XX:CMSInitiatingOc>
export LOG_FILENAME=thingsboard.out
export LOADER_PATH=/usr/share/thingsboard/conf,/usr/share/thingsboard/extensions
export SQL_DATA_FOLDER=/usr/share/thingsboard/data/sql
在编辑器下面加以下内容,并且在 PUT_YOUR_POSTGRESQL_PASSWORD_HERE的位置替换成自己设置的密码
# 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
###Step5 安装 apache2
sudo apt-get install apache2
启动 apache2
sudo /etc/init.d/apache2 start
这时在浏览器中输入你的 IP,出现 It works!说明连接,网页可被打开。
Step6 运行安装脚本
sudo /usr/share/thingsboard/bin/install/install.sh --loadDemo
运行后出现如下情况表明操作成功
===================================================
:: ThingsBoard :: (v3.2.1)
===================================================
Starting ThingsBoard Installation...
Installing DataBase schema for entities...
Installing SQL DataBase schema part: schema-entities.sql
Installing SQL DataBase schema indexes part: schema-entities-idx.sql
Installing DataBase schema for timeseries...
Installing SQL DataBase schema part: schema-ts-psql.sql
Successfully executed query: CREATE TABLE IF NOT EXISTS ts_kv_indefinite PARTITION OF ts_kv DEFAULT;
Loading system data...
Loading demo data...
Installation finished successfully!
ThingsBoard installed successfully!
Step7 启动 Things Board
sudo service thingsboard start
一旦启动,在浏览器中输入网址就可以看到 Things Board 用户界面
http://localhost(换成公网IP):8080/
进入 Things Board 页面后使用默认用户账号登陆
租户帐号:tenant@thingsboard.org
租户密码:tenant