1. 環(huán)境要求
mysql-server-5.6(也支持其他數(shù)據(jù)庫讼育,不過我選用的mysql)
sonarqube6.0
jdk1.8
sonar-runner-2.4
2.數(shù)據(jù)庫配置
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;
注:在配置數(shù)據(jù)庫之前一定要確保上述軟件版本正確,否則會運行出錯稠集。一旦運行出錯奶段,需要刪除sonar數(shù)據(jù)庫,重新運行上述配置語句痹籍。
3. 環(huán)境變量
export SONAR_HOME="/home/xx/file/sonarqube-6.0"
export SONAR_RUNNER_HOME="/home/xx/file/sonar-runner-2.4"
然后將SONAR_RUNNER_HOME/bin添加到path中去
4.修改sornarqube配置
vi $SONAR_HOEME/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
sonar.jdbc.driverClassName:com.mysql.jdbc.Driver
5.修改sonar-runner配置
vi $SONAR_RUNNER_HOME/conf/sonar-runner.properties
sonar.host.url=[http://localhost:9000](http://localhost:9000/sonar)
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
注:以上配置文件中本來就存在的筷畦,只需要去掉相應的注釋符號即可词裤。
6. 開始使用
以上運行環(huán)境都準備好了之后,即可開始運行鳖宾。
在$SONAR_HOME/bin/linux-x86-64/目錄下運行sonar.sh
sonar.sh start
可以通過查看$SONAR_HOME/log/sonar.log查看是否成功運行吼砂,如果看到如下日志
2016.09.05 10:31:32 INFO ce[o.s.ce.app.CeServer] Compute Engine is up
2016.09.05 10:31:33 INFO app[o.s.p.m.Monitor] Process[ce] is up
即成功運行∮婕纾可以在瀏覽器中訪問http://localhost:9000拇惋,如果能正常打開周偎,說明配置正確。
注:這里我碰到一個問題澳眷,就是訪問http://localhost:9000一直訪問不了蛉艾,后來改為訪問http://localhost:9000/sonar钳踊,就能正常訪問了勿侯。賬戶密碼默認的為admin,admin助琐。
7. 運行sonar-runner檢測代碼
在待檢測工程目錄下,直接運行sonar-runner蛆橡,即開始檢測。如果這里顯示無法連接http://localhost:9000/航罗,可以檢查之前配置是否有誤屁药。如果出現(xiàn)下面日志柏锄,說明解析成功
19:01:51.759 INFO - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
19:01:51.759 INFO - More about the report processing at http://localhost:9000/sonar/api/ce/task?id=AVb6Au95YHi3B3QHd6Kc
19:01:51.800 INFO - Task total time: 5.674 s
根據(jù)日志中鏈接可直接查看檢測結果。