下载地址(jdk版本需要1.8以上,默认账号密码--admin:admin)

SonarQube     https://www.sonarqube.org/downloads/

sonar-runner  http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/


解压

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

unzip sonarqube-6.5.zip -d /usr/local

mv /usr/local/sonar-runner-2.4  /usr/local/sonar-runner

mv /usr/local/sonarqube-6.5  /usr/local/sonarqube


配置环境变量

export SONAR_HOME=/usr/local/sonarqube

export SONAR_RUNNER_HOME=/usr/local/sonar-runner

export JAVA_HOME=/usr/local/java

export JRE_HOME=/usr/local/java/jre

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib

export PATH=$PATH:/usr/local/maven/bin/:$JAVA_HOME/bin:$SONAR_RUNNER_HOME/bin


修改配置文件

mv /usr/local/sonarqube/conf/sonar.properties /usr/local/sonarqube/conf/sonar.properties_bak

vi /usr/local/sonarqube/conf/sonar.properties

sonar.jdbc.url=jdbc:mysql://mysql.xxxxxx.xxxxxxx.com:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

sonar.jdbc.username=sonar

sonar.jdbc.password=SfzafCnUmgTIhE

sonar.web.host=0.0.0.0

sonar.web.context=

sonar.web.port=9000


vim /usr/local/sonarqube/conf/wrapper.conf

wrapper.java.command=/usr/local/java_1.8/bin/java


mv /usr/local/sonar-runner/conf/sonar-runner.properties /usr/local/sonar-runner/conf/sonar-runner.properties_bak

vi /usr/local/sonar-runner/conf/sonar-runner.properties

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

sonar.jdbc.url=jdbc:mysql://mysql.cloud.niudingfeng.com:3306/sonar?useUnicode=true&characterEncoding=utf8

sonar.jdbc.username=sonar

sonar.jdbc.password=SfzafCnUmgTIhE

sonar.sourceEncoding=UTF-8

sonar.login=admin

sonar.password=admin


启动服务

/usr/local/sonarqube/bin/linux-x86-64/sonar.sh start


停止服务

/usr/local/sonarqube/bin/linux-x86-64/sonar.sh start



在项目配置跟路径下,创建配置文件 sonar-project.properties,SonarQube Runner 执行时会读取该文件

#projectKey项目的唯一标识,不能重复。

sonar.projectKey=com.xiaoniu.dataplatform.ocrcloud-service.service

#projectName值不能是中文,否则web页面部分是乱码

sonar.projectName=ocrcloud-service

sonar.projectVersion=1.0

sonar.language=java

sonar.sourceEncoding=utf-8

sonar.sources=src/main

sonar.java.binaries=target/classes

sonar.core.codeCoveragePlugin=jacoco

sonar.jacoco.itReportPath=/home/ly/ocrcloud/jacoco-it.exec

sonar.jacoco.reportPath=target/jacoco.exec

sonar.dynamicAnalysis=reuseReports

sonar.junit.reportsPath=target/surefire-reports

sonar.surefire.reportsPath=target/surefire-reports

sonar.jacoco.reportMissing.force.zero=true



常见错误:

1、WrapperSimpleApp: Unable to locate the class org.sonar.application.App: Java.lang.UnsupportedClassVersionError: org/sonar/application/App : Unsupported major.minor version 51.0

解决方法: 

cd /usr/local/sonarqube/conf 

vi wrapper.conf 

linux: 

wrapper.java.command=/usr/local/java/bin/java

jdk版本要1.8.0以上