[TOC]
Q: 什么是Harbor?
答: Harbor(Harbor)是一个开源受信任的云本地注册项目(
cloud native registry project
),它存储、签署和扫描内容。Harbor通过添加用户通常需要的功能(如安全、身份和管理)来扩展开源 Docker 分发。使注册表更接近生成和运行环境可以提高映像传输效率。港湾支持在注册表之间复制映像,还提供高级安全功能,如用户管理、访问控制和活动审核。 其目标是成为 Kubernetes 值得信赖的云原生存储库 官网地址: https://goharbor.io/ 项目地址: https://github.com/goharbor/harbor
Q: 为啥要使用选择Harbor?
答: HHarbor 是一个云原生计算基金会毕业项目,Harbor是VMware公司开源的企业级
Docker Registry
项目即企业级 Docker 私有仓库;其目标是帮助用户迅速搭建一个企业级的Docker Registry服务,它是以Docker公司开源的registry为基础,但其提供了可视化管理界面以及高级安全功能,如用户管理、访问控制和活动审核。
Harbor 特性
Harbor 组成 描述: 用于部 署Harbor 的 Docker Compose模板位于 /Deployer/docker-compose.yml,由5个容器组成,这几个容器通过Docker link的形式连接在一起,在容器之间通过容器名字互相访问。
# 依赖镜像
Loaded image: goharbor/harbor-db:v2.4.1
Loaded image: goharbor/redis-photon:v2.4.1
Loaded image: goharbor/notary-signer-photon:v2.4.1
Loaded image: goharbor/clair-photon:v2.4.1
Loaded image: goharbor/clair-adapter-photon:v2.4.1
Loaded image: goharbor/harbor-core:v2.4.1
Loaded image: goharbor/harbor-portal:v2.4.1
Loaded image: goharbor/harbor-log:v2.4.1
Loaded image: goharbor/nginx-photon:v2.4.1
Loaded image: goharbor/prepare:v2.4.1
Loaded image: goharbor/harbor-registryctl:v2.4.1
Loaded image: goharbor/notary-server-photon:v2.4.1
Loaded image: goharbor/trivy-adapter-photon:v2.4.1
Loaded image: goharbor/harbor-jobservice:v2.4.1
Loaded image: goharbor/chartmuseum-photon:v2.4.1
Loaded image: goharbor/registry-photon:v2.4.1
# 安装配置文件
~/harbor/common/config$ tree
.
├── core
│ ├── app.conf
│ ├── certificates
│ └── env
├── db
│ └── env
├── jobservice
│ ├── config.yml
│ └── env
├── log
│ ├── logrotate.conf
│ └── rsyslog_docker.conf
├── nginx
│ ├── conf.d
│ └── nginx.conf
├── portal
│ └── nginx.conf
├── registry
│ ├── config.yml
│ ├── passwd
│ └── root.crt
├── registryctl
│ ├── config.yml
│ └── env
└── shared
└── trust-certificates
Harbor认证过程
Harbor认证流程
系统要求 & System requirements:
On a Linux host: docker 17.06.0-ce+ and docker-compose 1.18.0+ and Python 2.7+
安装方式: Download binaries of Harbor release
安装环境声明:
Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-52-generic x86_64)
Docker 19.03.13
Docker-Compose 1.27.4
Harbor v2.4.1
安装流程:
# 1.我也安装Docker环境此处不再累述docker安装过程(请自行docker官网查阅),下面进行安装docker-compose
# 方式1: https://github.com/docker/compose/releases/
sudo wget https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -O /usr/bin/docker-compose
sudo chmod a+x /usr/bin/docker-compose
# 方式2: 建议使用阿里云的源 https://developer.aliyun.com/mirror/docker-ce
# apt install -y docker-compose
# 2.下载harbor-offline安装包: https://github.com/goharbor/harbor/releases
wget https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
tar -zxf harbor-offline-installer-v2.4.1.tgz && ls harbor/
# common.sh harbor.v2.4.1.tar.gz harbor.yml.tmpl install.sh LICENSE prepare
docker load -i harbor.v2.4.1.tar.gz
echo '192.168.1.2 harbor.weiyigeek.top' >> /etc/hosts
# 3.harbor.yml.tmpl配置文件进行基础安装配置并将修改的配置输入到harbor.yaml之中(注意还有这一步)
$ egrep -v "^#|^ #" harbor.yml.tmpl | tee harbor.yml
# 目标的主机名或者完全限定域名(注意不能是127.0.0.1)
hostname: harbor.weiyigeek.top
db_password:用于db_auth的MySQL数据库的根密码。更改此密码进行任何生产用途
max_job_workers:对于每个映像复制作业,
customize_crt:(on或off。默认为on)当此属性打开时,prepare脚本将为注册表的令牌的生成/验证创建私钥和根证书
ssl_cert:SSL证书的路径,仅当协议设置为https时才应用
ssl_cert_key:SSL密钥的路径,仅当协议设置为https时才应用
secretkey_path:用于在复制策略中加密或解密远程注册表的密码的密钥路径
# 非SSL端口
http:
port: 80
# SSL端口以及证书配置
https:
port: 443
certificate: /etc/harbor/pki/server.crt
private_key: /etc/harbor/pki/server.key
# harbor管理密码
harbor_admin_password: Harbor12345
# harbor的Postgre数据密码
database:
password: root123
max_idle_conns: 50
max_open_conns: 1000
# harbor数据存储目录
data_volume: /data/harbor
clair:
updaters_interval: 12
trivy:
ignore_unfixed: false
skip_update: false
insecure: false
# 默认值为3 对于每个映像复制作业服务中的复制工作人员的最大数量。
# 工作人员将存储库的所有标签同步到远程目标,但是由于每个工作人员都会消耗一定数量的网络/ CPU/IO资源,请根据主机的硬件资源仔细选择该属性的值;
jobservice:
max_job_workers: 10
# 提醒最大数
notification:
webhook_job_max_retry: 10
chart:
absolute_url: disabled
# 日志记录设置
log:
level: info
local:
# 在删除日志文件之前,将log_rotate_count旋转几次。如果count为0,则删除旧版本,而不是旋转。
rotate_count: 50
# 只有当日志文件的大小大于log_rotate_size字节时,才会对其进行旋转。如果size后面跟着k,则假设size的单位为千字节。
rotate_size: 200M
location: /var/log/harbor
_version: 2.0.0
# 代理设置
proxy:
http_proxy:
https_proxy:
no_proxy:
components:
- core
- jobservice
- clair
- trivy
# 4.基础环境与创建 https 证书以及配置相关目录权限
sudo mkdir -pv /data/harbor /etc/harbor/pki/
openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
# Country Name (2 letter code) [AU]:CN
# State or Province Name (full name) [Some-State]:ChongQing
# Locality Name (eg, city) []:ChongQing
# Organization Name (eg, company) [Internet Widgits Pty Ltd]: weiyigeek
# Organizational Unit Name (eg, section) []: weiyigeek
# Common Name (e.g. server FQDN or YOUR name) []:harbor.weiyigeek.top
# Email Address []:master@weiyigeek.top
cp server.key server.key.org && openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
# Signature ok
# subject=C = CN, ST = ChongQing, L = ChongQing, O = weiyigeek, OU = weiyigeek.top, CN = harbor.weiyigeek.top, emailAddress = master@weiyigeek.top
# Getting Private key
sudo cp server.key server.crt /etc/harbor/pki/
# 可读权限即可
sudo chmod -R 644 /etc/harbor/pki/
# 5.执行安装脚本install.sh
$ sudo ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 19.03.13
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.25.0
[Step 2]: loading Harbor images ...
Loaded image: goharbor/harbor-db:v2.4.1
Loaded image: goharbor/redis-photon:v2.4.1
Loaded image: goharbor/notary-signer-photon:v2.4.1
Loaded image: goharbor/clair-photon:v2.4.1
Loaded image: goharbor/clair-adapter-photon:v2.4.1
Loaded image: goharbor/harbor-core:v2.4.1
Loaded image: goharbor/harbor-portal:v2.4.1
Loaded image: goharbor/harbor-log:v2.4.1
Loaded image: goharbor/nginx-photon:v2.4.1
Loaded image: goharbor/prepare:v2.4.1
Loaded image: goharbor/harbor-registryctl:v2.4.1
Loaded image: goharbor/notary-server-photon:v2.4.1
Loaded image: goharbor/trivy-adapter-photon:v2.4.1
Loaded image: goharbor/harbor-jobservice:v2.4.1
Loaded image: goharbor/chartmuseum-photon:v2.4.1
Loaded image: goharbor/registry-photon:v2.4.1
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /home/weiyigeek/harbor
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
[Step 5]: starting Harbor ...
✔ ----Harbor has been installed and started successfully.---- # 表示安装成功
1.利用内部 DNS 域名解析 harbor.weiyigeek.top
配置将k8s集群中的机器DNS设置为内部DNS地址
~$ ansible k8s -m shell -a "sudo sed -i 's#127.0.0.53#192.168.12.253#g' /etc/resolv.conf"
~$ ansible k8s -m shell -a "ping harbor.weiyigeek.top -c 2"
# WeiyiGeek-224 | CHANGED | rc=0 >>
# PING harbor.weiyigeek.top (192.168.12.108) 56(84) bytes of data.
# 64 bytes from WeiyiGeek-108 (192.168.12.108): icmp_seq=1 ttl=64 time=0.227 ms
# 64 bytes from WeiyiGeek-108 (192.168.12.108): icmp_seq=2 ttl=64 time=0.167 ms
Harbor 访问测试 Step 1.访问 harbor.weiyigeek.top 使用Harbor的默认账号密码登陆
账号密码 : admin / Harbor12345
WeiyiGeek.harbor-login
Step 2.用户创建与项目创建: 系统管理 -> 用户管理
Step 3.普通用户项目创建:
项目 -> 新建项目 -> 项目名称与访问级别
WeiyiGeek.项目创建
PS: 项目如果设置为私有则必须采用所属用户进行验证登陆后才能进行拉取;
Step 4.管理员才能可以进行垃圾回收: 系统管理 -> 垃圾清理
Step 5.镜像构建与上传测试
# 1.配置本地docker的insecure-registries的Harbor仓库地址
# 自签证书需要忽略的不安全证书验证 "insecure-registries"
sudo tee /etc/docker/daemon.json <<'EOF'
{
"registry-mirrors": ["https://xlx9erfu.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"insecure-registries": ["harbor.weiyigeek.top"]
}
EOF
sudo systemctl daemon-reload && sudo systemctl restart docker
# 2.指定Harbor仓库认证
docker login harbor.weiyigeek.top
# Username: weiyigeek
# Password:
# WARNING! Your password will be stored unencrypted in /home/weiyigeek/.docker/config.json.Configure a credential helper to remove this warning. See
# https://docs.docker.com/engine/reference/commandline/login/#credentials-store
# Login Succeeded
# 3.测试本地镜像上传到haibor中
# 下载镜像
$ docker pull nginx
# 镜像重新打标签
$ docker tag nginx:latest harbor.weiyigeek.top/test/nginx:v1.1
$ docker images | grep "nginx"
# harbor.weiyigeek.top/test/nginx v1.1 c39a868aad02 12 hours ago 133MB
# nginx latest c39a868aad02 12 hours ago 133MB
# push 镜像到harbor
$ docker push harbor.weiyigeek.top/test/nginx:v1.1
# The push refers to repository [harbor.weiyigeek.top/test/nginx]
# 7b5417cae114: Pushed
# aee208b6ccfb: Pushed
# 2f57e21e4365: Pushed
# 2baf69a23d7a: Pushed
# d0fe97fa8b8c: Pushed
# v1.1: digest: sha256:34f3f875e745861ff8a37552ed7eb4b673544d2c56c7cc58f9a9bec5b4b3530e size: 1362
Step 6.在Harbor上查看WeiyiGeek用户上传的镜像
WeiyiGeek.Harbor
Step 7.在其它节点拉取我们上传测试的镜像
# 1.同样需要修改Docker的守护进程
"insecure-registries": ["harbor.weiyigeek.top"]
# 2.拉取镜像测试
$ docker pull harbor.weiyigeek.top/test/nginx:v1.1
# v1.1: Pulling from test/nginx
# bb79b6b2107f: Pull complete
# 5a9f1c0027a7: Pull complete
# b5c20b2b484f: Pull complete
# 166a2418f7e8: Pull complete
# 1966ea362d23: Pull complete
# Digest: sha256:34f3f875e745861ff8a37552ed7eb4b673544d2c56c7cc58f9a9bec5b4b3530e
# Status: Downloaded newer image for harbor.weiyigeek.top/test/nginx:v1.1
# harbor.weiyigeek.top/test/nginx:v1.1
$ docker images | grep "nginx"
# harbor.weiyigeek.top/test/nginx v1.1 c39a868aad02 19 hours ago 133MB
添加支持Chart仓库扩展 描述: 安装chart图表仓库操作流程:
# (1) 当前harbor环境已具备
~/harbor$ sudo docker-compose ps
# [sudo] password for weiyigeek:
# Name Command State Ports
# ---------------------------------------------------------------------------------------------------------------
# harbor-core /harbor/entrypoint.sh Up (healthy)
# harbor-db /docker-entrypoint.sh Up (healthy)
# harbor-jobservice /harbor/entrypoint.sh Up (healthy)
# harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp
# harbor-portal nginx -g daemon off; Up (healthy)
# nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp
# redis redis-server /etc/redis.conf Up (healthy)
# registry /home/harbor/entrypoint.sh Up (healthy)
# registryctl /home/harbor/start.sh Up (healthy)
# (2) 安装目录
~/harbor$ ls
# common docker-compose.yml harbor.v2.4.1.tar.gz harbor.yml.tmpl LICENSE server.crt server.key
# common.sh harbor_install.log harbor.yml install.sh prepare server.csr server.key.org
# (3) 添加 chart 图表支持
~/harbor$ sudo ./install.sh --with-chartmuseum
# [Step 0]: checking if docker is installed ...
# Note: docker version: 19.03.13
# [Step 1]: checking docker-compose is installed ...
# Note: docker-compose version: 1.25.0
# [Step 2]: loading Harbor images ...
# Loaded image: goharbor/harbor-db:v2.4.1
# .....
# Loaded image: goharbor/registry-photon:v2.4.1
# [Step 3]: preparing environment ...
# [Step 4]: preparing harbor configs ...
# prepare base dir is set to /home/weiyigeek/harbor
# Clearing the configuration file: /config/db/env
# ......
# Clearing the configuration file: /config/registryctl/config.yml
# Generated configuration file: /config/portal/nginx.conf
# .....
# Generated configuration file: /compose_location/docker-compose.yml
# Clean up the input dir
# Note: stopping existing Harbor instance ...
# Stopping harbor-jobservice ... done
# ....
# Removing network harbor_harbor
# Removing network harbor_harbor-chartmuseum
# WARNING: Network harbor_harbor-chartmuseum not found.
# [Step 5]: starting Harbor ...
# Creating network "harbor_harbor" with the default driver
# Creating network "harbor_harbor-chartmuseum" with the default driver
# Creating harbor-log ... done
# Creating registryctl ... done
# Creating chartmuseum ... done
# Creating registry ... done
# Creating harbor-db ... done
# Creating harbor-portal ... done
# Creating redis ... done
# Creating harbor-core ... done
# Creating harbor-jobservice ... done
# Creating nginx ... done
# ✔ ----Harbor has been installed and started successfully.----
WeiyiGeek.Helm Charts已安装完成
温馨提示: 如果想安装公正服务 notary 以及漏洞扫描器 trivy ,我们在执行./install.sh
后添加如下参数。
$ sudo ./install.sh --with-notary --with-trivy --with-chartmuseum
描述: 当 Harbor 证书到期后我们需要续签证书或者重新申请证书,并替换掉配置 harbor.yml 文件中的 certificate、private_key 配置项。
操作流程: 步骤 01.创建CA并签发harbor证书
# 1.打印config模板文件从而进行修改其中有两个配置.
cfssl print-defaults config > ca-config.json
vim ca-config.json
{
"signing": {
"default": {
"expiry": "8760h"
},
"profiles": {
"harbor": {
"expiry": "87600h",
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
]
}
}
}
}
cfssl print-defaults csr > ca-csr.json
vim ca-csr.json
{
"CN": "weiyigeek.top",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "ChongQing",
"ST": "ChongQing",
"O": "weiyigeek",
"OU": "weiyigeek.top"
}
]
}
# 2.准备一份harbor证书配置请求文件。
tee harbor-csr.json <<'EOF'
{
"CN": "harbor.weiyigeek.top",
"hosts": [
"127.0.0.1",
"192.168.12.108",
"harbor.weiyigeek.top"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "ChongQing",
"ST": "ChongQing",
"O": "weiyigeek",
"OU": "weiyigeek.top"
}
]
}
EOF
# 2.利用CA签发 harbor 仓库使用的服务端证书。
$ cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=harbor harbor-csr.json | cfssljson -bare harbor
$ ls harbor*
harbor.csr harbor-csr.json harbor-key.pem harbor.pem
# 3.将生成证书与密钥改个后缀。
cp harbor.pem /etc/harbor/pki/harbor.crt
cp harbor-key.pem /etc/harbor/pki/harbor.key
步骤 02.修改替换对应的证书文件。
# 1.配置修改
$ im harbor.yml
# 非SSL端口
http:
port: 80
# SSL端口以及证书配置
https:
port: 443
certificate: /etc/harbor/pki/harbor.crt
private_key: /etc/harbor/pki/harbor.key
步骤 03.利用docker-compose停止harbor相关容器,更新预加载配置后再重启。
cd /opt/harbor && docker-compose down
/opt/harbor# ./prepare
prepare base dir is set to /opt/harbor
Clearing the configuration file: /config/portal/nginx.conf
........
Clearing the configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/portal/nginx.conf
........
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
/opt/harbor# docker-compose up -d
步骤 04.浏览器访问验证或者利用cfssl命令验证配置的证书, 注意如果没有配置公网和内部解析, 请在/etc/hosts指定对应的IP地址。
$ cfssl certinfo -domain harbor.weiyigeek.top
描述: 如果您是从以前版本的 Harbor 升级,您可能需要更新配置文件并迁移您的数据以适应更高版本的数据库架构。
Harbor 更新参考地址: https://goharbor.io/docs/2.4.0/administration/upgrade/
温馨提示: 如果要升级使用 Helm 部署的 Harbor 实例,请参阅升级使用 Helm 部署的 Harbor 【https://goharbor.io/docs/2.4.0/administration/upgrade/helm-upgrade/ 】。
环境说明
当前Harbor版本(v2.1.3)及其旧的离线安装包 harbor-offline-installer-v2.1.3.tgz
更新Harbor版本(v2.4.1)及其当前时间最新的离线安装包 harbor-offline-installer-v2.4.1.tgz
温馨提示: 截至2022年2月10日,目前最新的Harbor版本为[v2.4.1], 我们可以访问harbor的releases获取最新的Harbor(https://github.com/goharbor/harbor/releases)
升级前重要提示
1.在任何数据迁移之前备份Harbor相关数据,例如
# harbor 安装配置目录
cp /op/harbor{,.bak}
# harbor 数据库目录
cp -a /data/harbor{,.bak}
2.在v2.0中项目的元数据存储在数据库中,当升级后首次启动 Harbor 时,它将遍历注册表存储中的项目以将项目的元数据提取到数据库中, 如果注册表中存在大量项目,则此过程可能需要相对较长的时间
,尤其是在将注册表配置为使用外部存储(如 S3)时。 可以查看 harbor-core registry 日志验证是否在进行安装。
3.在 v2.2 之后Clair漏洞扫描仪将被移除, 建议在升级后使用 Trivy 作为默认扫描仪,或将 Clair 添加为外部扫描仪。
4.在 v2.3 使用 PostgreSQL v13.2 , 在升级过程中 Harbor 将删除旧的 PostgreSQL 数据,并将其迁移到兼容的新版本 PostgreSQL 的新目标位置, 所以在升级到v2.3.0 必须进行 PostgreSQL 数据备份。
快速升级Harbor或者迁移数据 步骤 01.停止 Harbor 所有组件运行实例。
# 我的安装目录是 /opt/harbor,你可根据实际情况进入对应的harbor解压目录
cd /opt/harbor && docker-compose down
步骤 02.备份 Harbor 相关数据(生产环境必须要、测试环境看你自己),以便在必要时可以回滚到当前版本。
# 备份 harbor 安装配置目录
cp -a /opt/harbor{,.bak}
# 备份 harbor 数据库目录
cp -a /data/harbor{,.bak}
步骤 03.从Harbor官方的Github中获取最新的Harbor版本包并将其解压缩(https://github.com/goharbor/harbor/releases), 国内环境推荐采用离线安装包的方式进行安装部署。
# 后台下载+断点续传
wget -b -c https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
温馨提示:建议通过迅雷进行下载,国内在服务器上采用wget直接下载太慢了。
步骤 04.解压下载的脱机安装程序包到harbor目录之中,并导入harbor对应版本的相关组件镜像到docker本地注册表中。
# 进入 脱机安装程序包 所在的目录执行解压操作
cd /opt/ && tar zxf harbor-offline-installer-v2.4.1.tgz
ls /opt/harbor
certs common common.sh docker-compose.yml harbor.v2.4.1.tar.gz harbor.yml harbor.yml.tmpl install.sh LICENSE prepare
# 导入镜像 && 查看导入的镜像
docker load -i harbor/harbor.v2.4.1.tar.gz
docker images --filter label=build-date=20211206
# REPOSITORY TAG IMAGE ID CREATED SIZE
# goharbor/harbor-exporter v2.4.1 0ee361b5454a 8 weeks ago 82.7MB
# goharbor/chartmuseum-photon v2.4.1 337a9d03b197 8 weeks ago 174MB
# goharbor/redis-photon v2.4.1 2bbe19b8cc5d 8 weeks ago 156MB
# goharbor/trivy-adapter-photon v2.4.1 d39fd42c93f0 8 weeks ago 151MB
# goharbor/notary-server-photon v2.4.1 e75c68b6638b 8 weeks ago 111MB
# goharbor/notary-signer-photon v2.4.1 17a627caf6dd 8 weeks ago 108MB
# goharbor/harbor-registryctl v2.4.1 bff3d2665456 8 weeks ago 137MB
# goharbor/registry-photon v2.4.1 b46e45c49d6f 8 weeks ago 79.2MB
# goharbor/nginx-photon v2.4.1 78aad8c8ef41 8 weeks ago 45.7MB
# goharbor/harbor-log v2.4.1 c86562daee64 8 weeks ago 160MB
# goharbor/harbor-jobservice v2.4.1 d8baceb5f1f6 8 weeks ago 220MB
# goharbor/harbor-core v2.4.1 80a4e3e60403 8 weeks ago 198MB
# goharbor/harbor-portal v2.4.1 1c9ed1cc3cb9 8 weeks ago 54.7MB
# goharbor/harbor-db v2.4.1 417d0a840247 8 weeks ago 222MB
# goharbor/prepare v2.4.1 e9158d34970b 8 weeks ago 257MB
步骤 05.升级迁移(migrate - 英 [maɪˈɡreɪt] )harbor指定版本并生成最新harbor.yml 配置文件
$ docker run -it --rm -v /:/hostfs goharbor/prepare:v2.4.1 migrate -i /opt/harbor/harbor.yml
# migrating to version 2.1.0
# migrating to version 2.2.0
# migrating to version 2.3.0
# migrating to version 2.4.0
# Written new values to /opt/harbor/harbor.yml
步骤 06.最新执行安装更新Harbor操作,此处我安装 notary(公证服务)、Trivy 和 chart(图表存储库)等服务
sudo ./install.sh --with-notary --with-trivy --with-chartmuseum
# Creating harbor-log ... done
# Creating chartmuseum ... done
# Creating registryctl ... done
# Creating harbor-db ... done
# Creating redis ... done
# Creating harbor-portal ... done
# Creating registry ... done
# Creating notary-signer ... done
# Creating harbor-core ... done
# Creating trivy-adapter ... done
# Creating notary-server ... done
# Creating harbor-jobservice ... done
# Creating nginx ... done
# 出现如下提示表明更新,如有错误请查看错误信息,并进行Google解决。
✔ ----Harbor has been installed and started successfully.----
WeiyiGeek.升级Harbor服务器到v2.4.1
至此,完成了harbor从v2.1.3版本更新迁移到v2.4.1版本。
描述: 在 Harbor 初始化安装时我们会在harbor.yaml文件中设定admin用户密码,当我们登录更改其密码后忘记设定的密码,如何进行重置密码?
版本环境说明: v2.4.x
操作流程:
步骤01.通过docker exec -it harbor-db /bin/bash
命令进入harbor-db容器内部
步骤02.执行如下postgresql命令行
psql -h postgresql -d postgres -U postgres # 这要输入默认密码:root123
psql -U postgres -d postgres -h 127.0.0.1 -p 5432 # 或者用这个可以不输入密码
步骤03.然后切换到harbor所在的数据库,执行 \c registry
命令
步骤04.执行SQL语句select * from harbor_user;
查看harbor_user表
步骤05.例如修改admin的密码,修改为初始化密码 Harbor12345 修改好了之后再可以从web ui上再改一次。
# 如下此方法不行
update harbor_user set password='a71a7d0df981a61cbb53a97ed8d78f3e',salt='ah3fdh5b7yxepalg9z45bu8zb36sszmr' where username='admin';
# 正确做法
update harbor_user set salt='', password='' where username='admin';
步骤06.执行 \q
退出postgresql,再执行 exit
退出容器。
步骤07.重启harbor服务,以配置中的默认密码进行登陆。
WeiyiGeek.重置Harbor仓库管理员密码
错误信息:
sudo ./install.sh --with-notary --with-trivy --with-chartmuseum
prepare base dir is set to /opt/harbor
Error happened in config validation...
ERROR:root:Error: the protocol must be https when Harbor is deployed with Notary
错误原因: 错误root错误,当Harbor与公证人一起部署时,协议必须是https
解决办法: 启用443以及设置证书,或者取消公证人Notary安装即可解决。
# https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /etc/harbor/pki/server.crt
private_key: /etc/harbor/pki/server.key