一 harbor安装准备

客户端
   ↓
Nginx
   ↓
Core
   ↓
 ┌──────────────┬───────────────┐
Registry      Jobservice
   ↓              ↓
磁盘存储       Redis / DB
                ↓
             PostgreSQL

1.1 组件说明表

| 组件名称                | 容器名称(默认)     | 类型   | 主要作用                  | 运维关注点            |
| ------------------- | -------------------- | ---- | --------------------- | ---------------- |
| Core                | harbor-core          | 核心服务 | 提供 API、权限认证、项目管理、任务调度 | API 报错、认证失败、日志异常 |
| Portal              | harbor-portal        | 前端   | Web UI 页面展示           | 页面 502/白屏        |
| Registry            | harbor-registry      | 核心存储 | 镜像 push/pull、镜像存储     | push 失败、磁盘满      |
| Registry Controller | harbor-registryctl   | 控制服务 | 管理 registry、执行 GC     | 垃圾回收异常           |
| Jobservice          | harbor-jobservice    | 后台任务 | 镜像复制、扫描任务、GC 调度       | 任务堆积、队列卡死        |
| Database            | harbor-db            | 数据库  | 存储用户、项目、标签、元数据        | 连接数过高、慢查询        |
| Redis               | harbor-redis         | 缓存   | 任务队列、会话缓存             | 内存占满、连接异常        |
| Trivy               | harbor-trivy         | 安全扫描 | 镜像漏洞扫描                | CVE 数据更新失败       |
| Notary(可选)       | harbor-notary-server | 镜像签名 | Docker Content Trust  | 签名验证失败           |
| Nginx               | harbor-nginx         | 反向代理 | SSL 终止、统一入口           | 443 访问失败、证书问题    |

1.2 下载安装包

https://goharbor.cn/docs/2.13.0/

在这里插入图片描述
链接如下

https://github.com/goharbor/harbor/releases/download/v2.14.2/harbor-online-installer-v2.14.2.tgz

1.3 资源配置限制

资源类型 最低配置 推荐配置
CPU 2 vCPU 4 vCPU
内存 4 GB 8 GB
磁盘 40 GB 160 GB

二 安装

2.1 去目录下解压

[root@rocky9-3 k8s-learn]# cd k8s-harbor/
[root@rocky9-3 k8s-harbor]# ll
总用量 690212
-rw-r--r--. 1 root root 706776117  214 01:22 harbor-offline-installer-v2.14.2.tgz
[root@rocky9-3 k8s-harbor]# tar xzvf harbor-offline-installer-v2.14.2.tgz 
harbor/harbor.v2.14.2.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl

2.2 进入harbor目录

[root@rocky9-3 harbor]# ll
总用量 696568
-rw-r--r--. 1 root root      3646  112 17:13 common.sh
-rw-r--r--. 1 root root 713241468  112 17:14 harbor.v2.14.2.tar.gz
-rw-r--r--. 1 root root     14688  112 17:13 harbor.yml.tmpl
-rwxr-xr-x. 1 root root      1975  112 17:13 install.sh
-rw-r--r--. 1 root root     11347  112 17:13 LICENSE
-rwxr-xr-x. 1 root root      2211  112 17:13 prepare

首先编辑这个

2.3 生成自签名证书

1 生成CA证书私钥

生成CA证书私钥

openssl genrsa -out ca.key 4096

文件夹里面会多出来一个ca

[root@rocky9-3 harbor]# openssl genrsa -out ca.key 4096
[root@rocky9-3 harbor]# ll
总用量 696572
-rw-------. 1 root root      3272  214 09:23 ca.key
-rw-r--r--. 1 root root      3646  112 17:13 common.sh
-rw-r--r--. 1 root root 713241468  112 17:14 harbor.v2.14.2.tar.gz
-rw-r--r--. 1 root root     14688  112 17:13 harbor.yml.tmpl
-rwxr-xr-x. 1 root root      1975  112 17:13 install.sh
-rw-r--r--. 1 root root     11347  112 17:13 LICENSE
-rwxr-xr-x. 1 root root      2211  112 17:13 prepare

生成crt

openssl req -x509 -new -nodes -sha512 -days 3650   -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.local"   -key ca.key   -out ca.crt
2 生成CA

生成 harbor自己的CA
证书通常包含 .crt 文件和 .key 文件,例如,rocky9-3.crt 和 rocky9-3.key
生成私钥

openssl genrsa -out rocky9-3.key 4096

[root@rocky9-3 harbor]# openssl req -sha512 -new \
>   -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=rocky9-3" \
>   -key rocky9-3.key \
>   -out rocky9-3.csr


3 生成服务器证书

生成证书签名请求 (CSR)
调整 -subj 选项中的值以反映您的组织。如果您使用 FQDN 连接您的 Harbor 主机,则必须将其指定为通用名称 (CN) 属性并在密钥和 CSR 文件名中使用它

