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

本页目录

Installing ThingsBoard Trendz Analytics on CentOS/RHEL

Prerequisites

This guide describes how to install Trendz Analytics on RHEL/CentOS 7/8.

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.

Before continue to installation execute the following commands in order to install necessary tools:

For CentOS 7:

1
2
3
4
5
# 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

For CentOS 8:

1
2
3
4
5
# 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

Step 1. Install Java 11 (OpenJDK)

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

1
sudo yum install java-11-openjdk

使用以下命令设置默认版本是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.rpm

Install Trendz Analytics as a service

1
sudo rpm -Uvh trendz-1.9.2-HF2.rpm

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

Instructions listed below will help you to install PostgreSQL.

1
2
# Update your system
sudo yum update

For CentOS 7:

1
2
3
4
5
6
7
8
9
10
11
12
# 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

For CentOS 8:

1
2
3
4
5
6
7
8
9
10
11
# 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

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

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

Then, press “Ctrl+D” to return to main user console.

After configuring the password, edit the pg_hba.conf to use MD5 authentication with the postgres user.

Edit pg_hba.conf file:

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

Locate the following lines:

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

Replace ident with md5:

1
host    all             all             127.0.0.1/32            md5

Finally, you should restart the PostgreSQL service to initialize the new configuration:

1
2
sudo systemctl restart postgresql-12.service

Create Database for Trendz

Connect to the database to create trendz DB:

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

Execute create database statement

1
2
3
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