Sonarqube Code Quality Management platform installation and configuration

Source: Internet
Author: User

1. Installation Instructions

PS: Why should I have installation instructions? I find the information on the Internet when I found a lot of tutorials are not explained clearly the installation environment. Therefore, it is unclear whether their tutorials are suitable for my environment. Clear "Installation instructions" to facilitate users to understand my configuration environment, so that you understand this tutorial in depth.

Virtual machines: VmWare Workstation 12

Operation User: Root

System environment: centos6.5-x86_64 (minimized installation)

Software Download Catalog:/root/opt

================

2. Preset conditions

1. Need jdk1.6+ support;

2. mysql database support is required (although Sonarqube has its own H2 database, it is recommended to use MySQL database for easy management of data)

More say: JDK must be installed, MySQL database is not necessary to install, if the company has a MySQL server, directly to use the line, the waterfront this time there is no installation of MySQL directly from the company intranet MySQL database provided.

================

3. Installation

Before installing, please describe the relationship between Sonarqube and Sonarqube runner.

Sonarqube is a server-side, it has two functions: 1. Analyze source code; 2. Because it embeds the Apache module, it provides Web-side interface access.

SonarQube Runner is a command-line tool that leverages the SonarQube server Analysis code to make it simple to understand as a client.

: http://www.sonarqube.org/downloads/

Therefore, for easy installation and commissioning, it is recommended to download Sonarqube and Sonarqube runner.

3.1 Installing Sonarqube

The first step: Unzip the downloaded Http://downloads.sonarsource.com/sonarqube/sonarqube-5.2.zip and put it into the/usr/local directory. The steps are as follows:

[Email protected] opt]# wget-c http://downloads.sonarsource.com/sonarqube/sonarqube-5.2.zip

[Email protected] opt]# unzip-n sonarqube-5.2.zip-d/usr/local

Step Two: Configure environment variables

[Email protected] ~]# VI +/etc/profile

Add to

sonar_home=/usr/local/sonarqube-5.2

Export Sonar_home

Save exit and make configuration effective

[Email protected] ~]# Source/etc/profile

Step Three: Configure Sonar.properties

[Email protected] ~]# vi/usr/local/sonarqube-5.2/conf/sonar.properties

When opened, locate

Sonar.host.url=http://localhost:80

Sonar.jdbc.username=sonar

Sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8& Rewritebatchedstatements=true&useconfigs=maxperformance

sonar.web.host=0.0.0.0

sonar.web.context=

Sonar.web.port=80

Ps:sonarqube listens on port 9000 by default. Because I'm going to use this virtual machine specifically for sonar. As a result, the address of the MySQL server in the intranet is also changed to the 80.sonar.jdbc.url in the Internet.

Fourth step: Start the service

[Email protected] ~]# cd/usr/local/sonarqube-5.2/bin/linux-x86-64

[[email protected] ~]#./sonar.sh start

In addition, the start/stop/Restart commands are as follows:
#./sonar.sh Start Service
#./sonar.sh Stop Stop Service
#./sonar.sh Restart Restart Service

Fourth step: Access the Sonarqube Web management interface. If you can see this interface proves that the Sonarqube installation was successful.

3.2 Installing Sonarqube Runner

The first step: the downloaded http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/ Sonar-runner-dist-2.4.zip extracted and placed in the/usr/local directory. The steps are as follows:

[Email protected] opt]# wget-c http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/ Sonar-runner-dist-2.4.zip

[Email protected] opt]# unzip-n sonar-runner-dist-2.4.zip-d/usr/local

Step Two: Configure environment variables

[Email protected] ~]# VI +/etc/profile

Add to

sonar_runner_home=/usr/local/sonar-runner-2.4/

Path=.: $SONAR _runner_home/bin

Export Sonar_runner_home

environment variable settings for #包含sonar和sonar-runner

Export sonar_home=/usr/local/sonarqube-5.2

Export Sonar_runner_home=/usr/local/sonar-runner-2.4export

Path= $PATH: $SONAR _home/bin: $SONAR _runner_home/bin

Save and exit

[Email protected] ~]# Source/etc/profile

Step Three: Configure Sonar-runner.properties

[Email protected] conf]# vi/usr/local/sonar-runner-2.4/conf/sonar-runner.properties

Found it

Sonar.host.url=http://localhost:80

Sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8

Sonar.jdbc.username=sonar

Sonar.jdbc.password=sonar

Sonar.login=admin

Sonar.password=admin

