首頁 > 軟體

SonarQube升級過程記錄

2020-06-16 17:36:02

1.閱讀SonarQube更新紀錄檔:

http://docs.codehaus.org/display/SONAR/Upgrading#Upgrading-ReleaseUpgradeNotes

2.停止SonarQube服務:

bin/<SYSTEM>/sonar stop

3.下載新版本的SonarQube及SonarQube Runner,並解壓至新的目錄NEW_SONARQUBE_HOME

http://www.sonarqube.org/downloads/

4.更新NEW_SONARQUBE_HOME/conf下sonar.properties與wrapper.conf檔案裡的內容,檔案內容參照OLD_SONARQUBE_HOME/conf下相應組態檔的內容,但切記千萬不要直接將原來的組態檔拷貝覆蓋,因為新的sonar.properties與wrapper.conf檔案還包含新版本的一些設定項。

5.拷貝OLD_SONARQUBE_HOME/extensions/plugins中的外掛至NEW_SONARQUBE_HOME/extensions/plugins

6.如果使用的是自定義的JDBC驅動,將其拷貝至NEW_SONARQUBE_HOME/extensions/jdbc-driver/<dialect>

7.備份資料庫:MySQL:

/usr/local/mysql# mysqldump -u sonar -p sonar>sonar.sql
8.啟動SonarQube:
bin/<SYSTEM>/sonar stop
9.用瀏覽器存取http://localhost:9000/setup (注意:不再是直接存取localhost:9000),根據提示升級
 
10.根據實際情況修改系統中或持續整合中所有涉及SONAR_HOME和SONAR_RUNNER_HOME環境變數
 
11.使用新版SonarQube Runner分析專案
 
 
可能遇到的問題:
一、分析專案時報外掛相容性錯誤
解決:登入http://localhost:9000 WEB中設定——更新中心,將plugins都更新至最新版本
註:更新Java Plugin時將會有個警告,
  • Version 2.4 moves Java from being an "ecosystem" of multiple plugins to a single, stand-along plugin that encompasses most of the functionality formerly contained in the ecosystem. Unfortunately, SonarQube's update center cannot handle the switch gracefully. You may use the update center to download the new version of the plugin. However,you must manually remove the Surefire, JaCoCo, and Squid for Java plugins from $SONARQUBE_HOME/extensions/plugins.
因此,在更新中心中下載新版本Java Plugin後,需要將$SONARQUBE_HOME/extensions/plugins下老的Surefire, JaCoCo, and Squid外掛jar包刪除,並重新啟動服務
 
二、Impossible to upgrade database
Migration failed: An error has occurred, all later migrations canceled: ActiveRecord::JDBCError: Specified key was too long; max key length is 1000 bytes: CREATE UNIQUE INDEX `rules_repo_key` ON `rules` (`plugin_name`, `plugin_rule_key`) .
Please check logs.
 
原因:Sonar在MySQL中對表建立索引時,key的長度超過1000 bytes了,由於MySQL使用MyISAM engine時會有key長度的限制,若MySQL使用的是MyISAM engine的話將會出現這個問題
 
解決:將MySQL的預設engine修改為INNODB
1.檢查當前的引擎 
mysql> show engines; 
 
2.確認確實使用的是MyISAM後,將預設engine修改為INNODB,並重新啟動MySQL服務
修改my.cnf組態檔:
/etc/mysql/my.cnf
default-storage-engine=INNODB
# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /usr/local/var
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/var
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
3.檢視是否支援動態載入
mysql>show variables like "have_%";
檢視have_dynamic_loading這行,如果是YES,則繼續 
 
