SonarQube版本升级
这里写目录标题
版本升级路径
升级路径:7.4 ->7.9.5 LTS -> 8.7.0
其它版本升级路径请根据官网查询:https://docs.sonarqube.org/latest/setup/upgrading/
总体升级流程
7.4 Mysql -> 7.4 PgSQL -> 7.9.5 PgSQL -> 8.7.0 PgSQL
新版本强制性依赖
-
SonarQube 7.9版之后只支持 JAVA11+
sudo yum install java-11-openjdk -y
-
SonarQube LTS 7.9版之后,放弃了对于MySQL数据库的支持, 所以数据迁移 Mysql --> PG
rpm -Uvh http://mirrors.ustc.edu.cn/postgresql/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum install -y postgresql12-server # 初始化数据库 /usr/pgsql-12/bin/postgresql-12-setup initdb # 修改配置文件-远程访问设置 vim /var/lib/pgsql/12/data/postgresql.conf #listen_addresses = '*' vim /var/lib/pgsql/12/data/pg_hba.conf # IPv4 local connections: host all all 0.0.0.0/0 trust # IPv6 local connections: host all all ::1/128 ident # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 ident #host replication postgres ::1/128 ident host all all 0.0.0.0/0 ident # 启动并加入开机启动 systemctl start postgresql-12 systemctl enable postgresql-12 # PG中创建sonar数据库 su - postgres psql create user sonar with password 'sonar'; create database sonar owner sonar; grant all on database sonar to sonar; \q
sonarcube Mysql数据库切换到PgSQL
备份 sonar 现有的MySQL数据库用于导入 PgSQL
$ mysqldump -u root sonar > sonar.sql
MySQL [(none)]> CREATE DATABASE sonar_bak DEFAULT CHARACTER SET utf8mb4;
MySQL [(none)]> use sonar_bak
MySQL [sonar_bak]> source /root/sonar.sql
使用sonarcube初始化一下postgresql数据库
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使用后才会找到和这个表!就是需要旧版本的SonarQube 初始化一次
$ scp 远程复制整个旧版本目录
$ vim sonar.properties
sonar.jdbc.url=jdbc:postgresql://172.16.0.67/sonar
$ /opt/sonarqube-7.4/bin/linux-x86-64/sonar.sh start
界面访问 http://172.16.0.67:9003/
数据迁移 mysql -> pgsql
官方提供的迁移工具: https://github.com/SonarSource/mysql-migrator
wget https://binaries.sonarsource.com/Distribution/mysql-migrator/mysql-migrator-1.1.0.119.zip
unzip mysql-migrator-1.1.0.119.zip
cd mysql-migrator-1.1.0.119/bin/
cat > source.properties <<'EOF'
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://192.168.55.126:3306/sonar_bak?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
EOF
cat > target.properties <<'EOF'
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://172.16.0.67/sonar
EOF
# 运行迁移工具
./mysql-migrator -source source.properties -target target.properties
[root@localhost bin]# ./mysql-migrator -source ./source.properties -target ./target.properties
[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 internal_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 ...
Tables Records Seconds
------------------------ ------- -------
organizations 1 0.1
organization_members 153 0.1
groups_users 232 0.1
rules_parameters 544 0.1
rules_profiles 42 0.1
org_qprofiles 42 0.0
default_qprofiles 20 0.0
project_qprofiles 4 0.0
qprofile_edit_users 0 0.0
qprofile_edit_groups 0 0.0
groups 10 0.0
snapshots 38388 7.3
group_roles 1505 0.3
rule_repositories 39 0.1
deprecated_rule_keys 0 0.0
rules 6354 2.2
rules_metadata 1472 0.3
events 41495 7.3
quality_gates 3 0.0
quality_gate_conditions 12 0.1
org_quality_gates 3 0.2
properties 963 0.2
project_links 12 0.1
duplications_index 0 0.1
live_measures 3658860 600.4
project_measures 2575904 370.4
internal_properties 3 0.0
projects 150163 41.2
manual_measures 0 0.4
active_rules 3483 0.2
notifications 0 0.0
user_roles 159 0.0
active_rule_parameters 368 0.0
users 153 0.0
metrics 146 0.0
issues 580694 129.3
issue_changes 1907132 193.7
permission_templates 8 0.0
perm_tpl_characteristics 18 0.0
perm_templates_users 3 0.0
perm_templates_groups 68 0.0
qprofile_changes 3664 0.3
file_sources 74865 77.2
ce_queue 0 0.1
ce_activity 47364 10.2
ce_task_characteristics 0 0.0
ce_task_input 0 0.0
ce_scanner_context 35156 5.1
ce_task_message 9832 1.2
user_tokens 53 0.0
es_queue 0 0.1
plugins 23 0.0
project_branches 203 0.1
analysis_properties 0 0.0
webhooks 2 0.0
webhook_deliveries 6 0.0
alm_app_installs 0 0.0
project_alm_bindings 0 0.0
project_mappings 0 0.0
Migration successful in 1452.0 seconds
You have new mail in /var/spool/mail/root
# 查看数据
su - postgres
psql
\c sonar
\dt
select * from projects;
重启服务
# 清除es索引
cd /opt/sonarqube-7.4/
rm -rf data/es5
# 启动服务
/opt/sonarqube-7.4/bin/linux-x86-64/sonar.sh start
升级 7.9.5
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.9.5.zip
unzip sonarqube-7.9.5.zip
mv ./sonarqube-7.9.5/ /opt/
chown sonar.sonar sonarqube-7.9.5 -R
cp /opt/sonarqube-7.4/conf/sonar.properties /opt/sonarqube-7.9.5/conf/
# sonarqube 7.9.1 必须使用jdk11 修改成java11 路径
vim ../../conf/wrapper.conf
wrapper.java.command=/usr/local/jdk-11/bin/java
# 关闭旧服务
/opt/sonarqube-7.4/bin/linux-x86-64/sonar.sh stop
# 启动新服务(注意切到sonar用户,这个版本好像不会自动切换?)
/opt/sonarqube-7.9.5/bin/linux-x86-64/sonar.sh start
# 进入网址点击升级
http://172.16.0.67:9003/setup
升级 8.7.0
# 备份数据库
su - postgres
pg_dump sonar > sonar.bak
# 下载按照
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.7.0.41497.zip
unzip sonarqube-8.7.0.41497.zip
mv sonarqube-8.7.0.41497 /opt/sonarqube-8.7.0
chown sonar.sonar sonarqube-8.7.0 -R
cp /opt/sonarqube-7.9.5/conf/sonar.properties /opt/sonarqube-8.7.0/conf/
# 依旧需要java11,参考上图,或者环境已经是java11的话忽略
# 关闭旧服务
/opt/sonarqube-7.9.5/bin/linux-x86-64/sonar.sh stop
# 启动新服务(注意切到sonar用户)
/opt/sonarqube-8.7.0/bin/linux-x86-64/sonar.sh start
# 进入网址点击升级
http://172.16.0.67:9003/setup