系統 CentOS 6.6 x86_64,需預裝 JDK 1.7 以上與 MySQL 5.5 以上,安裝套件為 sonarqube-4.5.7.zip。
cd /application/ unzip sonarqube-4.5.7.zip mv sonarqube-4.5.7/ sonarqube/ cd sonarqube/conf vi sonar.properties
在 sonar.properties 中設定資料庫連線資訊(JDBC URL、帳號、密碼)後存檔。
啟動服務並觀察日誌:
cd /application/sonarqube/bin/linux-x86-64 ./sonar.sh start tail -f ../../logs/sonar.log
防火牆放行 9090 連接埠後重啟:
瀏覽器開啟 https://192.168.230.131:9090/sonarqube/,看到畫面即代表安裝成功。下圖為已安裝中文插件的樣子。
在 Administration 的 Marketplace 中挑選需要的插件安裝,預設帳號為 admin/admin。
插件裝完必須重啟 SonarQube 服務才會生效。
在本機 Maven 的 settings.xml 中設定 SonarQube 伺服器位址(本例搭配 MyEclipse 內建的 Maven 插件)。
接著在專案 pom.xml 中加入 sonar 插件描述:
右鍵點選要分析的專案,Run as → Maven build:
按下 Run,在 console 檢視構建輸出。第一次執行會需要下載 sonar-runner 等相關插件,時間會長一些。
回到 SonarQube 控制台即可看到剛分析完的專案。
點進去可以看到逐行標示的問題清單。
每一條都能指派給相關人員處理,也可以調整嚴重度。
儀表盤的內容同樣可依需求自訂配置。
cd /etc/rc.d/init.d/ touch sonarqube chmod +x sonarqube vi sonarqube
腳本內容如下:
#!/bin/sh
# rc file for SonarQube
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
case $1 in
start) su root /application/sonarqube/bin/linux-x86-64/sonar.sh start ;;
stop) su root /application/sonarqube/bin/linux-x86-64/sonar.sh stop ;;
status) su root /application/sonarqube/bin/linux-x86-64/sonar.sh status ;;
restart) su root /application/sonarqube/bin/linux-x86-64/sonar.sh restart ;;
*) echo "require start|stop|status|restart" ;;
esac
存檔後即可用 service 管理:
service sonarqube start/stop/restart/status
最後註冊到開機啟動並確認:
chkconfig --add sonarqube chkconfig --list