下载jdk & sonarqube & sonar-scanner
安装jdk
基于ubuntu 16.04+apache[具体webserver采用缺省安装]
推荐下载安装【底部有网盘地址】
sonarqube-5.6.6.zip
jdk-8u121-linux-x64.tar.gz
sonar-scanner-2.8.zip
解压安装配置环境变量
我的在/usr/local下, uzip解压mv等操作略过
root@ubuntu:mkdir -p /usr/local/sonar
root@ubuntu:/usr/local/sonar# ls
sonarqube-5.6.6 sonar-scanner-2.8
root@ubuntu:/usr/local/sonar#
root@ubuntu:/usr/local/java# ls
jdk1.8.0_121
root@ubuntu:/usr/local/java#
vim ~/.bashrc
打开之后在末尾添加,以下只是参考,只要放到环境变量就行
export JAVA_HOME=/usr/local/java/YOUR_DOWN_LOAD_VERSION
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export SONAR_HOME=/usr/local/sonar/sonarqube-5.6.6
export SONAR_RUNNER_HOME=/usr/local/sonar-scanner-2.8
export JAVA_HOME=/usr/local/java/jdk1.8.0_121
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${SONAR_RUNNER_HOME}/bin:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
验证一下java环境
root@ubuntu:/usr/local/java# java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit
...
...
mysql数据源配置, sonar配置文件
mysql -h172.28.50.248 -root -p -P3316
以下除了第一行都不是必须
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;
配置sonarqube配置文件
vim /usr/local/sonar/sonarqube-5.6.6/conf/sonar.properties
注意以下配置mysql数据源,截取部分...
#----- Global database settings (not used for SonarQube 5.2+)
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://172.28.50.248:3316/sonar?useUnicode=true&characterEncoding=utf8
配置sonar-scanner配置文件
vim /usr/local/sonar/sonar-scanner-2.8/conf/sonar-scanner.properties
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- Default source code encoding
#sonar.sourceEncoding=UTF-8
#----- Global database settings (not used for SonarQube 5.2+)
sonar.jdbc.username=docker
sonar.jdbc.password=1234
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://172.28.50.248:3316/sonar_toon?useUnicode=true&characterEncoding=utf8
启动sonarqube
/usr/local/sonar/sonarqube-5.6.6/bin/linux-x86-64/sonar.sh start
查看启动状态
/usr/local/sonar/sonarqube-5.6.6/bin/linux-x86-64/sonar.sh status
来张图,已经汉化后的,运行地址:http://localhost:9000, 后台用户名及密码均是默认的admin
汉化
插件: 注意查看版本号
sonar-l10n-zh-plugin-1.11.jar
将jar包下载至/usr/local/sonar/sonarqube-5.6.6/extensions/plugins目录下。
重启sonar服务
/usr/local/sonar/sonarqube-5.6.6/bin/linux-x86-64/sonar.sh restart
安装php插件
sonar-php-plugin-2.10.0.2087.jar
引入具体项目
统一将需要检测的php项目放至/root/sonar_project/目录下。
需要在检测目录下建立一个配置文件即可。
[root@systoon-php ~]# cd sonar_project/php_metting/
[root@systoon-php php_metting]# ls
application bin build.sh conf logs public README.md sonar-project.properties Yaf.php
[root@systoon-php php_metting]# pwd
/root/sonar_project/php_metting
[root@systoon-php php_metting]#
在根目录下建立sonar-project.properites 文件,内容参考如下:
sonar.projectKey=org.codehaus.sonar:ci_cart
sonar.projectName=PHP php_meeting sonar test
sonar.projectVersion=1.0
#这里是php文件放的地方
sonar.sources=/root/sonar_project/php_metting
# Language
sonar.language=php
sonar.dynamicAnalysis=false
# Encoding of the source files
sonar.sourceEncoding=UTF-8
执行scanner
在项目中执行命令
[root@systoon-php php_metting]# /usr/local/sonar/sonar-scanner-2.8/bin/sonar-scanner