首先到sonarqube官網下載sonarqube和sonar-runner http://www.sonarqube.org/downloads/ 並將其解壓mysql
代碼分析後的結果將保存到數據庫,須要在根據SonarQube的要求創建數據庫linux
進入mysql,若是尚未安裝mysql,請移駕http://blog.csdn.net/u011403655/article/details/46404265sql
mysql -u root -p
鏈接到數據庫後執行以下指令數據庫
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;
在profile中添加環境變量和PATHvim
vim /etc/profile
在最後添加以下代碼ruby
export SONAR_HOME=/usr/local/sonarqube/sonarqube-5.1.2 export SONAR_RUNNER_HOME=/usr/local/sonarqube/sonar-runner-2.4 export PATH=$PATH:$SONAR_RUNNER_HOME/bin
執行source讓其馬上生效bash
source /etc/profile
執行markdown
sonar-runner -v
若是有相似下面的文字,則表示安裝成功url
SonarQube Runner 2.4 Java 1.6.0_22 Sun Microsystems Inc. (64-bit) Linux 2.6.32-220.el6.x86_64 amd64
修改sonarqube配置文件,文件路徑爲sonarqube安裝路徑下的conf文件夾中的sonar.propertiesspa
vim sonar.properties
去掉改行前的#,也就是去掉註釋
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
而後在以後添加兩行
sonar.jdbc.username=sonar sonar.jdbc.password=sonar
退出保存
切換到sonar-runner的安裝路徑下的conf
vim sonar-runner.properties
去掉
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 #sonar.login=admin #sonar.password=admin
前的#,保存退出
進入到sonarqube的安裝目錄的bin/linux-x86-64中,執行
./sonar.sh start