[root@rocky9-3 harbor]# openssl x509 -req -sha512 -days 3650 \
>   -extfile v3.ext \
>   -CA ca.crt -CAkey ca.key -CAcreateserial \
>   -in rocky9-3.csr \
>   -out rocky9-3.crt
Certificate request self-signature ok
subject=C=CN, ST=Beijing, L=Beijing, O=example, OU=Personal, CN=rocky9-3

生成 x509 v3 扩展文件。
无论您是使用 FQDN 还是 IP 地址连接到您的 Harbor 主机,您都必须创建此文件,以便您可以为您的 Harbor 主机生成符合主题备用名称 (SAN) 和 x509 v3 扩展要求的证书。替换 DNS 条目以反映您的域名。

[root@rocky9-3 harbor]# hostname -I
192.168.80.173 172.16.213.201 172.17.0.1 10.244.2.0 10.244.2.1 
[root@rocky9-3 harbor]# cat > v3.ext <<EOF
> authorityKeyIdentifier=keyid,issuer
> basicConstraints=CA:FALSE
> keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
> extendedKeyUsage = serverAuth
> subjectAltName = @alt_names
> 
> [alt_names]
> DNS.1=rocky9-3
> IP.1=192.168.80.173
> EOF

使用 v3.ext 文件为您的 Harbor 主机生成证书。

root@rocky9-3 harbor]# openssl x509 -req -sha512 -days 3650 \
>   -extfile v3.ext \
>   -CA ca.crt -CAkey ca.key -CAcreateserial \
>   -in rocky9-3.csr \
>   -out rocky9-3.crt
Certificate request self-signature ok
subject=C=CN, ST=Beijing, L=Beijing, O=example, OU=Personal, CN=rocky9-3

4 向docker和harbor提供证书

生成 ca.crt、rocky9-3.crt 和 rocky9-3.key 文件后,您必须将它们提供给 Harbor 和 Docker,并重新配置 Harbor 以使用它们。

[root@rocky9-3 harbor]# ll
总用量 696596
-rw-r--r--. 1 root root      2049  214 09:25 ca.crt
-rw-------. 1 root root      3272  214 09:25 ca.key
-rw-r--r--. 1 root root        41  214 13:12 ca.srl
-rw-r--r--. 1 root root      3646  112 17:13 common.sh
-rw-r--r--. 1 root root 713241468  112 17:14 harbor.v2.14.2.tar.gz
-rw-r--r--. 1 root root     14688  112 17:13 harbor.yml.tmpl
-rwxr-xr-x. 1 root root      1975  112 17:13 install.sh
-rw-r--r--. 1 root root     11347  112 17:13 LICENSE
-rwxr-xr-x. 1 root root      2211  112 17:13 prepare
-rw-r--r--. 1 root root      2118  214 13:12 rocky9-3.crt
-rw-r--r--. 1 root root      1700  214 13:10 rocky9-3.csr
-rw-------. 1 root root      3272  214 13:10 rocky9-3.key
-rw-r--r--. 1 root root       247  214 13:11 v3.ext

将服务器证书和密钥复制到 Harbor 主机上的证书文件夹中

[root@rocky9-3 harbor]# cp rocky9-3.crt /data/cert/
[root@rocky9-3 harbor]# cp rocky9-3.key /data/cert/

将 rocky9-3.crt 转换为 rocky9-3.cert,供 Docker 使用。
Docker 守护程序将 .crt 文件解释为 CA 证书,将 .cert 文件解释为客户端证书。

[root@rocky9-3 harbor]# openssl x509 -inform PEM -in rocky9-3.crt -out rocky9-3.cert
[root@rocky9-3 harbor]# 

将服务器证书、密钥和 CA 文件复制到 Harbor 主机上的 Docker 证书文件夹中。您必须首先创建相应的文件夹。

[root@rocky9-3 harbor]# mkdir -p /etc/docker/certs.d/rocky9-3
[root@rocky9-3 harbor]# cp ca.crt /etc/docker/certs.d/rocky9-3/
[root@rocky9-3 harbor]# cp rocky9-3.cert /etc/docker/certs.d/rocky9-3/
[root@rocky9-3 harbor]# cp rocky9-3.key /etc/docker/certs.d/rocky9-3/


重启docker

systemctl restart docker

root@rocky9-3 harbor]# systemctl restart docker
[root@rocky9-3 harbor]# 

证书配置

[root@rocky9-3 harbor]# tree /data/cert/
/data/cert/
├── rocky9-3.crt
└── rocky9-3.key

0 directories, 2 files
[root@rocky9-3 harbor]# tree /etc/docker/certs.d/rocky9-3/
/etc/docker/certs.d/rocky9-3/
├── ca.crt
├── rocky9-3.cert
└── rocky9-3.key


