How to install and configure SonarQube on CentOS 7

SonarQube is an open-source platform for continuous inspection of code quality. It is used to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities on more than 20 programming languages.

Here we are going to install and configure SonarQube 7.9.x LTS with Oracle JAVA 11, PostgreSQL 10.x, Nginx, and Let’s Encrypt certificates.

Installing and configuring SonarQube on CentOS

Execute the following commands using the root user.

1. Update System

yum update

2. Disable SELinux

Open SELinux configuration and edit the file:

vim /etc/sysconfig/selinux

Change “SELINUX=enforcing” to “SELINUX=disabled”.

Save and exit the file.

3. Set hostname to the server

 vim /etc/hostname

If vim is not available, install vim command first.

 yum install vim -y

Then reboot the system.


4. Prerequisite

You can check the official document for complete information.

  • Java (Oracle JRE 11 or OpenJDK 11)
  • PostgreSQL 10 or 9.3–9.6

Hardware Requirements

  • Server with 2GB or plus RAM
  • Systems setting for Linux

vm.max_map_count is greater or equals to 262144
fs.file-max is greater or equals to 65536
the user running SonarQube can open at least 65536 file descriptors
the user running SonarQube can open at least 4096 threads

5. Add System settings

Edit “sysctl.conf” file:

vim /etc/sysctl.conf

Add the following lines:


Sysctl Values
Sysctl Values

Save and exit the file.

6. Install Oracle Java 11

Download Oracle JDK 11 from here.

Oracle JAVA
Oracle JAVA

Before you download, it will redirect to the oracle login. If you have an account, use it or create a new one.

Oracle Login
Oracle Login

You can download the rpm package to your machine and upload it to the sonar server.

OR you can use the following steps:

a) You can copy the download link from web browser downloads.

Copy Download Link
Copy Download Link

b) Then go to your server and download using the “wget” command.


download using wget
download using wget

c) If “wget” command is not available in your system to install it using the following command:

 yum install wget -y

Rename the downloaded file.

 mv jdk-11.0.5_linux-x64_bin.rpm?AuthParam=1573886978_5511f6acaa0b321333446e8e838c1045 jdk-11.0.5_linux-x64_bin.rpm

Install Oracle JDK:

yum localinstall jdk-11.0.5_linux-x64_bin.rpm

Install Oracle JDK
Install Oracle JDK

Java installed in the following location:

cd /usr/java/

Java Installed Location
Java Installed Location

Add java environment variables:

vim /etc/bashrc

Add following lines to end of the file:

export JAVA_HOME=/usr/java/jdk-11.0.5/
export JRE_HOME=/usr/java/jdk-11.0.5/jre


Add Environment Variables
Add Environment Variables

Save and exit the file and check the java version.

java -version

Check Java Version
Check Java Version

7. Install PostgreSQL 10

You can see downloads for Redhat based distributions here.

Install repository first:

yum install

Install repository
Install repository

Install server:

yum install postgresql10-server postgresql10-contrib

Install postgresql10
Install postgresql10

Initialize the database:

/usr/pgsql-10/bin/postgresql-10-setup initdb

Initialize Database
Initialize Database

Modify pg_hba.conf file; change “peer” to “trust” and “idnet” to “md5”.

vim /var/lib/pgsql/10/data/pg_hba.conf

Change file
Change file

After the modification is done, the file should be as follows:

After Modification
After Modification

To start service and set on boot, enable PostgreSQL on system boot:

systemctl enable postgresql-10

Check service status and start it.

systemctl status postgresql-10
systemctl start postgresql-10

Change the default password of the Postgres user:

passwd postgres

Switch to the Postgres user.

su - postgres

Create a new user.

createuser sonar

Switch to PostgreSQL shell.


PostgreSQL shell
PostgreSQL shell

Set a password for the newly created user for the SonarQube database:

ALTER USER sonar WITH ENCRYPTED password 'd98ffW@123?Q';

Create a new database for the PostgreSQL database.


Exit from the psql shell.


Exit from the “postgres” user.


User and Database
User and Database

8. Download and configure SonarQube

We are going to download the package in to “opt” directory. So change directory

cd /opt

Here we are going to use 7.9.x LTS version and can be download here

I. Download Latest LTS version


II. Then unzip


If unzip command not available. Install unzip.

yum install unzip -y

III. Rename folder

mv sonarqube-7.9.1 sonarqube

IV. Modify “ file”.

vim /opt/sonarqube/conf/

Find the following lines. Then uncomment and modify values.

sonar.web.javaOpts=-server -Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError

Configuring the Elasticsearch storage path:

Save and exit the file.

V. Create a user for sonar

useradd sonar

Set password:

passwd sonar

VI. Modify folder permissions

chown -R sonar:sonar /opt/sonarqube

Create the following folders and grant permission:

mkdir -p /var/sonarqube/data
mkdir -p /var/sonarqube/temp
chown -R sonar:sonar /var/sonarqube

VII. Setting up Sonarqube as a service

vim /etc/systemd/system/sonarqube.service

Add the following content to file:

Description=SonarQube service

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


Reload “systemctl” daemon and enable sonar on system boot.

systemctl daemon-reload
systemctl enable sonarqube.service

Start service and check its status.

systemctl start sonarqube.service
systemctl status sonarqube.service

Sonar Status
Sonar Status

VIII. logfile location

cd /opt/sonarqube/logs/
  • SonarQube service log
tail -f /opt/sonarqube/logs/sonar.log
  • Web Server Logs
tail -f /opt/sonarqube/logs/web.log
  • ElasticSearch logs
tail -f /opt/sonarqube/logs/es.log
  • Compute Engine logs
tail -f /opt/sonarqube/logs/ce.log

9. Configure reverse proxy

Install Nginx, start service, and enable on system boot.

yum install -y nginx
systemctl start nginx
systemctl enable nginx

10. Configure SSL

Enable epel repo and install certbot.

yum install – y epel-release
yum install certbot python2-certbot-nginx

Run the following command to get a certificate and have Certbot edit your Nginx configuration automatically to serve it, turning on HTTPS access in a single step.

certbot --nginx

Command will ask questions . Then add needed details according to that.


Certbot Configurations
Certbot Configurations

After installation is done, open nginx.conf.

vim /etc/nginx/nginx.conf

You should see certbot SSL configuration.

After SSL configuration
After SSL configuration

Then add the following contents to a Location Blocks.

location / {

proxy_pass "";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;


Save and exit the file. The modified file looks like below:

Nginx Configurations
Nginx Configurations

Check nginx syntax:

nginx -t

Restart nginx:

systemctl restart nginx

11. DNS

Then go to your DNS manager and add A record for your sonar server.

A   Domain Name   Server IP

12. Modify Firewall Rules

If you have the firewall enabled, run the following command to open https traffic.

firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload

Firewall Rule HTTPS
Firewall Rule HTTPS

if you need to open sonar for specific IP, run the below command:

firewall-cmd --permanent --zone=public --add-rich-rule="
rule family="ipv4"
source address=""
port protocol="tcp" port="443" accept"
firewall-cmd --reload

13. Browse Sonarqube

Go to your browser and type your domain name.


Browse Sonarqube
Browse Sonarqube

Then click “login.”

14. Login page

The default username and password is “admin”.



Dash Board

Now we configured SonarQube successfully. In our upcoming articles, we will see how to integrate SonarQube with Jenkins.

Categorized as CentOS

Leave a comment

Your email address will not be published. Required fields are marked *