install sonarqube

We can install sonarqube on centos 7/8. we can also create a sonarqube service to start and stop it. Let’s see, how to install sonarqube on centos 7.

SonarQube is an open-source platform that is designed to continuously check the code quality to perform an automatic review with static analysis of code to detect the bugs, code smell, and security vulnerabilities.

Sonarqube requirements at least 2 GB of RAM and 1 GB ram for the Operating systems. It also requires excellent read/write on the hard drive to perform the operations.

Check Out: How To Install Brave Browser On Ubuntu 20.04/19.10

How To Install Sonarqube 6 On CentOS / Redhat 7/8:

Sonarqube 6 required the Java version 8 installed on the Linux. You can use the below link to download it.

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

Once you have downloaded the Package, we need to extract it to the below location.

unzip sonarqube-6.7.6.zip -d /opt/

Now go the location using /opt/sonarqube-6.7.6/conf and take a backup of the original files.

cp sonar.properties sonar.properties-org
cp wrapper.conf wrapper.conf-org 

Change the owner of the SonarQube directory folder.

chown -R sonarqube:sonarqube /opt/sonarqube-6.7.6

Create a user using useradd sonarqube and set the password with the command passwd sonarqube

Check Out: How To Force Quit Application Running on Windows 8/10

Before starting the configuration for sonarqube, we need to set a few parameters for Elasticsearch.

sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536

Create a database for Sonarqube:

I will use MySQL as a database server for Sonarqube. You can also other databases as well. I have installed the database on the same server.

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all privileges on sonar.* to 'sonar'@'localhost' identified by 't0res#fQ3cr3t';
mysql> flush privileges;

Check if you’re able to access the database using the above credentials.

mysql -u sonar -h localhost -p

you must be able to log in if not, you need to check the permission.

Check Out: How To Configure Samba Server For File Sharing On CentOS 7

Sonarqube Installation configuration:

Open the sonar.properties and add the below parameters.

sonar.jdbc.username=sonar
sonar.jdbc.password=t0re#fQ3cr3t
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.web.host=192.168.223.220
sonar.web.context=/sonar 
sonar.web.port=9001

Set the java path in the /opt/sonarqube-6.7.6/conf/wrapper.conf file.

wrapper.java.command=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/bin/java

you need to check the java path in your machine and changed it. You can use whereis java command to find the path.

Check Out: How To Edit Hosts File For Changes In Windows 7/10

Once you have configured the settings, you have to open the port 9001 in the firewall rules.

firewall-cmd --permanent --add-port=9001/tcp
firewall-cmd --reload

Create a service for Sonarqube:

We need to manually create service for sonarqube if you don’t want to run it using sonar.sh from the directory

vim /etc/systemd/system/sonarqube.service 
[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=simple
User=sonarqube
Group=sonarqube
PermissionsStartOnly=true
ExecStart=/bin/nohup java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /opt/sonarqube-6.7.6/lib/sonar-application-6.7.6.jar
StandardOutput=syslog
LimitNOFILE=65536
LimitNPROC=8192
TimeoutStartSec=5
Restart=always

[Install]
WantedBy=multi-user.target

Start and enable the service using the below commands.

systemctl start sonarqube && systemctl enable sonarqube

create sonarqube service

Go to the browser and hit the URL: http://192.168.223.220:9001/sonar

sonarqube install

Log in using the username admin and password admin. 

sonarqube java version requirements

That’s it. Create sonarqube service

LEAVE A REPLY

Please enter your comment!
Please enter your name here