SonarQube LTS 7.9.1升级指南
SonarQube LTS 7.9版之后,放弃了对于MySQL数据库的支持,同时Java的版本已经升至Java 11. 由于此两项依赖均为强制性依赖,所以从老版本上升上来的SonarQube至少需要完成Java版本的升级和数据库的移植才能实现SonarQube的版本升级。这篇文章以容器化的SonarQube服务升级为例,介绍如何实现从SonarQube LTS 6.7.1版本 + MySQL 5.7.16版本 升至SonarQube 7.9.1版本 + PostgreSQL 12.1版本。
一、事前准备
1、SonarQube环境搭建
准备LTS 6.7.1版本 + MySQL 5.7.16的环境,详细可参看:
- https://liumiaocn.blog.csdn.net/article/details/102691455
PS:在做数据库迁移的时候,先运行一个同版本的新sonar进行迁移,所以先要搭建一个基于 Postgres 的 SonarQube LTS 6.7.1
其实此工具应该是建立在对应的数据库结构创建完成的基础上,所以才会要求相同版本。因为本文使用容器化的方式,所以只需要修改docker-compose.yml文件做如下设定即可:
LTS 6.7.1版本 + MySQL 5.7.16
[root@localhost ~]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=111111 -e MYSQL_DATABASE=sonar liumiaocn/mysql:5.7.16[root@localhost ~]# docker run -d --name sonar-mysql -p 9001:9000 -e SONARQUBE_JDBC_USERNAME=root -e SONARQUBE_JDBC_PASSWORD=111111 -e SONARQUBE_JDBC_URL="jdbc:mysql://172.17.0.4:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance" liumiaocn/sonarqube:6.7.1
LTS 6.7.1版本 + postgres12
[root@localhost ~]# docker run -d --name postgres -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -e PGDATA=/var/lib/postgresql/data/pgdata postgres:12-alpine[root@localhost ~]# docker run -d --name sonar-pos -p 9002:9000 --link=postgres -e SONARQUBE_JDBC_URL=jdbc:postgresql://postgres:5432/sonar liumiaocn/sonarqube:6.7.1
运行后结构如下:
- LTS 6.7.1版本 + MySQL 5.7.16 ,启动端口:9001
- LTS 6.7.1版本 + postgres12 , 启动端口: 9002
2、准备测试数据
创建项目数据
安装sonar-scanner
[root@localhost ~]# wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.0.2311-linux.zip[root@localhost ~]# unzip sonar-scanner-cli-4.6.0.2311-linux.zip
获取maven项目
git clone https://github.com/zeyangli/simple-java-maven-app.gitmvn clean packagels -l target/ | awk '{print $NF}' classesmaven-archivermaven-statusmy-app-1.1-SNAPSHOT.jarsurefire-reportstest-classes
扫描项目
[root@localhost ~]# cd simple-java-maven-app/[root@localhost simple-java-maven-app]# /usr/local/sonar-scanner-4.5.0/bin/sonar-scanner -Dsonar.host.url=http://192.168.130.133:9001 -Dsonar.sources=. -Dsonar.login=admin -Dsonar.password=admin -Dsonar.projectKey=test
二、数据迁移
SonarQube提供了从MySQL将数据移出的工具,项目详细可以参看: https://github.com/SonarSource/mysql-migrator
- 下载地址:https://binaries.sonarsource.com/Distribution/mysql-migrator/
- 当前最新版本zip文件名称:mysql-migrator-1.1.0.119.zip
1、下载数据迁移工具
进入源SonarQube容器中(服务端口9001)
使用wget命令下载此文件至本地。
sonarqube@178c1767d4c9:/opt/sonarqube$ wget https://binaries.sonarsource.com/Distribution/mysql-migrator/mysql-migrator-1.1.0.119.zip--2021-01-27 12:17:05-- https://binaries.sonarsource.com/Distribution/mysql-migrator/mysql-migrator-1.1.0.119.zipResolving binaries.sonarsource.com (binaries.sonarsource.com)... 91.134.125.245Connecting to binaries.sonarsource.com (binaries.sonarsource.com)|91.134.125.245|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 2632311 (2.5M) [application/zip]Saving to: ‘mysql-migrator-1.1.0.119.zip’mysql-migrator-1.1.0.119.zip100%[=================================================================================================================>]2.51M391KB/sin 7.1s2021-01-27 12:17:13 (364 KB/s) - ‘mysql-migrator-1.1.0.119.zip’ saved [2632311/2632311]sonarqube@178c1767d4c9:/opt/sonarqube$ unzip mysql-migrator-1.1.0.119.zipArchive: mysql-migrator-1.1.0.119.zipcreating: mysql-migrator-1.1.0.119/creating: mysql-migrator-1.1.0.119/lib/ inflating: mysql-migrator-1.1.0.119/lib/mysql-migrator-1.1.0.119.jar inflating: mysql-migrator-1.1.0.119/lib/jsr305-1.3.9.jar inflating: mysql-migrator-1.1.0.119/lib/slf4j-simple-1.7.26.jar inflating: mysql-migrator-1.1.0.119/lib/slf4j-api-1.7.26.jar inflating: mysql-migrator-1.1.0.119/lib/postgresql-42.2.5.jar inflating: mysql-migrator-1.1.0.119/lib/mysql-connector-java-5.1.47.jar inflating: mysql-migrator-1.1.0.119/lib/mssql-jdbc-6.2.2.jre8.jarcreating: mysql-migrator-1.1.0.119/bin/ inflating: mysql-migrator-1.1.0.119/bin/mysql-migrator inflating: mysql-migrator-1.1.0.119/bin/mysql-migrator.batsonarqube@178c1767d4c9:/opt/sonarqube$ cd mysql-migrator-1.1.0.119sonarqube@178c1767d4c9:/opt/sonarqube/mysql-migrator-1.1.0.119$ lsbin libsonarqube@178c1767d4c9:/opt/sonarqube/mysql-migrator-1.1.0.119$ cd bin/sonarqube@178c1767d4c9:/opt/sonarqube/mysql-migrator-1.1.0.119/bin$ lsmysql-migrator mysql-migrator.batsonarqube@178c1767d4c9:/opt/sonarqube/mysql-migrator-1.1.0.119/bin$ cat >mysql.properties <<EOFsonar.jdbc.useame=rootsonar.jdbc.password=111111sonar.jdbc.url=jdbc:mysql://172.17.0.4:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformanceEOFsonarqube@178c1767d4c9:/opt/sonarqube/mysql-migrator-1.1.0.119/bin$sonarqube@178c1767d4c9:/opt/sonarqube/mysql-migrator-1.1.0.119/bin$ cat > postgres.properties <<EOFsonar.jdbc.useame=sonarsonar.jdbc.password=sonarsonar.jdbc.url=jdbc:postgresql://172.17.0.2:5432/sonarEOF
2、数据移行实施
sonarqube@178c1767d4c9:/opt/sonarqube/mysql-migrator-1.1.0.119/bin$ sh mysql-migrator -source mysql.properties -target postgres.propertiesWed Jan 27 12:18:50 UTC 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table organizations ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table organization_members ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table groups_users ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table rules_parameters ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table rules_profiles ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table org_qprofiles ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table default_qprofiles ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table project_qprofiles ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table qprofile_edit_users ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table qprofile_edit_groups ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table groups ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table snapshots ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table group_roles ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table rule_repositories ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table deprecated_rule_keys ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table rules ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table rules_metadata ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table events ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table quality_gates ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table quality_gate_conditions ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table org_quality_gates ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table properties ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table project_links ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table duplications_index ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table live_measures ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table project_measures ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table inteal_properties ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table projects ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table manual_measures ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table active_rules ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table notifications ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table user_roles ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table active_rule_parameters ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table users ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table metrics ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table issues ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table issue_changes ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table permission_templates ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table perm_tpl_characteristics ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table perm_templates_users ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table perm_templates_groups ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table qprofile_changes ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table file_sources ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table ce_queue ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table ce_activity ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table ce_task_characteristics ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table ce_task_input ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table ce_scanner_context ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table ce_task_message ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table user_tokens ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table es_queue ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table plugins ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table project_branches ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table analysis_properties ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table webhooks ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table webhook_deliveries ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table alm_app_installs ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table project_alm_bindings ...[main] INFO org.sonarsource.sqdbmigrator.migrator.ContentCopier - copying table project_mappings ...TablesRecords Seconds------------------------ ------- -------organizations1 0.3organization_members 137 0.1groups_users 138 0.2rules_parameters 400 0.2rules_profiles 21 0.1org_qprofiles 21 0.1default_qprofiles 14 0.0project_qprofiles0 0.0qprofile_edit_users 0 0.1qprofile_edit_groups0 0.0groups 2 0.1snapshots9590 0.6group_roles164 0.0rule_repositories 39 0.0deprecated_rule_keys0 0.1rules10013 1.7rules_metadata 1 0.1events 13284 0.7quality_gates3 0.1quality_gate_conditions 9 0.0org_quality_gates3 0.1properties 34 0.0project_links2 0.3duplications_index 0 0.2live_measures 341769 24.6project_measures 2024189 97.6inteal_properties 3 0.2projects15373 1.6manual_measures 0 0.2active_rules16165 0.3notifications0 0.1user_roles 0 0.1active_rule_parameters233 0.1users 137 0.2metrics169 0.2issues 289760 19.9issue_changes 2452287 76.8permission_templates1 0.1perm_tpl_characteristics0 0.1perm_templates_users0 0.1perm_templates_groups5 0.0qprofile_changes16194 0.5file_sources 5802 4.4ce_queue0 0.3ce_activity 9774 0.8ce_task_characteristics 0 0.1ce_task_input0 0.0ce_scanner_context1726 0.7ce_task_message 0 0.1user_tokens 3 0.1es_queue0 0.0plugins20 0.1project_branches52 0.0analysis_properties 0 0.0webhooks0 0.1webhook_deliveries 0 0.1alm_app_installs0 0.1project_alm_bindings0 0.5project_mappings0 0.1Migration successful in 238.4 seconds
3、删除ES索引并重启SonarQube服务
进入postgres12 对应的SonarQube容器
此时如果重启会发现,似乎从MySQL导入的数据并没有起作用,这是因为还需要清一下之前的ES的数据。
#清除es索引rm -fr data/es5
重启SonarQube容器
[root@localhost simple-java-maven-app]# docker restart 11aed04a7bd6
此时即可看到数据已经导入的效果
4、升级SonarQube
如果非容器方式的升级,则需要升级SonarQube所使用的JDK以及SonarQube自身。而容器化则非常简单,只需要将上述镜像的tag修改一下即可:
删除 postgres 12 原先对于的 sonarqube容器,执行以下升级的容器命令:
docker run -d --name sonarqube7.9 -p 9002:9000 --link=postgres -e SONARQUBE_JDBC_URL=jdbc:postgresql://postgres:5432/sonar sonarqube:7.9.1-community
再次通过 9002 端口进行访问可以看到如下信息:
需要重新进行初始化服务,访问地址为 http://localhost:9002/setup
点击Upgrade按钮,并重启SonarQube服务,即可确认升级后的信息了. 如果重启时发现无法启动,并提示如下错误信息
可通过尝试删除es6的内容后重启SonarQube服务来解决
FAQ
1.Could not determine SonarQube version of the target database. Could not select version from schema_migrations. ERROR: relation "schema_migrations" does not exist
新创建的空的PG是不能进行迁移的,需要同版本的soanr使用后才会找到和这个表!
2.Versions in source and target database don't match: 1838 != 2804
此问题一定要注意在做数据库迁移的时候,先运行一个同版本的新sonar进行迁移哦!
3.迁移完成没有数据怎么办? 是不是我操作错误了?
需要先删除es索引再启动sonarqube,详见切换服务部分。
4.出现SonarQube is under maintenance
升级后需要初始化详见切换服务部分。
转载于: https://blog.csdn.net/weixin_38168728/article/details/101732099
https://blog.csdn.net/liumiaocn/article/details/102788571
作者:流年晕开时光
来源链接:https://www.cnblogs.com/deny/p/14338564.html
版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。
2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。