5 校验证书是否正确
[root@rocky9-3 harbor]# openssl x509 -in ca.crt -noout -text | grep -E "Subject:|CA:"
        Subject: C=CN, ST=Beijing, L=Beijing, O=example, OU=Personal, CN=harbor.local
                CA:TRUE
[root@rocky9-3 harbor]# openssl x509 -in rocky9-3.crt -noout -text | grep -A1 "Subject Alternative Name"
            X509v3 Subject Alternative Name: 
                DNS:rocky9-3, IP Address:192.168.80.173
[root@rocky9-3 harbor]# openssl verify -CAfile ca.crt rocky9-3.crt
rocky9-3.crt: OK
[root@rocky9-3 harbor]# openssl x509 -in rocky9-3.crt -noout -text | grep -A1 "Subject Alternative Name"
            X509v3 Subject Alternative Name: 
                DNS:rocky9-3, IP Address:192.168.80.173
[root@rocky9-3 harbor]# 

2.4 部署harbor的参数

通过在 harbor.yml 中指定 hostname 和 https 属性来配置 Harbor 以使用证书的信息.
再生产环境中,harbor必须使用https

Harbor 部署的必需参数
参数 子参数 描述和附加参数
hostname 指定要部署 Harbor 的目标主机的 IP 地址或完全限定域名 (FQDN)。这是您访问 Harbor Portal 和 registry 服务的地址。例如,192.168.1.10reg.yourdomain.com。registry 服务必须可供外部客户端访问,因此不要将 localhost127.0.0.10.0.0.0 指定为主机名。
http   请勿在生产环境中使用 HTTP。仅在没有连接到外部互联网的气隙测试或开发环境中,使用 HTTP 才是可以接受的。在非气隙环境中使用 HTTP 会使您容易受到中间人攻击。
  port HTTP 的端口号,用于 Harbor portal 和 Docker 命令。默认值为 80。
https   使用 HTTPS 访问 Harbor Portal 和令牌/通知服务。始终在生产环境和非气隙环境中使用 HTTPS。
  port HTTPS 的端口号,用于 Harbor portal 和 Docker 命令。默认值为 443。
  certificate SSL 证书的路径。
  private_key SSL 密钥的路径。
internal_tls   使用 HTTPS 在 Harbor 组件之间进行通信
  enabled 将此标志设置为 true 表示启用内部 tls
  dir 包含内部证书和密钥的目录的路径
harbor_admin_password 为 Harbor 系统管理员设置初始密码。此密码仅在 Harbor 首次启动时使用。在后续登录时,将忽略此设置,管理员密码在 Harbor Portal 中设置。默认用户名和密码为 adminHarbor12345
database   使用本地 PostgreSQL 数据库。您可以选择配置外部数据库,在这种情况下,您可以停用此选项。
  password 设置本地数据库的 root 密码。对于生产部署,您必须更改此密码。
  max_idle_conns 空闲连接池中的最大连接数。如果 <=0,则不保留空闲连接。
  max_open_conns 到数据库的最大打开连接数。如果 <= 0,则对打开连接的数量没有限制。
  conn_max_lifetime 连接可以重用的最长时间。如果 <= 0,则连接不会因连接的寿命而关闭。
  conn_max_idle_time 连接可以空闲的最长时间。如果 <= 0,则连接不会因连接的空闲时间而关闭。
data_volume 目标主机上存储 Harbor 数据的location。即使 Harbor 的容器被删除和/或重新创建,此数据也保持不变。您可以选择配置外部存储,在这种情况下,停用此选项并启用 storage_service。默认值为 /data
trivy   配置 Trivy 扫描器。
  ignore_unfixed 将此标志设置为 true 以仅显示已修复的漏洞。默认值为 false
  security_check 要检测的安全问题(以逗号分隔的列表)。可能的值为 vulnconfigsecret。默认为 vuln
  skip_update 您可能需要在测试或 CI/CD 环境中启用此标志,以避免 GitHub 速率限制问题。如果启用该标志,您必须手动下载 trivy-offline.tar.gz 存档,解压缩 trivy.dbmetadata.json 文件,并将它们挂载到容器中的 /home/scanner/.cache/trivy/db/trivy.db 路径中。默认值为 false
  insecure 将此标志设置为 true 以跳过验证 registry 证书。默认值为 false
  github_token 设置 GitHub 访问令牌以下载 Trivy DB。Trivy DB 由 Trivy 从 GitHub 发布页面下载。从 GitHub 匿名下载受每小时 60 个请求的限制。通常,这样的速率限制对于生产操作来说是足够的。如果出于任何原因,它不够用,您可以通过指定 GitHub 访问令牌将速率限制提高到每小时 5000 个请求。有关 GitHub 速率限制的更多详细信息,请参阅 https://developer.github.com/v3/#rate-limiting 。您可以通过按照 https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line 中的说明创建 GitHub 令牌
