sonarqube代码检测

1、安装java环境

2、下载sonarqube包

sonarqube与sonar-runner的下载地址: http://www.sonarqube.org/downloads/
将下载好的软件包解压到指定目录,并配置环境变量:
mkdir /usr/local/sonar

unzip -o sonarqube-5.1.1.zip -d /usr/local/sonar

unzip -o sonar-runner-dist-2.4.zip -d /usr/local/sonar



vim /etc/profile

export JAVA_HOME=/usr/java/latest

export CLASSPATH=/usr/java/latest/lib:/usr/java/latest/jre/lib

export SONAR_HOME=/usr/local/sonar/sonarqube-5.1.1

export SONAR_RUNNER_HOME=/usr/local/sonar/sonar-runner-2.4

export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$RONAR_RUNNER_HOME/bin

3、配置mysql,创建sonar数据库,并授权

mysql> create database sonar;

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

4、修改sonarqube的配置文件

vim /usr/local/sonar/sonarqube-5.1.1/conf/sonar.properties

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

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

5、修改sonar-runner的配置文件

vim /usr/local/sonar/sonar-runner-2.4/conf/sonar-runner.properties

sonar.host.url=http://0.0.0.0:9000

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

sonar.jdbc.username=sonar 

sonar.jdbc.password=sonar

sonar.sourceEncoding=UTF-8

sonar.login=admin

sonar.password=admin

6、启动sonarqube

cd /usr/local/sonar/sonarqube-5.1.1/bin/linux-x86-64/

./sonar.sh start

7、安装插件

通过http://IP:9000打开sonarqube并登录,在settings-->system-->update center下可以看到各种插件,直接安装即可。汉化插件,php插件都通过此种方式安装。

8、使用sonar-runner分析php源码

在项目源码的根目录下创建sonar-project.properties配置文件

sonar.projectKey=apps  #projectKey必须唯一,可任意指定

sonar.projectName=apps  #指定project的名称

sonar.projectVersion=1.0  #项目版本号,可任意指定

sonar.sources=.            #源代码目录,.代表当前目录

切换到项目所在目录,执行分析:

/usr/local/sonar/sonar-runner-2.4/bin/sonar-runner

 

 

你可能感兴趣的:(Sonar)