1.环境配置

操作用户:root


系统环境:centos7.2-x86_64

     1.需要JDK1.7~支持;

     2.需要Mysql数据库支持

3.IP地址192.168.1.43


       JDK是必须安装的,Mysql数据库并不是必须要安装的,如果公司有Mysql服务器,直接拿来使用就行,


3.安装

在安装之前,介绍一下SonarQube和SonarQube Runner之间的关系。


SonarQube是服务器端,它主要有两个功能:

    1.分析源代码;

    2.因为它内嵌了Apache模块,所以提供Web端的界面访问。

    3.SonarQube Runner是一个利用SonarQube服务端分析代码的命令行工具,可以把它简单理解为客户端。


下载地址:https://downloads.sonarsource.com/sonarqube/


所以,为了安装和调试方便,SonarQube和SonarQube Runner都下载。



3.1安装SonarQube

第一步:将下载的https://downloads.sonarsource.com/sonarqube/sonarqube-5.1.2.zip sonarqube-5.1.2.zip  解压后放到/usr/local目录下。具体步骤如下:


[root@hanye opt]# wget -c http://downloads.sonarsource.com/sonarqube/sonarqube-5.1.2.zip

[root@hanye opt]# unzip sonarqube-5.1.2.zip[root@hanyeopt]# mv sonarqube-5.1.2 /usr/local/

第二步:配置环境变量


[root@hanye ~]# vi + /etc/profile 添加

SONAR_HOME=/usr/local/sonarqube-5.1.2 export SONAR_HOME

保存退出并使配置生效

[root@hanye ~]# source /etc/profile

第三步:配置sonar-runner.properties


[root@hanye ~]# vi /usr/local/sonarqube-5.1.2/conf/sonar.properties

打开后,找到

sonar.host.url=http://localhost:9000 sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:mysql://192.168.1.44:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar.web.host=0.0.0.0 

sonar.web.context=

sonar.web.port=8080

     PS:SonarQube默认监听9000端口。


第四步:启动服务


[root@hanye ~]# /usr/local/sonarqube-5.1.2/bin/linux-x86-64/sonar.sh start

另外,启动/停止/重启命令如下: 

#./sonar.sh start   启动服务 

#./sonar.sh stop    停止服务 

#./sonar.sh restart 重启服务


第四步:访问SonarQube Web管理界面。如果能够看到这个界面证明SonarQube安装成功啦。

   http://192.168.1.43:8080

3.2安装SonarQube Runner

第一步:将下载的http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip解压后放到/usr/local目录下。具体步骤如下:



[root@hanyeopt]# wget -c http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip [root@hanyeopt]# unzip sonar-runner-dist-2.4.zip [root@hanyeopt]# mv sonar-runner-2.4/ /usr/local/




[root@db-server conf]# grep -vE "^#|^$" sonar.properties

sonar.jdbc.username=root

sonar.jdbc.password=root12300.

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=10000


[root@db-server conf]# cat sonar-runner.properties

#Configure here general information about the environment, such as SonarQube DB details for example

#No information about specific project should appear here


#----- Default SonarQube server

#sonar.host.url=http://localhost:9000

sonar.host.url=http://192.168.1.44:10000


#----- PostgreSQL

#sonar.jdbc.url=jdbc:postgresql://localhost/sonar


#----- MySQL

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


#----- Oracle

#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE


#----- Microsoft SQLServer

#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor


#----- Global database settings

#sonar.jdbc.username=sonar

sonar.jdbc.username=root

sonar.jdbc.password=root12300.

#sonar.jdbc.password=sonar


#----- Default source code encoding

sonar.sourceEncoding=UTF-8


#----- Security (when 'sonar.forceAuthentication' is set to 'true')

#sonar.login=admin

#sonar.password=admin

sonar.sourceEncoding=UTF-8

sonar.projectKey=admin

sonar.projectName=admin

sonar.projectVersion=1.0

sonar.sources=.

sonar.language=java



如果是php环境  那就需要先下载php的插件和sonar.language=php