持續集成篇-- SonarQube代碼質量管理平台的安裝
IP:192.168.4.221
環境:CentOS 6.6、JDK7、MySQL5.1 、SonarQube-4.5.4(LTS)
root用戶操作
準備工作:已安裝JDK7並配置好了環境變量
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):
下載地址:https://www.sonarqube.org/downloads/
https://dist.sonar.codehaus.org/sonarqube-4.5.4.zip
下載:
wget https://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&characterEncoding=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
(初次啟動會自動建表和做相應的初始化)
瀏覽器中輸入:https://192.168.4.221:9090/sonarqube/
到此,SonarQube已安裝完畢,接下來是對SonarQube做相應的配置和使用
參考內容:基於Dubbo的分布式係統架構實戰
最後更新:2017-08-23 12:02:22