jobservice max_job_workers 作业服务中的最大复制 worker 数。对于每个镜像复制作业,worker 将仓库的所有标签同步到远程目标。增加此数字允许系统中进行更多并发复制作业。但是,由于每个 worker 都会消耗一定的网络/CPU/IO 资源,因此请根据主机的硬件资源设置此属性的值。默认值为 10。
notification webhook_job_max_retry 设置 Webhook 作业的最大重试次数。默认值为 10。
log   配置日志记录。Harbor 使用 `rsyslog` 收集每个容器的日志。
  level 将日志记录级别设置为 debuginfowarningerrorfatal。默认值为 info
  local 设置日志保留参数
  • rotate_count:日志文件在被删除之前轮换 rotate_count 次。如果计数为 0,则删除旧版本而不是轮换。默认值为 50。
  • rotate_size:仅当日志文件增长到大于 rotate_size 字节时才轮换。使用 k 表示千字节,M 表示兆字节,G 表示千兆字节。100100k100M100G 都是有效值。默认值为 200M。
  • location:设置存储日志的目录。默认值为 /var/log/harbor
  external_endpoint 启用此选项可将日志转发到 syslog 服务器。
  • protocol:syslog 服务器的传输协议。默认为 TCP。
  • host:syslog 服务器的 URL。
  • port:syslog 服务器监听的端口
proxy   配置供 trivy-adapter、复制作业服务和 Harbor 使用的代理。如果不需要代理,请留空。某些代理具有白名单设置,如果启用了 Trivy,则需要将以下 URL 添加到代理服务器白名单:github.comgithub-releases.githubusercontent.com*.s3.amazonaws.com.
  http_proxy 配置 HTTP 代理,例如,http://my.proxy.com:3128
  https_proxy 配置 HTTPS 代理,例如,http://my.proxy.com:3128
  no_proxy 配置何时不使用代理,例如,127.0.0.1,localhost,core,registry
cache   为您的 Harbor 实例配置缓存层。启用后,Harbor 将缓存一些 Harbor 资源(例如,工件、项目或项目元数据),从而减少重复请求相同 Harbor 资源所花费的时间和资源。强烈建议您在高并发拉取请求率的 Harbor 实例上启用此功能,以提高 Harbor 的整体性能。有关缓存层实现和性能改进的更多详细信息,请参阅 缓存层 wiki 页面
  enabled 默认为 false,设置为 true 以启用 Harbor 的缓存层。
  expire_hours 配置缓存过期时间限制(以小时为单位)。默认值为 24。

可选参数

Harbor 的可选参数
参数 子参数 描述和附加参数
external_url 启用此选项可使用外部代理。启用后,将不再使用主机名。
storage_service   默认情况下,Harbor 将镜像和图表存储在本地文件系统中。在生产环境中,您可能希望使用另一个存储后端而不是本地文件系统。下面列出的参数是 registry 的配置。有关如何配置不同后端的更多信息,请参阅下面的 *配置存储后端*。
  ca_bundle 自定义根 CA 证书的路径,该证书被注入到 registry 和 chart repository 容器的信任存储中。如果内部存储使用自签名证书,则通常需要此证书。
  filesystem 默认值为 filesystem,但您可以设置为 azuregcss3swiftoss。有关如何配置其他后端的信息,请参阅下面的 配置存储后端。设置 maxthreads 以限制到外部提供商的线程数。默认值为 100。
  redirect 当您要停用 registry 重定向时,将 deactivate 设置为 true
external_database   如果您停用本地数据库选项,请配置外部数据库设置。目前,Harbor 仅支持 PostgreSQL 数据库。您必须为 Harbor core 创建一个数据库。表在 Harbor 启动时自动生成。
  harbor

为 Harbor 数据配置外部数据库。

  • host:Harbor 数据库的主机名。
  • port:数据库端口。
  • db_name:数据库名称。
  • username:连接到 core Harbor 数据库的用户名。
  • password:您在 username 中设置的帐户的密码。
  • ssl_mode:启用 SSL 模式。
  • max_idle_conns:空闲连接池中的最大连接数。如果 <=0,则不保留空闲连接。默认值为 2。
  • max_open_conns:到数据库的最大打开连接数。如果 <= 0,则对打开连接的数量没有限制。默认值为 0。
external_redis   配置外部 Redis 实例。
  host 外部 Redis 实例的 redis_host:redis_port。如果您使用的是 Sentinel 模式,则此部分应为 host_sentinel1:port_sentinel1,host_sentinel2:port_sentinel2
  sentinel_master_set 仅在使用 Sentinel 模式时设置此项
  password 连接到外部 Redis 实例的密码。
  registry_db_index Harbor registry 的数据库索引。
  jobservice_db_index jobservice 的数据库索引。
  chartmuseum_db_index Chart museum 的数据库索引。
  trivy_db_index Trivy adapter 的数据库索引。
