Install and configure SonarQube on Ubuntu 16.04 LTS
Install and configure SonarQube on Ubuntu 16.04 LTS
SonarQube is a cost less and open informant platform of the quality management that is very useful in inspection of the automate code.It has many features such as calculate the set of metrics, examine the code of the files and display the output on the dashboard that is web based.As it is mostly written in Java language but it also assist other language as PHP,Ruby and perl. SonarQube by default aid h2 database , but it is not compatible.
So,other database server example MYSQL,Oracle,PostgreSQL and MSSQL also integrate with it. SOnarQube support many plugins that combine the code from the repositories automatically. It permit the developer in more than 20 different language to identify fragility and bugs as well as to reduce code smells. All of person smoothly integrate it with Visual Studio,IntelliJ IEDA and Eclipse improvement atmospheres through the SonarLint Plugins.
Obligatory as a earlier condition.
a) A latest Ubuntu 16.04 server install on system you have.
b) Required Minimum 4 GB of RAM.
c) non-root user with sudo privileges
Now we will begin to install and configure SonarQube on Ubuntu 16.04 LTS
Before going to start, it is prescribe to update base system you have with the new version. You can just click it and run the given command:
admin@solutionclub:~$ sudo apt-get update -y admin@solutionclub:~$ sudo apt-get upgrade -y
1. Install Java on Machine/Server
As it is said that Sonarqube is an application that is based on Java,So it is recommend that first you have to install Java 8.Java 8 is not accessible on Ubuntu repository. You have the option to install it with the support of webupd8team PPA to your system.
First of all PPA should add with the under given command :
admin@solutionclub:~$ sudo add-apt-repository ppa:webupd8team/java
Now, you can update the repository with the pursuing command:
admin@solutionclub:~$ sudo apt-get update -y
Once it is up to date, you now install Java 8 by running the pursuing command:
admin@solutionclub:~$ sudo apt-get install oracle-java8-installer -y
After Java installing done, you can also check the version of it with the pursuing command:
admin@solutionclub:~$ java -version
Once you are finished, then can move to the next step.
2.Basic configuration and installation of the Apache and MariaDB
You will also required to install Apache and MySQL 5.6, because we will use Apache for reverse proxy and Mysql 5.6 as a database. You simply install both by running the pursuing command:
admin@solutionclub:~$ sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe' admin@solutionclub:~$ sudo apt-get install apache2 mysql-server-5.6 -y
Once the installation is finished, you can start Apache and MariaDB service and enable them to jump on boot with the pursing command:
admin@solutionclub:~$ sudo systemctl restart apache2 admin@solutionclub:~$ sudo systemctl enable apache2 admin@solutionclub:~$ sudo systemctl restart mysql admin@solutionclub:~$ sudo systemctl enable mysql
3. Now Configure MySQL with primary steps.
By default MariaDB installation is not safeguarded, so we will required to secure MySQL installation. You can complete it by pursing the mysql_secure_installation script:
admin@solutionclub:~$ sudo mysql_secure_installation
Login Mysql/Mariadb server as root
admin@solutionclub:~$ mysql -u root -p
Enter your root password when prompt, then generate a database for SonarQube:
> CREATE DATABASE solutionclub_sonar;
Next, bring about a new database user and deliver the appropriate releases to your database user over the database that you have fabricated.
> GRANT ALL PRIVILEGES ON solutionclub_sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'XXXXXX';
Next, refer the changes to the database privileges with the given command:
> FLUSH PRIVILEGES;
In the last, exit from the MariaDB shell with the under given command:
> \q
4. Installation SonarQube
For download the new version of the SonarQube from their official website. You also download it with the wget command:
admin@solutionclub:~$ wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-7.0.zip
When downloading is completed, unzip the downloaded archive using the ensuing command:
admin@solutionclub:~$ sudo unzip sonarqube-7.0.zip -d /opt
After That , rename uts directory with the ensuing command:
admin@solutionclub:~$ sudo mv /opt/sonarqube-7.0 /opt/sonar
Now, you will covet to rectify the SonarQube main configuration file sonar.properties:
admin@solutionclub:~$ sudo nano /opt/sonar/conf/sonar.properties
Make the ensuing changes:
##Database User credentials: sonar.jdbc.username=sonar sonar.jdbc.password=yourpassword sonar.jdbc.url=jdbc:mysql://localhost:3306/solutionclub_sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
Save and close the file, then create a systemd service file for SonarQube.
admin@solutionclub:~$ sudo nano /etc/systemd/system/sonar.service
Add the given lines:
[Unit] Description=SonarQube service After=syslog.target network.target [Service] Type=forking ExecStart=/opt/sonar/bin/linux-x86-64/sonar.sh start ExecStop=/opt/sonar/bin/linux-x86-64/sonar.sh stop User=root Group=root Restart=always [Install] WantedBy=multi-user.target
Save the file when you completed and start the SonarQube service and allow it to begin at boot with the following command:
admin@solutionclub:~$ sudo systemctl start sonar admin@solutionclub:~$ sudo systemctl enable sonar
SonarQube process have some time to halt for creating database and populating data. You can see the status of SonarQube with the given command:
admin@solutionclub:~$ sudo systemctl status sonar
You can also monitor the refine by seeking into the contents of /opt/sonar/logs/sonar.log file. Once you done, you can move to the next step.
If you need to use URL without port then you can configure it as Reverse Proxy.
5. Configure Apache as a Reverse Proxy
By default, SonarQube listens is on port 9000. Here, we will try apache as a reverse proxy so that SonarQube can be approached using port 80:
First step is to enable the apache proxy module with the command:
admin@solutionclub:~$ sudo a2enmod proxy admin@solutionclub:~$ sudo a2enmod proxy_http
Afterward, generate a new virtual host file for SonarQube with this command:
admin@solutionclub:~$ sudo nano /etc/apache2/sites-available/sonar.conf
Sum the following lines:
<VirtualHost *:80> ServerName www.solutionclub.in ServerAdmin [email protected] ProxyPreserveHost On ProxyPass / http://localhost:9000/ ProxyPassReverse / http://localhost:9000/ TransferLog /var/log/apache2/sonar_access.log ErrorLog /var/log/apache2/sonar_error.log </VirtualHost>
Save and close the file and enable new virtual host by running the following command:
admin@solutionclub:~$ sudo a2ensite sonar
In the end, restart apache service with the following command:
admin@solutionclub:~$ sudo systemctl restart apache2
If you have install nginx in your machine then use follow steps down.
server { listen 80; server_name solutionclub.in www.solutionclub.in; location / { proxy_pass http://localhost:9000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
Now, Open your web browser and navigate to URL http://192.168.100.110, you should see the following screen:
Now, click on the “Log in” button, you should see the following screen:
First cube was not working because elasticsearch did not allow root. only figured that out after setting the log levels to DEBUG.
Now in a fresh environment with a user it still does not work, i get :
sudo -S systemctl start sonar
Job for sonar.service failed because the control process exited with error code. See “systemctl status sonar.service” and “journalctl -xe” for details.
sudo -S systemctl status sonar
● sonar.service – SonarQube service
Loaded: loaded (/etc/systemd/system/sonar.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Sun 2018-09-16 20:30:27 UTC; 7s ago
Process: 697 ExecStart=/opt/sonar/bin/linux-x86-64/sonar.sh start (code=exited, status=203/EXEC)
Sep 16 20:30:27 sonarqube systemd[1]: Failed to start SonarQube service.
Sep 16 20:30:27 sonarqube systemd[1]: sonar.service: Unit entered failed state.
Sep 16 20:30:27 sonarqube systemd[1]: sonar.service: Failed with result ‘exit-code’.
Sep 16 20:30:27 sonarqube systemd[1]: sonar.service: Service hold-off time over, scheduling restart.
Sep 16 20:30:27 sonarqube systemd[1]: Stopped SonarQube service.
Sep 16 20:30:27 sonarqube systemd[1]: sonar.service: Start request repeated too quickly.
Sep 16 20:30:27 sonarqube systemd[1]: Failed to start SonarQube service.
HI Ddeboer
Which database you are try to connect with sonarqube and check database connectivity.
Hi I am getting same issue “Job for sonarqube.service failed because the control process exited with error code. See “systemctl status sonarqube.service” and “journalctl -xe” for details.” And my database is external server(i.e aws postgres server, on ec2 machine sonarqube is installed.
And what is the best practise. Installing sonarqube & DB on same server. Or installing sonarqube & DB are separate servers.
1. Can you share with me error logs ..?
2. Are you able to connect postgresql ..?