Tuesday, April 7, 2020

Setup SonarQube Server on Azure VM | Install SonarQube Server on Ubuntu VM in Azure Cloud

Please find steps for installing SonarQube on a Ubuntu VM running in Azure Cloud. SonarQube is open source, Java based tool along with backend, Database can be MySQL, Oracle or PostgreSQL. We will use PostgreSQL which is open source for database with SonarQube installation.

Make sure port 9000 is opened as port 9000 is default port for SonarQube.
Ubuntu 16.0.4 instance at least 2 GM RAM

How to open port 9000 in Azure VM?

1. Select VM, under Settings--> choose Network

2. Click on Add inbound security role

3. Make sure you add entries like below: 
9000 as Destination port ranges
TCP as protocol
310 as priority number
port_9000 as Name

 4. Click on Add, once you add it should be like below:

Let us start with java installation on Azure VM.

1. Java 8 Installation steps

sudo apt-get update && sudo apt-get install default-jdk -y

2. PostgreSQL Installation

PostgreSQL is a popular open source database tool.

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

sudo wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

sudo apt-get -y install postgresql postgresql-contrib

sudo systemctl start postgresql
sudo systemctl enable postgresql
Login as postgres user now
sudo su - postgres

Now create a user below
createuser sonar

Switch to sql shell by entering

Execute the below three lines (one by one)

ALTER USER sonar WITH ENCRYPTED password 'password';


to come out of PSQL.

type exit to come out of postgres user.

3. Now install SonarQube Web App

sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.4.zip

Extract SonarQube Zip file
sudo apt-get -y install unzip
sudo unzip sonarqube-6.4.zip -d /opt

Re-name the folder
sudo mv /opt/sonarqube-6.4 /opt/sonarqube -v

Modify Sonar configuration file

sudo vi /opt/sonarqube/conf/sonar.properties
uncomment the below lines by removing # and add values highlighted yellow

Next, Add the below line for PostgreSQL

Now press escape, and enter :wq! to come out of the above screen.

Create Sonar as a service
Execute the below command (and add the below code in green color)
sudo vi /etc/systemd/system/sonar.service

Description=SonarQube service
After=syslog.target network.target


inux-x86-64/sonar.sh start
nux-x86-64/sonar.sh stop



Once copied, enter :wq! and enter to come out of the screen.

Now perform the below commands

sudo systemctl enable sonar
sudo systemctl start sonar
sudo systemctl status sonar
type q now to come out of this mode.
Now execute the below command to see if Sonarqube is up and running. This may take a few minutes.

tail -f /opt/sonarqube/logs/sonar.log

Press Contrl-C to come out of the above window.
Make sure you get the below message that says Sonarqube is up..


Access SonarQube UI by going to browser and enter public_ip_address with port 9000
You should be able to login to SonarQube using default credentials -->  admin/admin

No comments:

Post a Comment