close

This guide will help you install SonarQube on Ubuntu.

The SonarQube or formerly Sonar is an open-source platform for static code analysis and code security. SonarQube integrates into your existing workflow and detects issues in your code to help you perform continuous code inspections of your projects.

Prerequisites

  • A fresh Ubuntu 24.04 as standalone server (Physical or VM)
  • A user with sudo privileges
  • Java 17 installed (SonarQube requires a specific version of Java)

For this tutorial, we have used virtual server with the configuration of 2vCPU, 8GB RAM, 80GB SSD. It should have at least 2GB of RAM 1 CPU core and 30GB free space.

Procedure

Step 1 – System update and install Java

$sudo apt update
$sudo apt upgrade -y
$sudo apt install openjdk-17-jdk -y
$java -version

Step 2 – Install and Configure PostgreSQL

I install PostgreSQL 15 as requirement in this demo. You can choose another database (Oracle, Microsoft SQL), please check compatible version detail here

Install certificate

sudo apt install curl ca-certificates
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Run update and install PostgreSQL 15

sudo apt update
sudo apt install postgresql-15 -y

Lets configure PostgreSQL as following
– Switch to postgres user, create database and database user

sudo -i -u postgres
createuser sonar
createdb sonar -O sonar
psql
ALTER USER sonar WITH ENCRYPTED PASSWORD 'your_password';
\q
exit

Step 3 – Install and Configure SonarQube

Download and extract the SonarQube package

wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.6.0.92116.zip
unzip sonarqube-10.6.0.92116.zip
sudo mv sonarqube-10.6.0.92116.zip /opt/sonarqube

Create SonarQube user and change permission

sudo adduser --system --no-create-home --group --disabled-login sonarqube
sudo chown -R sonarqube:sonarqube /opt/sonarqube

Edit SonarQube config file
– Uncomment and set username, password, jdbc.url as below in the sonar.properties file

sudo nano /opt/sonarqube/conf/sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=your_password
sonar.jdbc.url=jdbc:postgresql://localhost/sonar

Step 4 – Configure a service,  filesystem limit and Firewall rules

  1. Create service file for SonarQube
#Create a service file
sudo nano /etc/systemd/system/sonarqube.service
#Add the following contents
[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=forking

ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop

User=sonarqube
Group=sonarqube
Restart=always

LimitNOFILE=65536
LimitNPROC=4096

[Install]
WantedBy=multi-user.target
#Reload services
sudo systemctl daemon-reload
sudo systemctl start sonarqube
sudo systemctl enable sonarqube

2. Check and set system limits

#To inscrease system limits, open below file
sudo nano /etc/security/limits.conf
#Add below lines to file
sonarqube   -   nofile   65536
sonarqube   -   nproc    4096
#Open sysctl.conf file to change virtual memory limits
sudo nano /etc/sysctl.conf
#Add following line
vm.max_map_count=262144
#Apply system changes
sudo sysctl -p

3. Config firewall rules

#Run following commands
ufw allow 9000/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload

Step 5 – Install Nginx and Config SSL Certificate

  1. Install Nginx.
    sudo apt install nginx -y
  2. Create Nginx config file for SonarQube

    sudo nano /etc/nginx/sites-available/sonarqube.example.com
    #Add following content to the sonarqube.example.com file
    server {
        listen 80;
        server_name sonarqube.example.com;
    
        access_log /var/log/nginx/sonarqube.access.log;
        error_log /var/log/nginx/sonarqube.error.log;
    
        location / {
            proxy_pass http://localhost:9000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
  3. Check and Restart Nginx service

    #Link the config file to enable when start Nginx
    sudo ln -s /etc/nginx/sites-available/sonarqube.example.com /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl restart nginx
  4. Configure SSL for Nginx domain.
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d sonarqube.example.com

Final step – Access SonarQube site.

Open web browser and access the link http (https)://IP_Address_Or_Domain:9000

References: AIX Installation Quick Start Guide

Tags : aixhmc profileibm hmcpartition profile
Administrator

The author Administrator

Leave a Response