轉自吳水成視頻
1 、安裝 MySQL5.1
(可參考前面 SVN 管理平臺的 MySQL 安裝步驟,如果已安裝則無需安裝)
# rpm -qa | grep mysql ## 查看該操作系統上是否已經安裝了 mysql 數據庫,
有的話,可以通過 rpm -e 命令 或者 rpm -e --nodeps 命令來卸載掉
# yum install mysql-server mysql mysql-devel
# service mysqld start
# chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
用上面的命令查看到 MySQL 並沒有設置開機啓動,所以需要設置開機啓動
# chkconfig mysqld on
爲了方便遠程管理,防火牆中打開 3306 端口
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重啓防火牆,使端口配置生效
# service iptables restart
設置 MySQL 數據庫 root 用戶的密碼:
# mysqladmin -u root password 'wusc.123'
登錄數據庫:
# mysql -u root -p
MySQL 授權遠程訪問(先用 root 登錄 mysql)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'wusc.321' WITH
GRANT OPTION;
mysql> FLUSH PRIVILEGES;
2、配置 MySQL
結合 SonarQube,MySQL 數據庫最好使用 InnoDB 引擎,可提高性能。 看你的 mysql 現在已提供什麼存儲引擎:mysql> show engines;
看你的 mysql 當前默認的存儲引擎:
mysql> show variables like '%storage_engine%';
修改 MySQL 存儲引擎爲 InnoDB, 在配置文件/etc/my.cnf 中的
[mysqld] 下面加入 default-storage-engine=INNODB
# vi /etc/my.cnf [mysqld]
default-storage-engine=INNODB
重啓 mysql 服務器
# service mysqld restart
再次登錄 MySQL 查看默認引擎設置是否生效
mysql> show variables like '%storage_engine%';
+---------------- |
+-------- |
+ |
| Variable_name |
| Value |
| |
+---------------- |
+-------- |
+ |
| |
storage_engine | |
InnoDB | |
+ |
----------------+ |
--------+ |
innodb_buffer_pool_size 參數值設置得儘可能大一點
這個參數主要作用是緩存 innodb 表的索引,數據,插入數據時的緩衝
默認值:128M,專用 mysql 服務器設置的大小:操作系統內存的 70%-80%最佳。
設置方法:my.cnf 文件[mysqld] 下面加入 innodb_buffer_pool_size 參數
# vi /etc/my.cnf [mysqld]
innodb_buffer_pool_size = 256M
(我們這裏設置爲 256M,因爲我們的不是專用的 MySQL 數據庫服務器,還有很多其他的服
務需要佔用系統內存)
設置 MySQL 的查詢緩存 query_cache_size ,最少設置 15M
# vi /etc/my.cnf [mysqld]
query_cache_type=1
query_cache_size=32M
重啓 mysql 服務器
# service mysqld restart
驗證緩存設置是否生效:
mysql> show variables like '%query_cache%';
+------------------------------ |
+---------- |
+ |
| Variable_name |
| Value |
| |
+------------------------------ |
+---------- |
+ |
| have_query_cache |
| YES |
| |
| query_cache_limit |
| 1048576 |
| |
| query_cache_min_res_unit |
| 4096 |
| |
| query_cache_size |
| 33554432 | |
|
| query_cache_type |
| ON |
| |
| query_cache_wlock_invalidate |
| OFF |
| |
+------------------------------ |
+---------- |
+ |
3、創建 sonarqube 數據庫(UTF-8 編碼)
二、安裝 SonarQube 的 Web Server
下載最新 LTS 版的 SonarQube 安裝包(當前版本爲 sonarqube-4.5.4.zip):
下載地址:http://www.sonarqube.org/downloads/
http://dist.sonar.codehaus.org/sonarqube-4.5.4.zip
下載:
# wget http://dist.sonar.codehaus.org/sonarqube-4.5.4.zip
解壓安裝:
# unzip sonarqube-4.5.4.zip
# mv sonarqube-4.5.4 sonarqube
編輯 sonar 配置:
# cd sonarqube/conf/
# vi sonar.properties sonar.jdbc.username=root sonar.jdbc.password=wusc.123
#----- MySQL 5.x sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterE ncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.web.host=0.0.0.0
sonar.web.context=/sonarqube
sonar.web.port=9090
保存以上配置(注意,要看看默認的 9000 端口是否已被佔用)
防火牆中打開 9090 端口:
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT
重啓防火牆,使端口配置生效
# service iptables restart
啓動 SonarQube Web Server
# /root/sonarqube/bin/linux-x86-64/sonar.sh start
(初次啓動會自動建表和做相應的初始化)
瀏覽器中輸入:http://192.168.4.221:9090/sonarqube/
登錄,默認用戶名/密碼爲 admin/admin
到此,SonarQube 已安裝完畢,接下來是對 SonarQube 做相應的配置和使用
一、SonarQube 的配置(前提,先用 admin 用戶登錄)
1、 安裝中文漢化包:
Setting >> Update Center >> Available Plugins >> LOCALIZATION >> Chinese Pack >> Install
安裝完漢化包之後需要重啓 SonarQube 才能生效(重啓前可順便把 CheckStyle、PMD 等插件
安裝一下)
# /root/sonarqube/bin/linux-x86-64/sonar.sh restart
Stopping SonarQube...
Stopped SonarQube.
Starting SonarQube...
Started SonarQube.
重啓完之後刷新 SonarQube:http://192.168.4.221:9090/sonarqube/
漢化成功(注意,漢化包並沒有完全漢化),重新登錄
2、 MyEclipse/Eclipse 中安裝 SonarQube 插件的安裝、配置、使用:
http://docs.sonarqube.org/display/SONAR/SonarQube+in+Eclipse
http://docs.sonarqube.org/display/SONAR/Installing+SonarQube+in+Eclipse
http://docs.sonarqube.org/display/SONAR/Configuring+SonarQube+in+Eclipse
http://docs.sonarqube.org/display/SONAR/Working+with+SonarQube+in+Eclipse
(請參考官方文檔操作,在此不作講解,我們重點講 SonarQube 結合 Maven 插件的使用)
3、 Maven 分析器插件的配置與使用
http://docs.sonarqube.org/display/SONAR/Installing+and+Configuring+Maven
在 Maven 本地庫中的 settings.xml(我這裏是 settings_edu.xml)配置文件中的
<profiles></profiles>節點中添加如下配置: <profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Example for MySQL--> <sonar.jdbc.url>
jdbc:mysql://192.168.4.221:3306/sonarqube?useUnicode=true&chara cterEncoding=utf8
</sonar.jdbc.url> <sonar.jdbc.username>root</sonar.jdbc.username> <sonar.jdbc.password>wusc.321</sonar.jdbc.password>
<!-- Optional URL to server. Default value is http://localhost:9000 --> <sonar.host.url>http://192.168.4.221:9090/sonarqube</sonar.host.url>
</properties>
</profile>
使用 Maven 分析器進行分析,命令:
純 Maven 命令:mvn clean install sonar:sonar MyEclipse 中執行:clean install sonar:sonar
(如果你是第一次運行此命令,看執行日誌你會發現它會先下載 sonar-runner 等插件)
成功執行完分析命令後便可到 Web Server 中查看代碼質量分析結果數據。
4、 配置:
(1) 配置
(2) 權限
(3) 系統
5、 質量配置介紹(切換默認配置)
6、 代碼規則介紹(自定義規則)
7、 問題處理介紹(質量管理的體現)
8、 指表
9、 儀表盤(自定義)