Monday, September 11, 2017

How to install Sonarqube on Redhat enterprise Linux - Install Sonarqube on Redhat enterprise Linux (RHEL)

SonarQube is popular static code analysis tool. It is Java based tool. Here are the steps for installing Sonarqube.

first you need to install a database as SonarQube uses database to store code quality report. We can use MySQL, Postgres, Oracle or MSSQL. Here are the steps for setting up SonarQube using MySQL database :

sudo yum update -y
sudo yum install wget -y

MySQL installation steps:
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
sudo yum install mysql-server -y

Start MySQL service
sudo systemctl start mysqld
sudo mysql_secure_installation

enter n as we will not be setting any admin password for user root.

Would you like to setup VALIDATE PASSWORD component?
type n

now set up password for root user

Remove anonymous users?
type y
for Disallow root login remotely?
type y
for Remove test database and access to it?
type y
for Reload privileges tables
type y


Setup Sonarqube user and password

mysql -u root -p
SHOW GLOBAL VARIABLES LIKE 'storage_engine';
CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'password';

CREATE DATABASE sonar;
GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'localhost';

now type exit to come out of MySQL.

Sonarqube web server installation steps:

Start with java installation.

sudo wget --no-check-certificate --no-cookies --header 'Cookie: oraclelicense=accept-securebackup-cookie' 'http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm'

sudo rpm -i jdk-8u141-linux-x64.rpm

now type java -version to make sure Java 8 is installed.


Download SonarQube
cd /opt 
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.6.zip

sudo yum install unzip -y
sudo unzip sonarqube-6.7.6.zip
sudo mv sonarqube-6.7.6 sonarqube



Modify Sonar Conf file
sudo vi /opt/sonarqube/conf/sonar.properties
uncomment the below lines by removing #:

sonar.jdbc.username=sonar
sonar.jdbc.password=password
sonar.web.host=0.0.0.0
sonar.web.javaOpts=-Xmx512m -Xms256m -XX:+HeapDumpOnOutOfMemoryError
sonar.ce.javaOpts=-Xmx512m -Xms256m -XX:+HeapDumpOnOutOfMemoryError

Run Sonarqube as sonar user
create a user called sonar by executing below command:
sudo useradd sonar

sudo chown -R sonar:sonar /opt/sonarqube

Edit the sonar.sh start script and change the #RUN_AS_USER to be RUN_AS_USER=sonar

sudo vi /opt/sonarqube/bin/linux-x86-64/sonar.sh

Change 
RUN_AS_USER=sonar
now start the server 
sudo sh /opt/sonarqube/bin/linux-x86-64/sonar.sh start
for any issues, look at logs at 

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

Verify by going to browser http://hostname:9000





 

2 comments:

  1. A pretty detailed explanation, I'm grateful to you for sharing. Applying initially CSS; C# and PHP I wanted to go to testing the code with SonarQube

    immediately after installing Java itself. But some installation errors made me stuck up to clarify the circumstances and troubleshooting, but before I launch SonarQube, I made sure
    that my machine is running JavaVirtual and that the Java tutorials https://explainjava.com/enable-java-chrome/ that serve me as the main source also stayed on the hard drive and are available for work. Next, following the recommendation, I paid attention to setting up the plugins, it seems like it worked well ...

    ReplyDelete