本文背景是对 harbor 进行升级,因为我的harbor版本是1.2.2,在当前2020年看来实在是有点过于陈旧,互联网搜索一番之后,不太建议直接升级到最新版,而是1.2.2 -> 1.5.0 -> 1.6 -> 1.7 -> 1.9,所以我在这里记录了第一次的升级操作和遇到的一些问题,部分问题的解决方法并非是最权威的,但是大体是白话的解释了原因和解决办法,ok!
毕竟是在做升级操作,一定切记备份数据,备份数据分两部分:
这里给出官网的流程 => Harbor upgrade and database migration guide
cd harbor
docker-compose down -v
harbor集群是通过 docker-compose 来管理的,可以批量操作一批相互关联的服务容器
mv harbor harbor.1.2.2.bak
https://github.com/vmware/harbor/releases
https://gitea.com/goharbor/harbor/releases?page=6
国内镜像仓库地址:http://harbor.orientsoft.cn/
如果服务所在的网络环境无法访问外网(无法下载依赖的镜像),则可以使用offline的下载地址:
tar包中已经包含了对应的镜像,只需要使用 docker load
命令导入即可
迁移工具通过镜像的方式来提供,迁移工具提供了数据备份、数据库架构(database schema)升级、harbor.cfg 配置升级、以及数据迁移的能力
docker pull vmware/harbor-migrator:v1.5.0
docker run -it --rm -e DB_USR=root -e DB_PWD={db_pwd} -v ${harbor_db_path}:/var/lib/mysql -v ${harbor_cfg}:/harbor-migration/harbor-cfg/harbor.cfg -v ${backup_path}:/harbor-migration/backup vmware/harbor-migrator:[tag] backup
注意,这里有一个出错的点,是权限问题,如果方便的话给所有的文件的所有用户可读可写权限,给所有的目录可读可写可执行的权限,我这里直接 777 了
docker run -it --rm -e DB_USR=root -e DB_PWD={db_pwd} -v ${harbor_db_path}:/var/lib/mysql -v ${harbor_cfg}:/harbor-migration/harbor-cfg/harbor.cfg vmware/harbor-migrator:[tag] up
理论上到了第7步就应该完成了,如果有一些要调节的,如端口,自行在docker-compose.yml文件中调节就好了
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
[ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
[ERROR] InnoDB: The system tablespace must be writable!
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
数据库数据权限错误,给所有的文件的所有用户添加可读可写权限,目录添加可读可写可执行权限,可能只有部分文件,这里我对所有文件均添加了操做,为了方便,直接chmod 777 -R xxx/harbor-data/database
InnoDB: No valid checkpoint found.
InnoDB: If you are attempting downgrade from MySQL 5.7.9 or later,
InnoDB: please refer to http://dev.mysql.com/doc/refman/5.6/en/upgrading-downgrading.html
InnoDB: If this error appears when you are creating an InnoDB database,
InnoDB: the problem may be that during an earlier attempt you managed
InnoDB: to create the InnoDB data files, but log file creation failed.
InnoDB: If that is the case, please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/error-creating-innodb.html
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
因为之前备份的时候失败了,导致了部分错误,我的出错就是因为之前数据库数据文件权限不对,导致创建InnoDB出错,解决就是直接用提前做好的备份直接恢复了数据,添加了权限重来,如果不嫌麻烦,也可以参考 http://dev.mysql.com/doc/refman/5.6/en/error-creating-innodb.html 来修正.
docker-compose.yml 文件不存在,如果安装方式是offline 安装,则需要复制 harbor 目录下 make 子目录中的 docker-compose.tpl文件为docker-compose.yml
需要修改 docker-compose.yml 里面的 version 值
老版本barbor未关闭,使用docker-compose down -v
进行关闭
这里是在执行第五步备份的时候或者第六部升级配置的时候出错
用错了harbor的配置文件,经过步骤六升级之后的harbor.cfg是给新版本harbor用的,不同版本之间的harbor.cfg文件中配置有差异,不能混用
官方文档指出,如果harbor能启动成功,则忽略,往往出现在 1.2 -> 1.3以上版本的升级过程中
[ERROR] Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
[ERROR] Incorrect definition of table mysql.event: expected column 'sql_mode' at position ... ...
[ERROR] mysqld: Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
[Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist