Sonar

Revision as of 11:59, 10 September 2014 by WikiFreak (talk | contribs)


The following instructions are for Ubuntu 14.04 LTS.


You can find all these instructions and more on the Official how-to: http://sonar-pkg.sourceforge.net/


Requirements

You need to have a MySQL server available.


Installation (Ubuntu)

Get package

vim /etc/apt/sources.list


Add a new repository

deb http://downloads.sourceforge.net/project/sonar-pkg/deb binary/


Update packages list and install sonar

apt-get update
apt-get install sonar


Create SONAR database

SONAR needs to work with a database.

You can create a new MySQL database + MySQL user for it.


Step 1: Login to MySQL as ROOT

mysql -u root -p
Enter password:


Step 2: Create the Database

mysql > create database sonar;


Step 3: Verify that it’s there

mysql > show databases;


Step 4: Create the User

mysql > create user sonar;


Step 5: Grant privileges while assigning the password

mysql > grant all on sonar.* to 'sonar'@'localhost' identified by 'sonar';


Step 6: Apply changes

mysql > flush privileges;


Step 7: exit

mysql > quit;


Configure SONAR

Edit SONAR configuration file

vim /opt/sonar/conf/sonar.properties


Database configuration

Disable embedded H2DB and enable MySQL database, lines 20 to 40:

sonar.jdbc.username=sonar				            
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true


Port number and root context

Adjust port number and context

#sonar.web.host:             0.0.0.0
#sonar.web.port:             9000
sonar.web.context:           /sonar

!!! This is VERY important that you uncomment and set the sonar.web.context !!!



Restart Sonar

service sonar restart

... wait for some times on 1st start (5 to 7 mn) !!


Check that Sonar is up

netstat -pl --numeric | grep 9000

You should have:

tcp        0      0 0.0.0.0:9000            0.0.0.0:*               LISTEN      xxxxx/java


Add apache2 proxy rule Sonar access will be done through Apache2 server To use the proxy rule, the target /sonar must match the root URL (see sonar.properties)

vim /etc/apache2/mods-enabled/proxy.conf </syntaxhighlight>

  1. Proxy to a Java application running over Tomcat, with IP filter

<Location /sonar> ProxyPass http://localhost:9000/sonar ProxyPassReverse http://localhost:9000/sonar

       ### Apache < 2.4

#Order allow,deny #Allow from 127.0.0.1 192.168.1.0/24 193.12.118.196

       ### Apache 2.4
       Require local
       Require ip 192.168.1
       Require host 193.12.118.196

</Location>


Test Sonar Navigate to http://myServer:9000/sonar or http://myServer/sonar

The default user and password are “admin” and “admin“.

Logs Sonar logs are in: /opt/sonar/logs/sonar.log

Upgrade Sonar Sometimes when there are a lot of changes the new sonar version required some database change. The service will not be available until you go to http://myServer/sonar/setup You have to agree to the terms and upgrade database