metric   配置将 Harbor 实例指标暴露到指定的端口和路径
  enabled 通过将其设置为 true 来启用在您的 Harbor 实例上暴露指标。默认为 false
  port 指标暴露的端口。默认值为 9090
  path 指标暴露的路径。默认值为 /metrics
trace   配置暴露分布式跟踪数据
  enabled 通过将其设置为 true 来启用在您的 Harbor 实例上暴露跟踪。默认为 false
  sample_rate 设置跟踪的采样率。例如,如果您要采样 100% 的跟踪数据,请将 sample_rate 设置为 1;如果您要采样 50% 的跟踪数据,请设置为 0.5,依此类推
  namespace 用于区分不同 Harbor 服务的命名空间,它将设置为键为 service.namespace 的属性
  attributes attributes 是一个键值字典,包含用于初始化跟踪提供程序的用户定义的自定义属性,所有这些属性都将添加到跟踪数据中
  jaeger
  • endpoint:端点的 url(例如 http://127.0.0.1:14268/api/traces)。设置端点表示通过 http 导出到 jaeger 收集器。
  • username::用于连接端点的用户名。如果不需要,则留空。
  • password::用于连接端点的密码。如果不需要,则留空。
  • agent_host:jaeger agent 的主机名。设置 agent_host 表示通过 udp 将数据导出到 jaeger agent。
  • agent_port::jaeger agent 的端口名。
  otel
  • endpoint:与 otel 兼容的后端的 hostname 和 port(例如 127.0.0.1:4318)。
  • url_path::端点的 url 路径(例如 127.0.0.1:4318
  • compression::是否启用数据压缩
  • insecure:忽略 otel 后端的证书验证
  • timeout::数据传输的超时时间

上面的参数还是非常多的,但是在生产中,至少要改这些

hostname: rocky9-3

https:
  port: 443
  certificate: /data/cert/rocky9-3.crt
  private_key: /data/cert/rocky9-3.key

harbor_admin_password: Admin@123

data_volume: /data

三harbar部署

3.1 修改yml文件

hostname: rocky9-3

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

# https related config
https:
  # https port for harbor, default is 443
  port: 443
  # The path of cert and key files for nginx
  certificate: /data/cert/rocky9-3.crt
  private_key: /data/cert/rocky9-3.key
harbor_admin_password: Admin@123

另外要注意一下这个地方

data_volume: /data

3.2 执行prepare来检查

[root@rocky9-3 harbor]# ./prepare
prepare base dir is set to /root/k8s-learn/k8s-harbor/harbor
Unable to find image 'goharbor/prepare:v2.14.2' locally
v2.14.2: Pulling from goharbor/prepare
5adc178031bc: Pull complete 
6c2683ad8eb6: Pull complete 
29022b7730e6: Pull complete 
e06428c81c9b: Pull complete 
26ca5ed7dad0: Pull complete 
1b53f1304785: Pull complete 
6902c808aabc: Pull complete 
836c838d6920: Pull complete 
906d689c7041: Pull complete 
b6472ec5af96: Pull complete 
Digest: sha256:838f47228b10437f171cefd332aab88356d00e281a9b696b2c4d0fd362f05d32
Status: Downloaded newer image for goharbor/prepare:v2.14.2
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
copy /data/secret/tls/harbor_internal_ca.crt to shared trust ca dir as name harbor_internal_ca.crt ...
ca file /hostfs/data/secret/tls/harbor_internal_ca.crt is not exist
copy  to shared trust ca dir as name storage_ca_bundle.crt ...
copy None to shared trust ca dir as name redis_tls_ca.crt ...
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

3.3 执行install 脚本

[root@rocky9-3 harbor]# mkdir -p /data/docker
[root@rocky9-3 harbor]# rsync -aHAX --numeric-ids /var/lib/docker/ /data/docker/
[root@rocky9-3 harbor]# mkdir -p /etc/docker
[root@rocky9-3 harbor]# ./install.sh

[Step 0]: checking if docker is installed ...

Note: docker version: 28.4.0

[Step 1]: checking docker-compose is installed ...

Note: Docker Compose version v2.39.4

[Step 2]: loading Harbor images ...
Loaded image: goharbor/prepare:v2.14.2
Loaded image: goharbor/trivy-adapter-photon:v2.14.2
Loaded image: goharbor/harbor-core:v2.14.2
Loaded image: goharbor/harbor-db:v2.14.2
6d3ae23b32a1: Loading layer [==================================================>]  11.63MB/11.63MB
3ddbb32889eb: Loading layer [==================================================>]  3.584kB/3.584kB
525194864e79: Loading layer [==================================================>]   2.56kB/2.56kB
3f292846d232: Loading layer [==================================================>]  63.06MB/63.06MB
014a25a3c85f: Loading layer [==================================================>]  63.99MB/63.99MB
Loaded image: goharbor/harbor-jobservice:v2.14.2
a5f70ebbe8a4: Loading layer [==================================================>]  8.683MB/8.683MB
8984529f2f3f: Loading layer [==================================================>]  4.096kB/4.096kB
b406224d99a4: Loading layer [==================================================>]  18.96MB/18.96MB
ef82472cb876: Loading layer [==================================================>]  3.072kB/3.072kB
7b197c1c2f63: Loading layer [==================================================>]  39.09MB/39.09MB
c177a6d74ce7: Loading layer [==================================================>]  58.98MB/58.98MB
Loaded image: goharbor/harbor-registryctl:v2.14.2
f8e4548401aa: Loading layer [==================================================>]  133.8MB/133.8MB
Loaded image: goharbor/nginx-photon:v2.14.2
9358925f5567: Loading layer [==================================================>]  133.8MB/133.8MB
54717031cc48: Loading layer [==================================================>]  6.985MB/6.985MB
5a2a5e2b4e53: Loading layer [==================================================>]  253.4kB/253.4kB
27b2eaaf7cff: Loading layer [==================================================>]  1.539MB/1.539MB
Loaded image: goharbor/harbor-portal:v2.14.2
9a142a04d5ad: Loading layer [==================================================>]  16.64MB/16.64MB
b39340afa8af: Loading layer [==================================================>]    132MB/132MB
3c7101960f6a: Loading layer [==================================================>]  3.072kB/3.072kB
1e5ac7e43952: Loading layer [==================================================>]   59.9kB/59.9kB
eb7e74589373: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.14.2
187fdf6ca974: Loading layer [==================================================>]  8.683MB/8.683MB
f0f3837f579c: Loading layer [==================================================>]  4.096kB/4.096kB
3b6dba6beca3: Loading layer [==================================================>]  3.072kB/3.072kB
61bd6049aac2: Loading layer [==================================================>]  18.96MB/18.96MB
1e25fa76b6f6: Loading layer [==================================================>]  19.89MB/19.89MB
Loaded image: goharbor/registry-photon:v2.14.2
167576c0a7bf: Loading layer [==================================================>]  146.6MB/146.6MB
303ab61fea72: Loading layer [==================================================>]  3.584kB/3.584kB
3de7a9d04043: Loading layer [==================================================>]  3.072kB/3.072kB
366215203a54: Loading layer [==================================================>]   2.56kB/2.56kB
9a602f7c615a: Loading layer [==================================================>]  3.072kB/3.072kB
b3927607131a: Loading layer [==================================================>]  3.584kB/3.584kB
6b5cc7407e49: Loading layer [==================================================>]  20.48kB/20.48kB
Loaded image: goharbor/harbor-log:v2.14.2
96362639625d: Loading layer [==================================================>]  11.64MB/11.64MB
33b160e28bf4: Loading layer [==================================================>]  39.87MB/39.87MB
ca6ae9a5eb53: Loading layer [==================================================>]  4.608kB/4.608kB
4c4362dfe634: Loading layer [==================================================>]   40.8MB/40.8MB
Loaded image: goharbor/harbor-exporter:v2.14.2


[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /root/k8s-learn/k8s-harbor/harbor
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
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
copy /data/secret/tls/harbor_internal_ca.crt to shared trust ca dir as name harbor_internal_ca.crt ...
ca file /hostfs/data/secret/tls/harbor_internal_ca.crt is not exist
copy  to shared trust ca dir as name storage_ca_bundle.crt ...
copy None to shared trust ca dir as name redis_tls_ca.crt ...
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir


Note: stopping existing Harbor instance ...


[Step 5]: starting Harbor ...
[+] Running 10/10
 ✔ Network harbor_harbor        Created                                                                                           0.2s 
 ✔ Container harbor-log         Started                                                                                           1.0s 
 ✔ Container harbor-portal      Started                                                                                           3.5s 
 ✔ Container harbor-db          Started                                                                                           3.1s 
 ✔ Container registry           Started                                                                                           3.5s 
 ✔ Container redis              Started                                                                                           3.7s 
 ✔ Container registryctl        Started                                                                                           2.1s 
 ✔ Container harbor-core        Started                                                                                           4.3s 
 ✔ Container nginx              Started                                                                                           5.8s 
 ✔ Container harbor-jobservice  Started                                                                                           5.6s 
✔ ----Harbor has been installed and started successfully.--

3.4 检查是否启动成功

[root@rocky9-3 harbor]# ss -lntp | egrep ':80|:443'
LISTEN 0      4096         0.0.0.0:80         0.0.0.0:*    users:(("docker-proxy",pid=159616,fd=7))
LISTEN 0      4096         0.0.0.0:443        0.0.0.0:*    users:(("docker-proxy",pid=159637,fd=7))
LISTEN 0      4096            [::]:80            [::]:*    users:(("docker-proxy",pid=159626,fd=7))
LISTEN 0      4096            [::]:443           [::]:*    users:(("docker-proxy",pid=159646,fd=7))
[root@rocky9-3 harbor]# curl -kI https://rocky9-3
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 14 Feb 2026 06:32:05 GMT
Content-Type: text/html
Content-Length: 785
Connection: keep-alive
Last-Modified: Mon, 12 Jan 2026 09:08:39 GMT
ETag: "6964ba17-311"
Cache-Control: no-store, no-cache, must-revalidate
Accept-Ranges: bytes
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: DENY
Content-Security-Policy: frame-ancestors 'none'


四 harbor的使用

4.1 登录harbor

在这里插入图片描述
画面还是很好看的
账号:admin
密码就是上面改的Admin@123
在这里插入图片描述

4.2 harbor仓库主页面

在这里插入图片描述

1 新建项目

在这里插入图片描述

2 新建用户

在这里插入图片描述

jekins项目里面添加这个
在这里插入图片描述
给这个用户设置权限
在这里插入图片描述

4.3 主要分成两步

给镜像打标签

docker tag SOURCE_IMAGE[:TAG] rocky9-3/jenkins/REPOSITORY[:TAG]

上传镜像到当前仓库

docker push rocky9-3/jenkins/REPOSITORY[:TAG]
1 登录镜像仓库
root@rocky9-3 rocky9-3]# docker login 192.168.80.173
Username: admin
Password: 

WARNING! Your credentials are stored unencrypted in '/root/.docker/config.json'.
Configure a credential helper to remove this warning. See
https://docs.docker.com/go/credential-store/

Login Succeeded


2 查看镜像列表
[root@rocky9-3 docker]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED       SIZE
goharbor/harbor-exporter                            v2.14.2   26fc5ce17425   4 weeks ago   131MB
goharbor/redis-photon                               v2.14.2   d62cec11627f   4 weeks ago   187MB
goharbor/trivy-adapter-photon                       v2.14.2   6165b96861b7   4 weeks ago   402MB
goharbor/harbor-registryctl                         v2.14.2   1364c6d80c42   4 weeks ago   166MB
goharbor/registry-photon                            v2.14.2   4161f69794cf   4 weeks ago   87.4MB
goharbor/nginx-photon                               v2.14.2   9383173f860e   4 weeks ago   172MB
goharbor/harbor-log                                 v2.14.2   77a92995972a   4 weeks ago   185MB
goharbor/harbor-jobservice                          v2.14.2   5b11a15a5cb0   4 weeks ago   177MB
goharbor/harbor-core                                v2.14.2   604ea0c2c17f   4 weeks ago   203MB
goharbor/harbor-portal                              v2.14.2   b936a8ce0efb   4 weeks ago   181MB
goharbor/harbor-db                                  v2.14.2   d80918ffd062   4 weeks ago   288MB
goharbor/prepare                                    v2.14.2   6337f8dedb39   4 weeks ago   198MB
kubernetesui/dashboard                              v2.7.0    07655ddf2eeb   3 years ago   246MB
swr.cn-north-1.myhuaweicloud.com/iivey/linux-desk   v1.0      0deb15e820c5   5 years ago   1.55GB
[root@rocky9-3 docker]# 

3 修改镜像标签并push
root@rocky9-3 tmp]# docker tag redis:7.2 192.168.80.173/jenkins/redis:7.2
[root@rocky9-3 tmp]# docker push 192.168.80.173/jenkins/redis:7.2
The push refers to repository [192.168.80.173/jenkins/redis]
dc22a8cbb427: Pushed 
5f70bf18a086: Pushed 
c6c5191831f6: Pushed 
6922d1849c17: Pushed 
877b2940eab9: Pushed 
ec89d164289b: Pushed 
4d4d6ca004a4: Pushed 
e48af84b2108: Pushed 
7.2: digest: sha256:fd825e89d050167f15fee7f0a6bb837e016c227da3317ab128971a6b1147fe2f size: 1986

去网站上查看效果
在这里插入图片描述

4.4 如果显示启动不成功

装一个docker-compose来控制harbor

[root@rocky9-3 harbor]# sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 12.1M  100 12.1M    0     0  77405      0  0:02:44  0:02:44 --:--:--  108k
[root@rocky9-3 harbor]# chmod +x /usr/local/bin/docker-compose
[root@rocky9-3 harbor]# docker-compose --version
docker-compose version 1.29.2, build 5becea4c
[root@rocky9-3 harbor]# cd /root/k8s-learn/k8s-harbor/harbor
[root@rocky9-3 harbor]# docker-compose down
Stopping harbor-log ... done
Removing nginx             ... done
Removing harbor-jobservice ... done
Removing harbor-core       ... done
Removing registryctl       ... done
Removing redis             ... done
Removing harbor-portal     ... done
Removing registry          ... done
Removing harbor-db         ... done
Removing harbor-log        ... done
Removing network harbor_harbor
[root@rocky9-3 harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registryctl   ... done
Creating harbor-db     ... done
Creating redis         ... done
Creating harbor-portal ... done
Creating registry      ... done
Creating harbor-core   ... done
Creating harbor-jobservice ... done
Creating nginx             ... done

这有个好处,就是启动非常的快,比方说这个操作步骤

root@rocky9-3 /]# docker ps
CONTAINER ID   IMAGE                                                    COMMAND                   CREATED        STATUS                 PORTS                                                   NAMES
3f83ebf06e2f   goharbor/harbor-log:v2.14.2                              "/bin/sh -c /usr/loc…"   4 hours ago    Up 2 hours (healthy)   127.0.0.1:1514->10514/tcp                               harbor-log
646cbe111dc9   swr.cn-north-1.myhuaweicloud.com/iivey/linux-desk:v1.0   "/start.sh"               4 months ago   Up 2 hours             5900/tcp, 0.0.0.0:6080->6080/tcp, [::]:6080->6080/tcp   linuxdesk
[root@rocky9-3 /]# docker-compose down
ERROR: 
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml, compose.yml, compose.yaml
        
[root@rocky9-3 /]# cd /root/k8s-learn/k8s-harbor/harbor/
[root@rocky9-3 harbor]# docker-compose down
Stopping harbor-log ... done
Removing nginx             ... done
Removing harbor-jobservice ... done
Removing harbor-core       ... done
Removing registry          ... done
Removing harbor-portal     ... done
Removing redis             ... done
Removing harbor-db         ... done
Removing registryctl       ... done
Removing harbor-log        ... done
Removing network harbor_harbor
[root@rocky9-3 harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registryctl   ... done
Creating harbor-portal ... done
Creating harbor-db     ... done
Creating redis         ... done
Creating registry      ... done
Creating harbor-core   ... done
Creating nginx             ... done
Creating harbor-jobservice ... done
[root@rocky9-3 harbor]# docker ps
CONTAINER ID   IMAGE                                                    COMMAND                   CREATED          STATUS                             PORTS                                                                                NAMES
2e5dc7f744c8   goharbor/harbor-jobservice:v2.14.2                       "/harbor/entrypoint.…"   13 seconds ago   Up 10 seconds (health: starting)                                                                                        harbor-jobservice
683e58cd763d   goharbor/nginx-photon:v2.14.2                            "nginx -g 'daemon of…"   13 seconds ago   Up 12 seconds (health: starting)   0.0.0.0:80->8080/tcp, [::]:80->8080/tcp, 0.0.0.0:443->8443/tcp, [::]:443->8443/tcp   nginx
85898bbc7ca7   goharbor/harbor-core:v2.14.2                             "/harbor/entrypoint."   14 seconds ago   Up 13 seconds (health: starting)                                                                                        harbor-core
0011ffd4a47c   goharbor/redis-photon:v2.14.2                            "redis-server /etc/r…"   18 seconds ago   Up 17 seconds (health: starting)                                                                                        redis
3fda8977340a   goharbor/registry-photon:v2.14.2                         "/home/harbor/entryp…"   18 seconds ago   Up 17 seconds (health: starting)                                                                                        registry
30b4aea719e3   goharbor/harbor-db:v2.14.2                               "/docker-entrypoint."   18 seconds ago   Up 17 seconds (health: starting)                                                                                        harbor-db
814b3f039a2e   goharbor/harbor-portal:v2.14.2                           "nginx -g 'daemon of…"   18 seconds ago   Up 17 seconds (health: starting)                                                                                        harbor-portal
f8c8f176afd7   goharbor/harbor-registryctl:v2.14.2                      "/home/harbor/start."   18 seconds ago   Up 17 seconds (health: starting)                                                                                        registryctl
af94934fc3b8   goharbor/harbor-log:v2.14.2                              "/bin/sh -c /usr/loc…"   19 seconds ago   Up 18 seconds (health: starting)   127.0.0.1:1514->10514/tcp                                                            harbor-log
646cbe111dc9   swr.cn-north-1.myhuaweicloud.com/iivey/linux-desk:v1.0   "/start.sh"               4 months ago     Up 2 hours                         5900/tcp, 0.0.0.0:6080->6080/tcp, [::]:6080->6080/tcp                                linuxdesk
[root@rocky9-3 harbor]# 

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