4.安裝外掛
mysql>INSTALL PLUGIN INNODB SONAME 'ha_innodb_plugin.so';  
mysql>INSTALL PLUGIN INNODB_TRX SONAME 'ha_innodb_plugin.so';  
mysql>INSTALL PLUGIN INNODB_LOCKS SONAME 'ha_innodb_plugin.so';  
mysql>INSTALL PLUGIN INNODB_LOCK_WAITS SONAME 'ha_innodb_plugin.so';  
mysql>INSTALL PLUGIN INNODB_CMP SONAME 'ha_innodb_plugin.so';  
mysql>INSTALL PLUGIN INNODB_CMP_RESET SONAME 'ha_innodb_plugin.so';  
mysql>INSTALL PLUGIN INNODB_CMPMEM SONAME 'ha_innodb_plugin.so';  
mysql>INSTALL PLUGIN INNODB_CMPMEM_RESET SONAME 'ha_innodb_plugin.so' 
5.再次檢視當前的引擎
mysql> show engines;

6.檢視sonar庫中有哪些表是使用的MyISAM engine(註:這裡TABLE_SCHEMA中的‘sonar’為安裝sonar建庫時資料庫的名稱,需改成自身建庫時的名稱

SELECT TABLE_NAME, ENGINE  FROM information_schema.TABLES  WHERE TABLE_SCHEMA = 'sonar';
+---------------------------+--------+
| TABLE_NAME                | ENGINE |
+---------------------------+--------+
| action_plans              | MyISAM |
| active_dashboards        | MyISAM |
| active_rule_changes      | MyISAM |
| active_rule_param_changes | MyISAM |
| active_rule_parameters    | MyISAM |
| active_rules              | MyISAM |
| activities                | MyISAM |
| authors                  | MyISAM |
| characteristics          | MyISAM |
| dashboards                | MyISAM |
| dependencies              | MyISAM |
| duplications_index        | MyISAM |
| events                    | MyISAM |
| graphs                    | MyISAM |
| group_roles              | MyISAM |
| groups                    | MyISAM |
| groups_users              | MyISAM |
| issue_changes            | MyISAM |
| issue_filter_favourites  | MyISAM |
| issue_filters            | MyISAM |
| issues                    | MyISAM |
| loaded_templates          | MyISAM |
| manual_measures          | MyISAM |
| measure_filter_favourites | MyISAM |
| measure_filters          | MyISAM |
| metrics                  | MyISAM |
| notifications            | MyISAM |
| perm_templates_groups    | MyISAM |
| perm_templates_users      | MyISAM |
| permission_templates      | MyISAM |
| project_links            | MyISAM |
| project_measures          | MyISAM |
| projects                  | MyISAM |
| properties                | MyISAM |
| quality_gate_conditions  | MyISAM |
| quality_gates            | MyISAM |
| resource_index            | MyISAM |
| rules                    | MyISAM |
| rules_parameters          | MyISAM |
| rules_profiles            | MyISAM |
| schema_migrations        | MyISAM |
| semaphores                | MyISAM |
| snapshot_data            | MyISAM |
| snapshot_sources          | MyISAM |
| snapshots                | MyISAM |
| user_roles                | MyISAM |
| users                    | MyISAM |
| widget_properties        | MyISAM |
| widgets                  | MyISAM |
+---------------------------+--------+
49 rows in set (0.01 sec)
7.將相應的表更新為INNODB
ALTER TABLE sonar.widget_properties ENGINE=INNODB;        
ALTER TABLE sonar.widgets ENGINE=INNODB;                  
ALTER TABLE sonar.user_roles ENGINE=INNODB;               
ALTER TABLE sonar.users ENGINE=INNODB;                    
ALTER TABLE sonar.snapshot_sources ENGINE=INNODB;         
ALTER TABLE sonar.snapshot_data ENGINE=INNODB;            
ALTER TABLE sonar.snapshots ENGINE=INNODB;                
ALTER TABLE sonar.semaphores ENGINE=INNODB;               
ALTER TABLE sonar.schema_migrations ENGINE=INNODB;        
ALTER TABLE sonar.rules_profiles ENGINE=INNODB;           
ALTER TABLE sonar.rules_parameters ENGINE=INNODB;         
ALTER TABLE sonar.rules ENGINE=INNODB;                    
ALTER TABLE sonar.resource_index ENGINE=INNODB;           
ALTER TABLE sonar.quality_gate_conditions ENGINE=INNODB;  
ALTER TABLE sonar.quality_gates ENGINE=INNODB;            
ALTER TABLE sonar.properties ENGINE=INNODB;               
ALTER TABLE sonar.project_measures ENGINE=INNODB;         
ALTER TABLE sonar.project_links ENGINE=INNODB;            
ALTER TABLE sonar.projects ENGINE=INNODB;                 
ALTER TABLE sonar.perm_templates_users ENGINE=INNODB;     
ALTER TABLE sonar.perm_templates_groups ENGINE=INNODB;    
ALTER TABLE sonar.permission_templates ENGINE=INNODB;     
ALTER TABLE sonar.notifications ENGINE=INNODB;            
ALTER TABLE sonar.metrics ENGINE=INNODB;                  
ALTER TABLE sonar.measure_filter_favourites ENGINE=INNODB;
ALTER TABLE sonar.measure_filters ENGINE=INNODB;          
ALTER TABLE sonar.manual_measures ENGINE=INNODB;          
ALTER TABLE sonar.loaded_templates ENGINE=INNODB;         
ALTER TABLE sonar.issue_filter_favourites ENGINE=INNODB;  
ALTER TABLE sonar.issue_filters ENGINE=INNODB;            
ALTER TABLE sonar.issue_changes ENGINE=INNODB;            
ALTER TABLE sonar.issues ENGINE=INNODB;                   
ALTER TABLE sonar.group_roles ENGINE=INNODB;              
ALTER TABLE sonar.groups_users ENGINE=INNODB;             
ALTER TABLE sonar.groups ENGINE=INNODB;                   
ALTER TABLE sonar.graphs ENGINE=INNODB;                   
ALTER TABLE sonar.events ENGINE=INNODB;                   
ALTER TABLE sonar.duplications_index ENGINE=INNODB;       
ALTER TABLE sonar.dependencies ENGINE=INNODB;             
ALTER TABLE sonar.dashboards ENGINE=INNODB;               
ALTER TABLE sonar.characteristics ENGINE=INNODB;          
ALTER TABLE sonar.authors ENGINE=INNODB;                  
ALTER TABLE sonar.activities ENGINE=INNODB;               
ALTER TABLE sonar.active_rule_param_changes ENGINE=INNODB;
ALTER TABLE sonar.active_rule_parameters ENGINE=INNODB;   
ALTER TABLE sonar.active_rule_changes ENGINE=INNODB;      
ALTER TABLE sonar.active_rules ENGINE=INNODB;             
ALTER TABLE sonar.active_dashboards ENGINE=INNODB;        
ALTER TABLE sonar.action_plans ENGINE=INNODB;

三、伺服器端分析專案時或Eclipse本地分析時報

Caused by: org.sonar.api.utils.SonarException: The plugin findbugs is not supported with Java 1.6.0_**
由於最新版本的findbugs外掛需要JDK1.7及以上的支援,因此需要安裝JDK1.7以上
對於Eclipse,若不想改變系統的JAVA環境,而只改變Eclipse中的JAVA環境,則可在eclipse.ini檔案中增加
-vm
%JAVA1.7_HOME%/bin/javaw.exe

設定Sonar、Jenkins進行持續審查 http://www.linuxidc.com/Linux/2016-08/133877.htm

sonarQube程式碼品質管理工具環境籌建筆記 http://www.linuxidc.com/Linux/2016-08/133878.htm

SonarQube程式碼品質管理平台安裝與使用  http://www.linuxidc.com/Linux/2016-08/133879.htm

Sonar 的詳細介紹請點這裡
Sonar 的下載地址請點這裡

本文永久更新連結地址http://www.linuxidc.com/Linux/2016-08/133880.htm


IT145.com E-mail:sddin#qq.com