立即试用 商务报价
Trendz分析
Installation > 本地环境 > Ubuntu

本页目录

Installing ThingsBoard Trendz Analytics on Ubuntu

Prerequisites

This guide describes how to install Trendz Analytics on Ubuntu 18.04 LTS / Ubuntu 20.04 LTS.

Hardware requirements depend on amount of analyzed data and amount of devices connected to the system. To run Trendz Analytics on a single machine you will need at least 1Gb of free RAM.

In small and medium installations Trendz can be installed on the same server with ThingsBoard.

Step 1. Install Java 11 (OpenJDK)

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

1
2
sudo apt update
sudo apt install openjdk-11-jdk

使用以下命令设置默认版本是OpenJDK 11:

1
sudo update-alternatives --config java

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

1
java -version

命令输出结果:

1
2
3
openjdk version "11.0.xx"
OpenJDK Runtime Environment (...)
OpenJDK 64-Bit Server VM (build ...)

Step 2. Trendz Analytics service installation

Download installation package.

1
wget https://dist.thingsboard.io/trendz-1.9.2-HF2.deb

Install Trendz Analytics as a service

1
sudo dpkg -i trendz-1.9.2-HF2.deb

Step 3. Obtain and configure license key

We assume you have already chosen subscription plan for Trendz and have license key. If not, please get your Free Trial license before you proceed. See How-to get pay-as-you-go subscription for more details.

Once you get the license secret, you should put it to the trendz configuration file. Open the file for editing using the following command:

1
sudo nano /etc/trendz/conf/trendz.conf

Add the following lines to the configuration file and put your license secret:

1
2
# License secret obtained from ThingsBoard License Portal (https://license.thingsboard.io)
export TRENDZ_LICENSE_SECRET=YOUR_LICENSE_SECRET_HERE

Step 4. Configure connection with ThingsBoard Platform

You can connect Trendz Analytics to the ThingsBoard Community Edition or ThingsBoard Professional Edition.

编辑配置文件

1
sudo nano /etc/trendz/conf/trendz.conf

Add ThingsBoard REST API URL that would be used for communicating with ThingsBoard Platform. In most cases, when Trendz installed in the same server with ThingsBoard, API_URL would be http://localhost:8080. Otherwise you should use ThingsBoard domain name.

1
2
# ThingsBoard URL that will be used by Trendz
export TB_API_URL=http://localhost:8080

Step 5. Configure Trendz database

Trendz uses PostgreSQL as a database. You can install PostgreSQL on the same serverfor Trendz or use managed PostgreSQL service from your cloud vendor.

PostgreSQL Installation

PostgreSQL安装说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# install **wget** if not already installed:
sudo apt install -y wget

# import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# add repository contents to your system:
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

# install and launch the postgresql service:
sudo apt update
sudo apt -y install postgresql-12
sudo service postgresql start

创建一个新用户或为主用户设置密码

1
2
3
4
sudo su - postgres
psql
\password
\q

Create Database for Trendz

Then, press “Ctrl+D” to return to main user console and connect to the database to create trendz DB:

1
2
3
psql -U postgres -d postgres -h 127.0.0.1 -W
CREATE DATABASE trendz;
\q

Configure database connection for Trendz

Edit Trendz configuration file

1
sudo nano /etc/trendz/conf/trendz.conf

将以下行添加到配置文件 Don’t forget to replace “PUT_YOUR_POSTGRESQL_PASSWORD_HERE” with your real postgres user password:

1
2
3
4
# DB Configuration 
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/trendz
export SPRING_DATASOURCE_USERNAME=postgres
export SPRING_DATASOURCE_PASSWORD=PUT_YOUR_POSTGRESQL_PASSWORD_HERE

Step 6. Run installation script

Once Trendz service is installed and DB configuration is updated, you can execute the following script:

1
sudo /usr/share/trendz/bin/install/install.sh

Step 7. Start Trendz service

Execute the following command to start Trendz Analytics:

1
sudo service trendz start

启动后使用以下链接打开Web UI:

1
http://localhost:8888/trendz

Note: If Trendz installed on a remote server, you have to replace localhost with the public IP address of the server or with a domain name. Also, check that port 8888 opened for public access.

Authentication

For first authentication you need to use Tenant Administrator credentials from your ThingsBoard

Trendz uses ThingsBoard as an authentication service. During first sign in ThingsBoard service should be also available to validate credentials.

Step 8. HTTPS configuration

可能要使用HAProxy配置HTTPS访问。
This is possible in case you are hosting Trendz in the cloud and have a valid DNS name assigned to your instance.

Trendz and ThingsBoard hosted on same server

Use this section if HAProxy/Let’s Encrypt already installed in the server and HTTPS enabled for ThingsBoard.

Open HAProxy configuration file

1
sudo nano /etc/haproxy/haproxy.cfg

Locate frontend https_in section, add new access list that will match traffic by domain name and redirect this traffic to Trendz backend:

1
2
acl trendz_http hdr(host) -i new-trendz-domain.com
use_backend tb-trendz if trendz_http

In the same file register Trendz backend:

1
2
3
4
5
6
backend tb-trendz
  balance leastconn
  option tcp-check
  option log-health-checks
  server tbTrendz1 127.0.0.1:8888 check inter 5s
  http-request set-header X-Forwarded-Port %[dst_port]

Generate SSL certificates for new domain:

1
sudo certbot-certonly --domain new-trendz-domain.com --email some@email.io

Refresh HAProxy configuration:

1
sudo haproxy-refresh

That’s it, HTTPS for Trendz UI configured and now you can access it via: https://new-trendz-domain.com

Fresh installation on new server

Please follow this guide to install HAProxy and generate valid SSL certificate using Let’s Encrypt.

Step 9. Host ThingsBoard and Trendz on the same domain

ThingsBoard and Trendz can share same domain name. In this case ThingsBoard web page would be loaded using following link:

1
https://{my-domain}/

and Trendz web page would be loaded using following link

1
https://{my-domain}/trendz

For enabling such configuration we have to update HAProxy config to route specific requests to Trendz service. Open HAProxy configuration file

1
sudo nano /etc/haproxy/haproxy.cfg

Locate frontend https_in section, add new access list that will match traffic by URL path and redirect this traffic to Trendz backend:

1
2
3
4
...
acl trendz_acl path_beg /trendz path_beg /apiTrendz
....
use_backend tb-trendz if trendz_acl

Troubleshooting

Trendz logs are stored in the following directory:

1
/var/log/trendz

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

1
cat /var/log/trendz/trendz.log | grep ERROR

Next steps