> For the complete documentation index, see [llms.txt](https://docs.livestreamiq.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.livestreamiq.com/readme/2.-installation/2.2-guide-for-virtual-machine-vm-installation/2.2.2-for-linux.md).

# 2.2.2 For Linux

This section outlines the prerequisites and installation procedure for deploying LivestreamIQ on a Linux operating system.

### **1. Pre-Requisite:**

Before proceeding with the installation, ensure the following requirements are met:

* Windows Server (for Ubuntu, CentOS, RHEL, Amazon Linux, etc.)
* Sudo or root access
* Java 17
* LivestreamIQ application JAR file (example -livestreamiq-4.1.2.jar)
* Postresql with timecase db
* PgAdmin for DB monitoring

### **2. Installation Steps:**

The installation process is divided into the following two parts:

1. Setup of TimescaleDB
2. Setup of LiveStreamIQ Platform
3. **Setup of TimeScaleDB**

Step 1 - Disable the Default PostgreSQL Module

1. Disable the built-in PostgreSQL module to prevent conflicts with the official PostgreSQL (PGDG) repository.<br>

   ```
   sudo dnf -qy module disable postgresql
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note:</strong> Run this even if PostgreSQL is not yet installed. It only marks the built-in stream as disabled — it removes nothing.</p></div>

Step 2: Add the PostgreSQL (PGDG) Repository

1. Install the official PostgreSQL repository.<br>

   ```
   sudo dnf install -y \
     https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
   ```

Step 3: Install PostgreSQL 16

1. Install the PostgreSQL server and client packages.<br>

   ```
   sudo dnf install -y postgresql16-server postgresql16
   ```
2. Verify the installation:<br>

   ```
   postgres --version
   psql --version
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note:</strong> Replace version 16 with any supported major PostgreSQL version (13, 14, 15, 16, or 17), as required by your deployment environment.</p></div>

Step 4: Initialize the Database Cluster

1. Initialize the PostgreSQL database cluster.<br>

   ```
   sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
   ```
2. Enable and start the PostgreSQL service.<br>

   ```
   sudo systemctl enable postgresql-16
   sudo systemctl start postgresql-16
   ```
3. Verify the service status.<br>

   ```
   sudo systemctl status postgresql-16
   ```
4. Test the database connection.<br>

   ```
   sudo -u postgres psql -c "SELECT version();"
   ```

Step 5: Add the TimescaleDB Repository

1. Create the TimescaleDB repository configuration.<br>

   ```
   sudo tee /etc/yum.repos.d/timescale_timescaledb.repo << EOL
   [timescale_timescaledb]
   name=timescale_timescaledb
   baseurl=https://packagecloud.io/timescale/timescaledb/el/$(rpm -E %{rhel})/$basearch
   repo_gpgcheck=1
   gpgcheck=0
   enabled=1
   gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
   sslverify=1
   sslcacert=/etc/pki/tls/certs/ca-bundle.crt
   metadata_expire=300
   EOL
   ```
2. Verify the repository configuration.<br>

   ```
   cat /etc/yum.repos.d/timescale_timescaledb.repo
   ```

Step 6: Install the TimescaleDB Package

1. Install the TimescaleDB extension that matches your PostgreSQL version.<br>

   ```
   sudo dnf install -y timescaledb-2-postgresql-16
   ```
2. Verify the installation.<br>

   ```
   ls /usr/pgsql-16/lib/timescaledb*.so
   ls /usr/pgsql-16/share/extension/timescaledb.control
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note:</strong> Both files must be present before proceeding.<br></p></div>

Step 7: Configure TimescaleDB

1. Run the tuning utility to automatically configure PostgreSQL for TimescaleDB.<br>

   ```
   sudo timescaledb-tune --quiet --yes
   ```

2\. Restart PostgreSQL to apply the configuration.

```
sudo systemctl restart postgresql-16
```

3. Verify that TimescaleDB has been added to the preload libraries.<br>

   ```
   sudo -u postgres psql -c "SHOW shared_preload_libraries;"
   ```

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note:</strong> The output should include <strong>timescaledb</strong>.</p></div>

Step 8: Create a Database (Optional)

1. Create a dedicated database for TimescaleDB.<br>

   ```
   sudo -u postgres psql
   ```
2. Inside psql:<br>

   ```
   CREATE DATABASE tsdb;
   \q
   ```

Step 9: Enable the TimescaleDB Extension

1. Connect to the postgres database:<br>

   ```
   sudo -u postgres psql
   ```

   \
   Or connect to a specific database:<br>

   ```
   sudo -u postgres psql -d tsdb
   ```
2. Inside psql, run:<br>

   ```
   CREATE EXTENSION IF NOT EXISTS timescaledb;
   ```
3. TimescaleDB prints a welcome banner to the console when the extension loads for the first time. After that, confirm the version:<br>

   ```
   SELECT extname, extversion FROM pg_extension WHERE extname = 'timescaledb';
   ```
4. Exit psql:<br>

   ```
   \q
   ```

{% hint style="info" %}
**Note:** CREATE EXTENSION requires superuser privileges. Always run it as the postgres user or another role with SUPERUSER.
{% endhint %}

Step 10: Verify the Installation

1. Perform the following checks to confirm that TimescaleDB has been installed successfully.
   1. **Check 1** - Verify Service is running<br>

      ```
      sudo systemctl status postgresql-16
      ```

      \
      Expected Output: Active: active (running)
   2. **Check 2** - Verify Extension is loaded<br>

      ```
      sudo -u postgres psql -c "SELECT extname, extversion FROM pg_extension WHERE extname = 'timescaledb';"
      ```

      \
      Expected Output: one row with extname = timescaledb and the current version number such as 2.24.0
   3. **Check 3** - Verify TimescaleDB configuration<br>

      ```
      sudo -u postgres psql -c "SELECT name, setting FROM pg_settings WHERE name LIKE 'timescaledb%';"
      ```

      \
      Expected Output: several rows listing TimescaleDB configuration parameters such as timescaledb.max\_background\_workers. An empty result means the library did not load - revisit Step 7.
2. **Setup of LiveStreamIQ Platform**

Step 1: Update the Operating System

1. Update the operating system packages to ensure all dependencies are current.
   1. **For Ubuntu / Debian:**<br>

      ```
      sudo apt update
      sudo apt upgrade -y
      ```
   2. **For CentOS/RHEL:**<br>

      ```
      sudo yum update -y
      ```

Step 2: Install Java 17

1. Verify whether Java is already installed.<br>

   ```
   java -version
   ```
2. If Java is not installed, install OpenJDK 17.
   1. **For Ubuntu/Debian:**<br>

      ```
      sudo apt install openjdk-17-jdk -y
      ```
   2. **For CentOS/RHEL:**<br>

      ```
      sudo yum install java-17-openjdk java-17-openjdk-devel -y
      ```
3. Verify the installation.<br>

   ```
   java -version
   ```

   \
   Expected Output: openjdk version "17.x.x"

Step 3: Create an Application User (Optional)

1. Create a dedicated user to run the LivestreamIQ service.<br>

   ```
   sudo useradd -m livestreamiq
   ```
2. Verify the user.<br>

   ```
   id livestreamiq
   ```

Step 4: Create the Application Directory

1. Create the directory that will store the application.<br>

   ```
   isudo mkdir -p /home/livestreamiq/lvs
   ```
2. Assign ownership to the application user.<br>

   ```
   sudo chown -R livestreamiq:livestreamiq /home/livestreamiq/lvs
   ```
3. Verify the directory.<br>

   ```
   sls -ld /home/livestreamiq/lvs
   ```

Step 5: Deploy the LivestreamIQ Application

1. Copy the LivestreamIQ application package to the deployment directory.<br>

   ```
   cp livestreamiq-4.1.1.jar /home/livestreamiq/lvs/
   ```
2. Verify the deployment.<br>

   ```
   ls -ltr /home/livestreamiq/lvs
   ```

   \
   Expected output: livestreamiq-4.1.1.jar

Step 6: Verify the Application

1. Run the application manually to verify that it starts successfully.<br>

   ```
   java -jar /home/livestreamiq/lvs/livestreamiq-4.1.1.jar
   ```
2. After confirming that the application starts successfully, stop it using:<br>

   ```
   Ctrl + C
   ```

Step 7: Configure LivestreamIQ as a System Service

1. Create a systemd service file.<br>

   ```
   sudo vi /etc/systemd/system/livestreamiq.service
   ```
2. Add the following configuration:

   ```
   [Unit]
   Description=LivestreamIQ Spring Boot Application
   After=network.target

   [Service]
   User=livestreamiq
   WorkingDirectory=/home/livestreamiq/lvs

   # Environment Variables
   Environment=SPRING_PROFILES_ACTIVE=prod
   Environment=LVS_DB_URL=r2dbc:postgresql://localhost:5432/lvs
   Environment=LVS_DB_USERNAME=postgres
   Environment=LVS_DB_PASSWORD=1234
   Environment=ALLOW_ORIGIN=https://www.livestreamiq.com

   # Application Startup
   ExecStart=/usr/bin/java -jar /home/livestreamiq/lvs/livestreamiq-4.1.1.jar

   # Restart Policy
   SuccessExitStatus=143
   Restart=always
   RestartSec=5

   # Logging
   StandardOutput=journal
   StandardError=journal

   [Install]
   WantedBy=multi-user.target
   ```

Step 8: Enable and Start the Service

1. Reload the systemd configuration.<br>

   ```
   sudo systemctl daemon-reload
   ```
2. Enable the service to start automatically during system boot.<br>

   ```
   sudo systemctl enable livestreamiq
   ```
3. Start the service.<br>

   ```
   sudo systemctl start livestreamiq
   ```

Step 9: Verify the Service

1. Check the service status.<br>

   ```
   sudo systemctl status livestreamiq
   ```

   \
   Expected Output: Active: active (running)

Step 10: Monitor Application Logs

1. View real-time application logs.<br>

   ```
   sudo journalctl -u livestreamiq -f
   ```
2. View the most recent log entries.<br>

   ```
   sudo journalctl -u livestreamiq -n 100
   ```

Step 11: Manage the LivestreamIQ Service

1. Use the following commands to manage the LivestreamIQ service.
   1. Start LivestreamIQ Service:<br>

      ```
      sudo systemctl start livestreamiq
      ```
   2. Stop LivestreamIQ Service:<br>

      ```
       sudo systemctl stop livestreamiq
      ```
   3. Restart LivestreamIQ Service:<br>

      ```
       sudo systemctl restart livestreamiq
      ```
   4. Status LivestreamIQ Service:<br>

      ```
       sudo systemctl status livestreamiq
      ```
   5. Disable Auto Start LivestreamIQ Service:<br>

      ```
       sudo systemctl disable livestreamiq
      ```

Step 12: Verify the Application Port

1. Verify that the application is listening on the expected network port.<br>

   ```
   sudo ss -tulpn | grep java
   ```

   \
   Alternatively:<br>

   ```
   sudo netstat -tulpn | grep java
   ```
2. For performing the Troubleshooting:
   1. Service Fails to Start:<br>

      ```
      sudo journalctl -u livestreamiq -f
      ```

      \
      Review the application logs for startup errors.
   2. Java Not Found:\
      Verify the Java installation and executable path.

      ```
      which java
      ```

      \
      *Update the ExecStart path if required.*
   3. Service Continuously Restarts.\
      Review the detailed service logs.<br>

      ```
      sudo journalctl -xeu livestreamiq
      ```
3. Then, Verify the following:

* The LivestreamIQ JAR file exists in the deployment directory.
* PostgreSQL and TimescaleDB are running and accessible.
* Database connection details are correctly configured.
* The required application ports are available and not in use.
* The Java runtime version is compatible with the application.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.livestreamiq.com/readme/2.-installation/2.2-guide-for-virtual-machine-vm-installation/2.2.2-for-linux.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
