harbor安装
Harbor是k8s常用的私有仓库,属于企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等,而且Harbor支持中文,方便国人使用。
本文在生产环境的harbor实操,harbor从v1.3版本升级到v1.8。harbor数据库在v1.6版本做了很大的升级。数据库从原来的MySQL升级为postgresql数据库。根据官方文档的解释(https://github.com/goharbor/harbor/blob/master/docs/migration_guide.md),旧版本的harbor升级到最新的v1.8,需先将harbor升级到v1.6,再升级到更高的版本。
准备工作
配置epel源和docker-ce源,安装最新的docker-compse和docker
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install -y yum-utils yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum install docker-compose -y yum install docker-ce –y systemctl enable docker systemctl start docker
下载Harbor1.6和1.8版本的离线安装包
https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.6.0.tgz
https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.8.0.tgz
harbor1.3升级到harbor1.6
关闭harbor
cd harbor docker-compose down
备份harbor以及整个数据库
hharbor1.3安装时,数据库的数据都放在/data/harbor/data里,所以直接备份整个目录即可
mv harbor /backup/harbor
从docker hub拉取1.6和1.8的数据迁移镜像
docker pull goharbor/harbor-migrator:v1.6.0 docker pull goharbor/harbor-migrator:v1.8.0
备份mysql数据库和harbor.cfg到/path/to/backup(安全起见备份mysql的数据库和配置文件)
docker run -it --rm -e DB_USR=root -e DB_PWD=root123 -v /backup/harbor/data/database/:/var/lib/mysql -v /backup/harbor/harbor.cfg:/harbor-migration/harbor-cfg/harbor.cfg -v /path/to/backup:/harbor-migration/backup goharbor/harbor-migrator:v1.6.0 backup
升级数据库框架(将MySQL框架升级为postgresql)
docker run -it --rm -e DB_USR=root -e DB_PWD=root123 -v /backup/harbor/data/database/:/var/lib/mysql -v /backup/harbor/harbor.cfg:/harbor-migration/harbor-cfg/harbor.cfg -v /path/to/backup:/harbor-migration/backup goharbor/harbor-migrator:v1.6.0 up
框架升级后的目录如下图
升级harbor配置文件
docker run -it --rm -v /backup/harbor/harbor.cfg:/harbor-migration/harbor-cfg/harbor.cfg goharbor/harbor-migrator:v1.6.0 --cfg up 将1.6版本的harbor解压到/data目录下 tar zxvf harbor-offline-installer-v1.8.0.tgz -C /data/ cd /data/harbor
复制升级后的数据框架和数据到当前目录
cp -r /backup/harbor/data/ ./ cp /backup/harbor/harbor.cfg ./
新版本的docker-compose.yml需要手动修改,将harbor所需的容器的目录执行到/data/harbor/data下
version: '2' services: log: image: goharbor/harbor-log:v1.6.0 container_name: harbor-log restart: always volumes: - ./data/log/:/var/log/docker/:z - ./common/config/log/:/etc/logrotate.d/:z ports: - 127.0.0.1:1514:10514 networks: - harbor registry: image: goharbor/registry-photon:v2.6.2-v1.6.0 container_name: registry restart: always volumes: - ./data/registry:/storage:z - ./common/config/registry/:/etc/registry/:z networks: - harbor environment: - GODEBUG=netdns=cgo depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://127.0.0.1:1514" tag: "registry" postgresql: image: goharbor/harbor-db:v1.6.0 container_name: harbor-db restart: always volumes: - ./data/database:/var/lib/postgresql/data:z networks: - harbor env_file: - ./common/config/db/env depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://127.0.0.1:1514" tag: "postgresql" adminserver: image: goharbor/harbor-adminserver:v1.6.0 container_name: harbor-adminserver env_file: - ./common/config/adminserver/env restart: always volumes: - ./data/config/:/etc/adminserver/config/:z - ./data/secretkey:/etc/adminserver/key:z - ./data/:/data/:z networks: - harbor depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://127.0.0.1:1514" tag: "adminserver" ui: image: goharbor/harbor-ui:v1.6.0 container_name: harbor-ui env_file: - ./common/config/ui/env restart: always volumes: - ./common/config/ui/app.conf:/etc/ui/app.conf:z - ./common/config/ui/private_key.pem:/etc/ui/private_key.pem:z - ./common/config/ui/certificates/:/etc/ui/certificates/:z - ./data/secretkey:/etc/ui/key:z - ./data/ca_download/:/etc/ui/ca/:z - ./data/psc/:/etc/ui/token/:z networks: - harbor depends_on: - log - adminserver - registry logging: driver: "syslog" options: syslog-address: "tcp://127.0.0.1:1514" tag: "ui" jobservice: image: goharbor/harbor-jobservice:v1.6.0 container_name: harbor-jobservice env_file: - ./common/config/jobservice/env restart: always volumes: - ./data/job_logs:/var/log/jobs:z - ./common/config/jobservice/config.yml:/etc/jobservice/config.yml:z networks: - harbor depends_on: - redis - ui - adminserver logging: driver: "syslog" options: syslog-address: "tcp://127.0.0.1:1514" tag: "jobservice" redis: image: goharbor/redis-photon:v1.6.0 container_name: redis restart: always volumes: - ./data/redis:/var/lib/redis networks: - harbor depends_on: - log logging: driver: "syslog" options: syslog-address: "tcp://127.0.0.1:1514" tag: "redis" proxy: image: goharbor/nginx-photon:v1.6.0 container_name: nginx restart: always volumes: - ./common/config/nginx:/etc/nginx:z networks: - harbor ports: - 80:80 - 443:443 - 4443:4443 depends_on: - postgresql - registry - ui - log logging: driver: "syslog" options: syslog-address: "tcp://127.0.0.1:1514" tag: "proxy" networks: harbor: external: false
在当前目录下启动harbor实例
./install.sh
页面访问https://devops.reg.io
没做dns的话可直接访问ip
查看原镜像是否丢失,测试上传下载镜像是否能成功
Harbor1.6升级到harbor1.8
备份harbor1.6
cd /data/ docker-compose down mv harbor /backup1/
解压harbor1.8到/data/目录下
tar zxvf harbor-offline-installer-v1.8.0.tgz -C /data/
升级harbor.cfg到harbor.yml
docker run -it --rm -v /backup1/harbor/harbor.cfg:/harbor-migration/harbor-cfg/harbor.cfg -v /data/harbor/harbor.yml:/harbor-migration/harbor-cfg-out/harbor.yml goharbor/harbor-migrator:v1.8.0 --cfg up
由于1.8版本的docker-compse已交由harbor.yml控制,在./install.sh时加载harbor.yml文件生成docker-compose.yml(注:数据目录必须使用绝对路径)故还需要对新的harbor.yml进行修改
修改数据目录和日志目录
data_volume: /data/harbor/data location: /data/harbor/data/log
将数据拷贝到harbor1.8的软件目录下
cp -r /backup1/harbor/data/ /data/harbor/
修改证书期限(10年)
cd /data/harbor/data/cert/ find . -type f | xargs rm –f $ openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 3650 -out ca.crt $ openssl req -newkey rsa:4096 -nodes -sha256 -keyout devops-reg.io.key -out devops-reg.io.csr $ echo 'subjectAltName = DNS: devops-reg.io, IP:192.168.2.112' > extfile.cnf $ openssl x509 -req -days 3650 -in devops-reg.io.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out devops-reg.io.crt $ openssl x509 -noout -text -in devops-reg.io.crt 启动harbor1.8 cd /data/harbor ./install.sh
登陆https://devops-reg.io(图为升级测试的结果)
完成测试上传下载镜像(注:稳定运行一段时间,将旧版本的备份数据清理!)
参考文章:https://github.com/goharbor/harbor/blob/master/docs/migration_guide.md
相关文章:
- Xtrabackup安装以及应用
- Nagios 配置及监控
- Docker 镜像及Docker仓库配置 [四]
- Kubernetes 1.14 二进制集群安装