Java on Ubuntu Installation - tirta-ir/kalbe-b7-sealing-temp GitHub Wiki
Installing ThingsBoard CE using Java
This guide describes how to install ThingsBoard on Ubuntu 18.04 LTS / Ubuntu 20.04 LTS. Hardware requirements depend on chosen database and amount of devices connected to the system. To run ThingsBoard and PostgreSQL on a single machine you will need at least 1Gb of RAM. To run ThingsBoard and Cassandra on a single machine you will need at least 8Gb of RAM.
Step 1. Install Java 11 (OpenJDK)
ThingsBoard service is running on Java 11. Follow this instructions to install OpenJDK 11:
sudo apt update
sudo apt install openjdk-11-jdk
Don't forget to configure your operating system to use OpenJDK 11 by default. You can configure which version is the default using the following command:
sudo update-alternatives --config java
# Check the installation version using this command
java -version
Expected command output is:
openjdk version "11.0.xx"
OpenJDK Runtime Environment (...)
OpenJDK 64-Bit Server VM (build ...)
Step 2. ThingsBoard service installation
Download and install the thingsboard package using these commands:
# Download the installation package
wget https://github.com/thingsboard/thingsboard/releases/download/v3.6.2/thingsboard-3.6.2.deb
# Install TB as a service
sudo dpkg -i thingsboard-3.6.2.deb
Step 3. Configure ThingsBoard database
ThingsBoard is able to use SQL or hybrid database approach. But in our case, we use PostgreSQL because it's recommended for development and production environments with reasonable load. This method is a cost-effective solution for most of ThingsBoard instances.
We need to install PostgreSQL using these commands:
# 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:
echo "deb https://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-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-15
sudo service postgresql start
Once PostgreSQL is installed you may want to create a new user or set the password for the the main user. The instructions below will help to set the password for main postgresql user
stgres
psql
\password
\q
Then, press “Ctrl+D” to return to main user console and connect to the database to create thingsboard DB:
psql -U postgres -d postgres -h 127.0.0.1 -W
CREATE DATABASE thingsboard;
\q
Next, you must edit ThingsBoard configuration file with this command:
sudo nano /etc/thingsboard/conf/thingsboard.conf
Add the following lines to the configuration file. Don’t forget to replace “PUT_YOUR_POSTGRESQL_PASSWORD_HERE” with your real postgres user password:
# DB Configuration
export DATABASE_TS_TYPE=sql
export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
export SPRING_DATASOURCE_USERNAME=postgres
export SPRING_DATASOURCE_PASSWORD=PUT_YOUR_POSTGRESQL_PASSWORD_HERE
# Specify partitioning size for timestamp key-value storage. Allowed values: DAYS, MONTHS, YEARS, INDEFINITE.
export SQL_POSTGRES_TS_KV_PARTITIONING=MONTHS
Step 4. Choose ThingsBoard queue service
ThingsBoard is able to use various messaging systems/brokers for storing the messages and communication between ThingsBoard services. How to choose the right queue implementation?
-
In Memory queue implementation is built-in and default. It is useful for development(PoC) environments and is not suitable for production deployments or any sort of cluster deployments. In Memory queue is built-in and enabled by default. No additional configuration steps required.
-
Kafka is recommended for production deployments. This queue is used on the most of ThingsBoard production environments now. It is useful for both on-prem and private cloud deployments. It is also useful if you like to stay independent from your cloud provider. However, some providers also have managed services for Kafka. See AWS MSK for example.
-
RabbitMQ is recommended if you don’t have much load and you already have experience with this messaging system.
-
AWS SQS is a fully managed message queuing service from AWS. Useful if you plan to deploy ThingsBoard on AWS.
-
Google Pub/Sub is a fully managed message queuing service from Google. Useful if you plan to deploy ThingsBoard on Google Cloud.
-
Azure Service Bus is a fully managed message queuing service from Azure. Useful if you plan to deploy ThingsBoard on Azure.
-
Confluent Cloud is a fully managed streaming platform based on Kafka. Useful for a cloud agnostic deployments.
Step 5. Run installation script
Once ThingsBoard service is installed and DB configuration is updated, you can execute the following script:
# --loadDemo option will load demo data: users, devices, assets, rules, widgets.
sudo /usr/share/thingsboard/bin/install/install.sh --loadDemo
Step 7. Start ThingsBoard service
Execute the following command to start, stop, or restart ThingsBoard service:
# Start TB service
sudo service thingsboard start
# Stop TB service
sudo service thingsboard stop
# Restart TB service
sudo service thingsboard restart
Once started, you will be able to open Web UI using the following link:
http://localhost:8080/
The following default credentials are available if you have specified –loadDemo during execution of the installation script:
System Administrator: [email protected] / sysadmin Tenant Administrator: [email protected] / tenant Customer User: [email protected] / customer
You can always change passwords for each account in account profile page.
Installing Trendz using Java
If you're already installed the Java OpenJDK and PostgreSQL, then you can skip those step for installing Trendz.
Step 1. Trendz Analytics service installation
You'll need to download and install Trendz Analytics package as a service using these commands:
# Download the package
wget https://dist.thingsboard.io/trendz-1.10.3-HF3.deb
# Install Trendz as a service
sudo dpkg -i trendz-1.10.3-HF3.deb
Step 2. Obtain and configure the 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 sudo nano /etc/trendz/conf/trendz.conf
and add the following lines to the config file and put your license secret:
# License secret obtained from ThingsBoard License Portal
export TRENDZ_LICENSE_SECRET=YOUR_LICENSE_SECRET_HERE
Step 3. Configure connection with TB platform
You can connect Trendz Analytics to the ThingsBoard Community Edition or ThingsBoard Professional Edition. Edit ThingsBoard config file using 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 (e.g. https://thingsboard.cloud for cloud).
# ThingsBoard URL that will be used by Trendz
export TB_API_URL=http://localhost:8080
Step 4. Create database for Trendz
Connect to the database to create trendz DB using these commands:
psql -U postgres -d postgres -h 127.0.0.1 -W
CREATE DATABASE trendz;
\q
After that you must configure the connection within config file using sudo nano /etc/trendz/conf/trendz.conf
and Add the following lines to the configuration file. Don’t forget to replace “PUT_YOUR_POSTGRESQL_PASSWORD_HERE” with your real postgres user password:
# 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 5. Run installation script
Once Trendz service is installed and DB configuration is updated, you can execute the following script:
sudo /usr/share/trendz/bin/install/install.sh
Step 6. Start Trendz service
Execute the following command to start, stop, or restart Trendz service:
# Start Trendz service
sudo service trendz start
# Stop Trendz service
sudo service trendz stop
# Restart Trendz service
sudo service trendz restart
Once started, you will be able to open Web UI using the following link:
http://localhost:8888/
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.
Also, if you're using TB cloud then use the cloud credential rather than the pre-defined local TB credential.
Step 7. Install Trendz Python executor
For writing custom Python models and transformation script you need to install Python libraries on the server where Trendz is installed. Alternative option is to run executor as a docker container, you can find how to do that in install instructions for Docker. But in this section we will write how to install Python libraries directly on the server with Trendz.
First, install Python3 (just in case you didn't have it yet).
sudo apt update
sudo apt install python3
sudo apt install python3-pip
Then, install required python packages using these commands:
echo "flask == 2.3.2" > requirements.txt
echo "numpy == 1.24.1" >> requirements.txt
echo "statsmodels == 0.13.5" >> requirements.txt
echo "pandas == 1.5.3" >> requirements.txt
echo "scikit-learn == 1.2.2" >> requirements.txt
echo "prophet == 1.1.3" >> requirements.txt
echo "seaborn == 0.12.2" >> requirements.txt
echo "pmdarima == 2.0.3" >> requirements.txt
sudo -u trendz pip3 install --user --no-cache-dir -r requirements.txt