http://docs.codehaus.org/display/SONAR/Install+Sonar
It was tested with Sonar 2.13.1
A. Getting Sonar and testing it
1. Get Sonar from:
http://www.sonarsource.org/downloads/
2. Unzip it to the
#---
unzip -x <sonar zip file> -d /opt/
#---
2.1. Example:
#---
unzip -x sonar-2.13.1.zip -d /opt/
#---
3. Start Sonar as standalone
#---
/opt/sonar-<version>/bin/linux-<arch>/sonar.sh start
#---
3.1. Example:
#---
/opt/sonar-2.13.1/bin/linux-x86-64/sonar.sh start
#---
4. Follow the logs to check that everything is ok:
#---
tail -f /opt/sonar-<version>/logs/sonar.log
#---
4.1. Example:
#---
tail -f /opt/sonar-2.13.1/logs/sonar.log
#---
NOTE: You are waiting for a line similar to:
INFO | jvm 1 | 2012/02/25 17:16:31 | 2012-02-25 17:16:31.818:INFO::Started SelectChannelConnector@0.0.0.0:9000
5. Check that Sonar is actually accepting connections:
#---
netstat -nl --inet --inet6 | grep 9000
#---
NOTE: It should return something like:
tcp 0 0 :::9000 :::* LISTEN
5.1. Open your browser to double check:
http://localhost:9000/
Login credentials:
username: admin
password: admin
B. Configuring Sonar to work with PostgreSQL
1. Check if PostgreSQL is running:
#---
systemctl status postgresql.service
#---
1.1. If not, just enable it and start it:
#---
systemctl enable postgresql.service
systemctl start postgresql.service
#---
1.2. Check if it has listeners running:
#---
netstat -nl --inet --inet6 | grep 5432
#---
NOTE: You are expecting something like this:
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN tcp 0 0 ::1:5432 :::* LISTEN
[UPDATED]
2. Setup PostgreSQL
#---
createuser -U postgres -W -D -R -S sonar
psql -U postgres -W -c "ALTER USER sonar WITH PASSWORD 'sonar';"
createdb -U postgres -W -E UTF8 -O sonar sonar
psql -U postgres -W -c "GRANT ALL ON DATABASE sonar TO sonar;"
#---
[UPDATED]
2.1. Check connection:
#---
psql -U sonar -d sonar -W -c "SELECT 1;"
#---
3. Configure Sonar:
3.1. Edit the file /opt/sonar-<version>/conf/sonar.properties
After editing it must looks like the following (after issuing the below command):
#---
cat conf/sonar.properties | grep -v "^#" | grep -v "^[[:space:]]*$"
#---
sonar.jdbc.username: sonar sonar.jdbc.password: sonar # if you gave another password this property must reflect it sonar.jdbc.url: jdbc:postgresql://localhost/sonar sonar.jdbc.driverClassName: org.postgresql.Driver sonar.jdbc.validationQuery: select 1 sonar.jdbc.schema: public sonar.jdbc.maxActive: 20 sonar.jdbc.maxIdle: 5 sonar.jdbc.minIdle: 2 sonar.jdbc.maxWait: 5000 sonar.jdbc.minEvictableIdleTimeMillis: 600000 sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 sonar.notifications.delay=60
4. Check if Sonar is ok by restarting it:
#---
/opt/sonar-<version>/bin/linux-<arch>/sonar.sh restart
#---
4.1. Example:
#---
/opt/sonar-2.13.1/bin/linux-x86-64/sonar.sh restart
#---
4.2. Keep track of the log (see step 4 of section A)
5. Check if Sonar correctly accessed the database in PostgreSQL:
#---
psql -U sonar -d sonar -W -c "\\dt"
#---
NOTE: It currently has 47 tables and it yields it on the above command with the following line:
(47 rows)
C. Test your Sonar with any project you want (below what you need for Maven projects).
1. With Maven projects you will need the following pom.xml section:
<project> <!-- your pom initial setup --> <properties> <!-- your other properties --> <sonar.jdbc.url>jdbc:postgresql://localhost/sonar</sonar.jdbc.url> <sonar.jdbc.username>sonar</sonar.jdbc.username> <sonar.jdbc.password>sonar</sonar.jdbc.password> <sonar.jdbc.driver>org.postgresql.Driver</sonar.jdbc.driver> </properties> <!-- your pom remaining setup --> </project>
2. Execute the Sonar target on your project:
#---
cd <maven project>
mvn clean sonar:sonar
#---