SonarQube Server Installation

in #linux8 years ago

SonarQube Server Installation




Sonar

For more information on the SonarQube Server, visit sonatype.org


Description:


SonarQube is an open platform to manage code quality.


Pre-Requisites:


Install the packages that are needed to support SonarQube


COMPATABILITY NOTICE:

These instructions were constructed on SonarQube 5.6.1 LTS.


1.    Database:
SonarQube requires a database connection. Either install a local MySQL/Postgres instance, or on a remote MySQL/Postgres server create a new database to hold the SonarQube DB. In this tutorial we will be using a remote database server that is running PostgreSQL 9.4.


On the PostgreSQL database server, not the SonarQube Server, create the database

CREATE DATABASE sonarqube;
CREATE USER sonar WITH PASSWORD 'qubemin123';
GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonar;


Set connection permissions

vim /var/lib/pgsql/9.4/data/pg_hba.conf
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    sonarqube       sonar           10.0.0.9/32             md5


Reload the permission set

  • This step will be done as the postgres user (su postgres)
/usr/pgsql-9.4/bin/pg_ctl reload -D /var/lib/pgsql/9.4/data/


2.    Dependancies:

RHEL   RHEL   &   CentOS   CentOS:

yum clean all
yum -y install sudo vim wget unzip net-tools java-1.8.0-openjdk.x86_64


Verify Java

java -version
openjdk version "1.8.0_101"
OpenJDK Runtime Environment (build 1.8.0_101-b13)
OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)



Debian   Debian   &   Ubuntu   Ubuntu:

Install the backports list server, containing openjdk-8

echo "deb http://ftp.de.debian.org/debian jessie-backports main" >> /etc/apt/sources.list


Update Apt

apt-get update


Install OpenJDK 8

apt-get -y install openjdk-8-jdk


Install other dependancies

apt-get -y install sudo vim wget unzip


Verify Java

java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-1~bpo8+1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)



Installation:



RHEL   RHEL   &   CentOS   CentOS:

1.    Install the repo:

wget -O /etc/yum.repos.d/sonar.repo http://downloads.sourceforge.net/project/sonar-pkg/rpm/sonar.repo


2.    Install Sonarqube:

yum -y install sonar



Debian   Debian   &   Ubuntu   Ubuntu:

1.    Install the repo:

echo "deb http://downloads.sourceforge.net/project/sonar-pkg/deb binary/" >> /etc/apt/sources.list


2.    Install Sonarqube:

apt-get update
apt-get -y --force-yes install sonar


Configuration:


1.    Database Config:
Edit the sonar.properties file and configure database access

vim /opt/sonar/conf/sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=qubemin123
sonar.jdbc.url=jdbc:postgresql://10.0.0.5/sonarqube


Settings for the web server can also be set in this file

sonar.web.host=0.0.0.0
sonar.web.port=8080
sonar.web.context=


Firewall Rules:


In the event that a connection can not be established, ensure a firewall rule exists to allow the traffic


RHEL   RHEL/CentOS 7 FirewallD:

firewall-cmd --zone=public --permanent --add-port=8080/tcp
firewall-cmd --reload


IPTables:

iptables -A INPUT -p tcp --dport 8080 --jump ACCEPT
iptables-save
# Generated by iptables-save v1.4.21 on Sun Jul 31 13:34:40 2016
*filter
:INPUT ACCEPT [54:4032]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [30:3624]
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
COMMIT
# Completed on Sun Jul 31 13:34:40 2016


Start the server:


/etc/init.d/sonar start
Starting SonarQube...
Started SonarQube.



Login:


Open your web browser and go to the ip of the server.

http://10.0.0.9:8080


Default Credentials:

username: admin
password: admin


Post Requisites:


Optionally install the Sonar Runner. The Sonar Runner is responsible for running your test cases and posting the results to SonarQube.


1.    Download:

mkdir -p /opt/sonar_scanner
chown sonar /opt/sonar_scanner
cd /opt/sonar_scanner
wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.6.1.zip
unzip sonar-scanner-2.6.1.zip


2.    Configure:

cd /opt/sonar_scanner/sonar-scanner-2.6.1/conf/
vim sonar-scanner.properties
#----- Default SonarQube server
sonar.host.url=http://localhost:8080


3.    Export Path:

Export the path to the sonar runner/scanner binaries

export PATH=$PATH:/opt/sonar_scanner/sonar-scanner-2.6.1/bin


References:


clusterfrak.com
Sonar Install Docs
Sonar Package Repos
SonarQube Scanner 2.6.1

Sort:  

Interesting thoughts