Remove the previous #

PS: Just now we have seen that Sonarqube has been able to access, so we changed the Sonar.host.url to the actual access address.

Fourth step: Run Sonar-runner Analysis Source code

Sonar has provided a very full code sample for beginners to get started with.

: Https://github.com/SonarSource/sonar-examples/archive/master.zip

After downloading, use unzip decompression. Enter PHP to execute the sonar-runner command. The operation commands are as follows:

[Email protected] opt]# Wget-chttps://github.com/sonarsource/sonar-examples/archive/master.zip

[Email protected] opt]# Unzip Master.zip

[Email protected] opt]# Cdsonar-examples-master/projects/languages/php/php-sonar-runner

[Email protected] php-sonar-runner]# Sonar-runner

If you can see the following output information, prove that your Sonarqube runner is installed and configured correctly.

INFO:------------------------------------------------------------------------

Info:execution SUCCESS

INFO:------------------------------------------------------------------------

Total time:2:59.167s

Final memory:17m/204m

INFO:------------------------------------------------------------------------

Fifth step: Look at Sonarqube Web interface, whether you can see the results of the analysis.

Sonarqube The Chinese Language pack is not installed by default. Can see my display is in Chinese, because I installed the Chinese language pack. How to install a language pack. Go to the Sonarqube plugin directory and download the language pack. The steps are as follows:

[Email protected] ~]# Cd/usr/local/sonarqube-5.1.1/extensions/plugins

[Email protected] plugins]# wget-chttp://repo1.maven.org/maven2/org/codehaus/sonar-plugins/l10n/ Sonar-l10n-zh-plugin/1.8/sonar-l10n-zh-plugin-1.8.jar

PS: The latest version of the language pack is Sonar-l10n-zh-plugin-1.8.jar.

This is the Chinese Language pack source address: Https://github.com/SonarCommunity/sonar-l10n-zh

If you are interested in working with foreigners to maintain this source code, if you want to experience the latest source directly downloaded, packaged into jars can be

================

4. The pits that are trampled when configured

Sonar is a very good Code analysis tool. But many tutorials on the web are about the Jenkins+sonar configuration. If you follow the online tutorial to do it, you will collapse to death. Why? The reasons are as follows:

1. The Jenkins+sonar of many tutorials on the web is based on the analysis of Java source code. So, if you do PHP code analysis, there is a very important step is to install the PHP plugin. And if the Jenkins+sonar together to configure, a lot of pits, fill up until you collapse;

2.Jenkins is an automated build tool, and if it is used for the first time, there are many pits.

Aside from Jenkins, the source code can be analyzed directly using Sonnar. So, you need to run the Sonnar under CentOS so that it can parse the source code under the command line. Make sure this step is not a problem, and then continue to integrate with Jenkins.

I was the beginning of the Jenkins+sonar configuration, busy half a day, or the configuration is not good. It's not the problem, it's there.

================

5.SonarQube languages that can be analyzed

Sonarqube can analyze the most common and popular languages of the present. such as: ruby,python,php,css,javascript,java,go,web,c#. Support for over 20 languages. Sonarqube after successful installation, only Java can be parsed by default, and if you want it to parse other languages, you need to install plugins.

Support parsing programming language plugin address:

Http://docs.sonarqube.org/display/PLUG/Plugin+Library

If you are doing web development, you can choose to install the Php,css,javascript,web four of the line. directly into the Sonarqube plugin directory download, after successful restart Sonarqube can be.

Example: Installing the PHP Analysis plugin

[Email protected] ~]# Cd/usr/local/sonarqube-5.1.1/extensions/plugins

[Email protected] plugins]# wget-chttp://downloads.sonarsource.com/plugins/org/codehaus/sonar-plugins/php/ Sonar-php-plugin/2.6/sonar-php-plugin-2.6.jar

================

6. Reference Links

http://blog.csdn.net/hunterno4/article/details/11687269

Http://wenku.baidu.com/view/a5c2a3357375a417876f8f09.html

http://my.oschina.net/zj0303/blog/301474

Http://www.cnblogs.com/gao241/p/3190701.html

Note:

Chinese package Sonar-l10n-zh-plugin-1.6.jar in the following directory

/usr/local/sonarqube-5.2/extensions/plugins

And then restart sonar to take effect.

Cd/usr/local/sonarqube-5.2/bin/linux-x86-64

./sonar.sh Start

Sonarqube Code Quality Management platform installation and configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.