检查Linux系统上面确定安装了jdk(命令Java -version),否则需要下载安装jdk-8u111-linux-x64

1. 软件包下载

需要下载sonarqube,mysql,sonar-runner,插件下载

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

https://dev.mysql.com/downloads/file/?id=465564

https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

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

2. 安装sonarqube

将下载的sonarqube-6.1.zip包解压至某路径如/usr/local

修改sonar配置文件/conf/sonar.properties文件,配置数据库设置,默认已经提供了各类数据库的支持
这里使用mysql,因此取消mysql模块的注释

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

# Optional properties
sonar.jdbc.driverClassName:                com.mysql.jdbc.Driver

3.安装 sonar-runner

下载的sonar-runner-dist-2.8.zip包解压某路径/usr/local

修改sonar-runner的配置文件/conf/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  
#----- PostgreSQL  
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar  
#----- MySQL  
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8  
#----- <a href="http://lib.csdn.net/base/oracle" class='replace_word' title="Oracle知识库" target='_blank' style='color:#df3434; font-weight:bold;'>Oracle</a>  
#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.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_HOME、SONAR_RUNNER_HOME环境变量,并将SONAR_RUNNER_HOME加入PATH

4.安装mysql

解压mysqlmysql-5.7.17-linux-glibc2.5-x86_64.tar.gz安装包到某路径/usr/local

进行初始化,然后启动mysql,进入数据库输入以下命令

#mysql -u root -p

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 
mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
mysql> FLUSH PRIVILEGES;

5.启动sonar

目录切换至sonar的/bin/linux-x86-64/目录,启动服务
#./sonar.sh start   启动服务
#./sonar.sh stop    停止服务
#./sonar.sh restart 重启服务

浏览器http:\\安装机子ip:9000,可以访问证明安装成功。