1. 構(gòu)建持續(xù)的質(zhì)量管理平臺(tái)的生態(tài)環(huán)境
- 源碼版本控制工具:SVN闲孤、Git等
- JDK:JDK1.8地址
- 持續(xù)集成工具:Jenkins等
- 質(zhì)量管理工具:SonarQube等
2. SonarQube的工具鏈
- 工程(Project):待分析的源碼工程;
- 一個(gè)數(shù)據(jù)庫(kù)(SonarQube Database):存放配置信息和分析結(jié)果信息烤礁;以Mysql為例讼积;
- 一個(gè)WEB服務(wù)器(SonarQube Server):發(fā)布應(yīng)用,在線瀏覽鸽凶、配置分析币砂;
- 一個(gè)客戶端(SonarQube Scanner):執(zhí)行源代碼分析建峭。
- 原名為 sonar runner玻侥,改為 sonar scanner
3. 本文主要介紹 SonarQube 在mac機(jī)上的搭建流程
3.1 搭建 Mysql 數(shù)據(jù)庫(kù)
3.1.1 Mysql 下載地址
-
3.1.2 點(diǎn)擊 mysql 的 dmg 文件,安裝mysql亿蒸,安裝完成獲取提示凑兰,注意記錄賬號(hào) root;密碼:LhEfS:lEe0c(密碼隨機(jī)生成):
2017-09-18T13:50:51.563897Z 1 [Note] A temporary password is generated for root@localhost: LhEfS:lEe0c) If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.
-
3.1.3 驗(yàn)證mysql安裝結(jié)果
終端輸入 mysql --version 命令行边锁,顯示以下內(nèi)容則表示安裝成功mysql --version mysql Ver 14.14 Distrib 5.7.19, for macos10.12 (x86_64) using EditLine wrapper
-
驗(yàn)證失敗處理方法
如果沒(méi)有成功姑食,執(zhí)行以下命令行:
cd /usr/local/bin/ sudo ln -fs /usr/local/mysql/bin/mysql mysql
-
-
3.1.4 終端登錄 mysql 數(shù)據(jù)庫(kù)
終端輸入 mysql -u root -p 之后輸入密碼(LhEfS:lEe0c),顯示以下內(nèi)容表示登錄成功:mysql -u root -p Enter password: ******* Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 36 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
-
登錄異常處理措施:
Access denied for user 'root'@'localhost' (using password: YES)
-
停止MySQL的服務(wù)茅坛,打開系統(tǒng)的偏好設(shè)置音半,找到MySQL 進(jìn)去后则拷,點(diǎn)擊Stop MySQL Server即可。
停止Mysql.png -
開啟兩個(gè)終端曹鸠,在第一個(gè)終端輸入 sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables 輸入當(dāng)前用戶的密碼煌茬,如下所示
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables Password:****** 2017-09-20T03:47:18.6NZ mysqld_safe Logging to '/usr/local/mysql/data/Kim.local.err'. 2017-09-20T03:47:18.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
-
然后在第二個(gè)終端輸入 sudo /usr/local/mysql/bin/mysql -u -root ,然后輸入當(dāng)前用戶的密碼后彻桃,出現(xiàn)以下的界面
sudo mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 36 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
-
然后在第二個(gè)終端繼續(xù)輸入命令 UPDATE mysql.user SET authentication_string=PASSWORD('新密碼') WHERE User='root'; 回車坛善,出現(xiàn)以下內(nèi)容,說(shuō)明修改成功邻眷。
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('newPassword') WHERE User='root'; Query OK, 0 rows affected, 1 warning (0.01 sec) Rows matched: 1 Changed: 0 Warnings: 1 mysql>
-
然后在第二個(gè)終端繼續(xù)輸入命令 FLUSH PRIVILEGES; 回車眠屎,出現(xiàn)以下內(nèi)容。
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql>
-
然后在第二個(gè)終端繼續(xù)輸入命令 \q 肆饶,退出旭贬,關(guān)閉第一個(gè)終端脂倦,回到系統(tǒng)的偏好設(shè)置,重新開啟MySQL即可。
mysql> \q Bye
-
-
3.2 創(chuàng)建sonar user 和 database
-
3.2.1 打開一個(gè)終端世分,輸入命令
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;
-
異常處理
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解決方法:SET PASSWORD=PASSWORD('新密碼’); 注意該新密碼指的是root用戶; 參考 http://blog.sina.com.cn/s/blog_7d553bb50102w9rb.html
-
3.3 下載SonarQube服務(wù)
-
3.3.1 JAVA JDK下載地址 橡类,安裝完成桥滨,終端輸入命令 java -version
java -version java version "1.8.0_40" Java(TM) SE Runtime Environment (build 1.8.0_40-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
3.3.2 下載地址 版本SonarQube 5.6.6 (LTS *) 建議下載LTS最新版本,不建議下載非LTS版作為生產(chǎn)使用洒放。
-
3.3.3 打開終端蛉鹿,執(zhí)行命令
unzip sonarqube-5.6.zip mv sonarqube-5.6 /usr/local
-
3.3.4 修改 sonar.properties
文件路徑 :
/usr/local/sonarqube-5.6/conf/sonar.properties
修改參數(shù):
sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
-
3.3.5 sonar命令行
-
啟動(dòng)sonar
sudo /usr/local/sonarqube-5.6/bin/linux-x86-64/sonar.sh start
-
關(guān)閉 sonar:
sudo /usr/local/sonarqube-5.6/bin/linux-x86-64/sonar.sh stop
-
重啟 sonar:
sudo /usr/local/sonarqube-5.6/bin/linux-x86-64/sonar.sh restart
-
-
3.3.6 訪問(wèn) http://localhost:9000
-
默認(rèn)賬號(hào):admin 默認(rèn)密碼:admin
- 異常處理,如果sonar配置MySQL失敗往湿,Web頁(yè)面會(huì)提示妖异,sonar會(huì)使用默認(rèn)的數(shù)據(jù)庫(kù)。
配置MySQL失敗的提示.png -
3.4 配置 Sonar Scanner 分析器
-
3.4.1 打開終端领追,執(zhí)行 brew install sonar-scanner
brew install sonar-scanner
-
3.4.2 驗(yàn)證 sonar-scanner 安裝結(jié)果
sonar-scanner --version INFO: Project root configuration file: NONE INFO: SonarQube Scanner 3.0.3.778 INFO: Java 1.8.0_40 Oracle Corporation (64-bit) INFO: Mac OS X 10.12.6 x86_64
3.5 配置必須的插件
-
3.5.1 漢化插件流程
插件安裝流程.png