1 您需要了解

  • 虚拟化平台版本 VMware Workstation 17.5.0 ,本篇使用镜像版本为 CentOS-Stream-8,最小化 minimal 安装
  • Docker CE 版本为 26.1.3,Harbor 版本为 v2.7.1点击这里 GitHub 下载 Harbor,如访问受限,您可通过站内私信进行获取
  • 为有更好的浏览体验,您可以点击文章左上方目录按钮来显示文章整体目录结构
  • 点击获取 Harbor-2.7.1 离线包 | Harbor-2.7.1 离线镜像

2 系统设置

2.1 关闭防火墙及SELinux

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config

2.2 安装 Docker

yum install -y vim net-tools bash-completion yum-utils
bash
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install -y docker-ce

systemctl start docker
systemctl enable docker
docker -v
[Docker version 26.1.3, build b72abbb]

3 Harbor 安装

3.1 传包并解压

[root@docker ~]# tar -zxvf harbor-offline-installer-v2.7.1.tgz
harbor/harbor.v2.7.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl

3.2 配置 Harbor

  • 修改 harbor.yml
cd harbor/
cp harbor.yml.tmpl harbor.yml
vim harbor.yml

#修改主机名为本机IP地址
hostname: 192.168.44.150

#修改端口号为5500,可自定义
# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 5000

#注释 https
# https related config
# https:
  # https port for harbor, default is 443
  # port: 443
  # The path of cert and key files for nginx
  # certificate: /your/certificate/path
  # private_key: /your/private/key/path
  • 修改 docker.service
vim /usr/lib/systemd/system/docker.service

#在 ExecStart 参数后面添加 --insecure-registry=192.168.44.150:5500
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry=192.168.44.150:5500

#重启服务(重要,必须重启)
systemctl daemon-reload 
systemctl restart docker
  • 导入离线镜像
[root@docker ~]# docker load -i harbor-2.7.1.tar
d635f8a69c64: Loading layer [==================================================>]  37.73MB/37.73MB
09859c8fc317: Loading layer [==================================================>]  5.763MB/5.763MB
a2262dec17c9: Loading layer [==================================================>]  91.75MB/91.75MB
1cda8d191cea: Loading layer [==================================================>]  3.072kB/3.072kB
6015205cdf66: Loading layer [==================================================>]  4.096kB/4.096kB
7197ebd96a1d: Loading layer [==================================================>]  92.54MB/92.54MB
Loaded image: goharbor/chartmuseum-photon:v2.7.1
9b681d7437ee: Loading layer [==================================================>]  5.758MB/5.758MB
a83e69e7a5ba: Loading layer [==================================================>]  8.987MB/8.987MB
4976a6e767f1: Loading layer [==================================================>]  14.47MB/14.47MB
480d367aea76: Loading layer [==================================================>]  29.29MB/29.29MB
dee8463c1f24: Loading layer [==================================================>]  22.02kB/22.02kB
54570f91d11d: Loading layer [==================================================>]  14.47MB/14.47MB
Loaded image: goharbor/notary-signer-photon:v2.7.1
e04fe2da5f19: Loading layer [==================================================>]  5.764MB/5.764MB
fc3ccce61cbe: Loading layer [==================================================>]  4.096kB/4.096kB
e1befb3b20d0: Loading layer [==================================================>]  17.41MB/17.41MB
381df6c03446: Loading layer [==================================================>]  3.072kB/3.072kB
b819771c362f: Loading layer [==================================================>]  30.69MB/30.69MB
c508d3c8aeac: Loading layer [==================================================>]  48.89MB/48.89MB
Loaded image: goharbor/harbor-registryctl:v2.7.1
0d6e31ae4572: Loading layer [==================================================>]     99MB/99MB
64ae4b9c8bce: Loading layer [==================================================>]  3.584kB/3.584kB
c6a1a03ae721: Loading layer [==================================================>]  3.072kB/3.072kB
4b8ff43d0c5f: Loading layer [==================================================>]   2.56kB/2.56kB
a4ce38a3c8a8: Loading layer [==================================================>]  3.072kB/3.072kB
759b81f2ba78: Loading layer [==================================================>]  3.584kB/3.584kB
fecfd1ab18de: Loading layer [==================================================>]  20.99kB/20.99kB
Loaded image: goharbor/harbor-log:v2.7.1
cb897960d30f: Loading layer [==================================================>]  8.906MB/8.906MB
fb6f4fd16c90: Loading layer [==================================================>]  3.584kB/3.584kB
173d6ab78d38: Loading layer [==================================================>]   2.56kB/2.56kB
c1fc6a63abb3: Loading layer [==================================================>]  103.2MB/103.2MB
5f7e1bd6f6a5: Loading layer [==================================================>]    104MB/104MB
Loaded image: goharbor/harbor-jobservice:v2.7.1
7a5dc411df76: Loading layer [==================================================>]   91.1MB/91.1MB
ceff2ad73365: Loading layer [==================================================>]  6.145MB/6.145MB
2abd5823ecd7: Loading layer [==================================================>]  1.249MB/1.249MB
e30926f66daa: Loading layer [==================================================>]  1.194MB/1.194MB
Loaded image: goharbor/harbor-portal:v2.7.1
29f59c2a2eb6: Loading layer [==================================================>]  43.64MB/43.64MB
b27d3e5a8df6: Loading layer [==================================================>]  65.83MB/65.83MB
30a3023736ef: Loading layer [==================================================>]  19.19MB/19.19MB
9b3adbbdba09: Loading layer [==================================================>]  65.54kB/65.54kB
31692c2b302f: Loading layer [==================================================>]   2.56kB/2.56kB
c97591717d77: Loading layer [==================================================>]  1.536kB/1.536kB
447e7da95733: Loading layer [==================================================>]  12.29kB/12.29kB
9215e490929e: Loading layer [==================================================>]  2.614MB/2.614MB
f02c03ccd4ea: Loading layer [==================================================>]    407kB/407kB
Loaded image: goharbor/prepare:v2.7.1
856cff93e4d6: Loading layer [==================================================>]  8.906MB/8.906MB
cf9e05a3f1f1: Loading layer [==================================================>]  25.65MB/25.65MB
7bccc4373df9: Loading layer [==================================================>]  4.608kB/4.608kB
b3ca201ee095: Loading layer [==================================================>]  26.44MB/26.44MB
Loaded image: goharbor/harbor-exporter:v2.7.1
c36fbbc4c25b: Loading layer [==================================================>]  91.93MB/91.93MB
c77d114477fc: Loading layer [==================================================>]  3.072kB/3.072kB
b5adfac82a36: Loading layer [==================================================>]   59.9kB/59.9kB
1161cc44e0d4: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.7.1
3a104ad3dfa8: Loading layer [==================================================>]  123.4MB/123.4MB
a582b782d956: Loading layer [==================================================>]  17.67MB/17.67MB
747ad719967e: Loading layer [==================================================>]   5.12kB/5.12kB
347857745db7: Loading layer [==================================================>]  6.144kB/6.144kB
7ffc6a14a878: Loading layer [==================================================>]  3.072kB/3.072kB
40e4f5237627: Loading layer [==================================================>]  2.048kB/2.048kB
115d9d0765bb: Loading layer [==================================================>]   2.56kB/2.56kB
b707c713f224: Loading layer [==================================================>]   2.56kB/2.56kB
60dba025610e: Loading layer [==================================================>]   2.56kB/2.56kB
4ccd0988c811: Loading layer [==================================================>]  9.728kB/9.728kB
Loaded image: goharbor/harbor-db:v2.7.1
ad617d2bc63f: Loading layer [==================================================>]  6.291MB/6.291MB
77e676fefcfc: Loading layer [==================================================>]  4.096kB/4.096kB
2748a8bff421: Loading layer [==================================================>]  3.072kB/3.072kB
e44fb65f4eba: Loading layer [==================================================>]  185.6MB/185.6MB
97cc74bfda1f: Loading layer [==================================================>]  13.73MB/13.73MB
928b80c07fce: Loading layer [==================================================>]  200.1MB/200.1MB
Loaded image: goharbor/trivy-adapter-photon:v2.7.1
1f4c775bffe8: Loading layer [==================================================>]  5.758MB/5.758MB
3284ab8d01eb: Loading layer [==================================================>]  8.987MB/8.987MB
dd8fa1a2b2b0: Loading layer [==================================================>]  15.88MB/15.88MB
8106ce046abf: Loading layer [==================================================>]  29.29MB/29.29MB
1053b310e287: Loading layer [==================================================>]  22.02kB/22.02kB
0aa0bd6cf9e6: Loading layer [==================================================>]  15.88MB/15.88MB
Loaded image: goharbor/notary-server-photon:v2.7.1
4f730363c02d: Loading layer [==================================================>]  5.764MB/5.764MB
23e70dd83173: Loading layer [==================================================>]  4.096kB/4.096kB
a42372d3c73d: Loading layer [==================================================>]  3.072kB/3.072kB
a76104dd55c5: Loading layer [==================================================>]  17.41MB/17.41MB
77cd695198ba: Loading layer [==================================================>]   18.2MB/18.2MB
Loaded image: goharbor/registry-photon:v2.7.1
9023a432c05c: Loading layer [==================================================>]   91.1MB/91.1MB
Loaded image: goharbor/nginx-photon:v2.7.1
1f5497d46044: Loading layer [==================================================>]  8.906MB/8.906MB
af93c68750db: Loading layer [==================================================>]  3.584kB/3.584kB
c5cf9feadf24: Loading layer [==================================================>]   2.56kB/2.56kB
26a09c87d905: Loading layer [==================================================>]  84.83MB/84.83MB
1347fb69ddac: Loading layer [==================================================>]  5.632kB/5.632kB
4b368dfd8acc: Loading layer [==================================================>]    108kB/108kB
6a175467b77e: Loading layer [==================================================>]  44.03kB/44.03kB
62281197b07e: Loading layer [==================================================>]  85.78MB/85.78MB
cdcda83640cc: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.7.1
  • 运行 prepare 脚本准备镜像
[root@docker ~]# cd harbor/
[root@docker harbor]# ./prepare
prepare base dir is set to /root/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
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
  • 修改脚本命令

CentOS 8 / CentOS 9 版本中使用的 docker compose 命令与 CentOS 7 版本命令不同,脚本中默认使用的是 CentOS 7 版本命令 docker-compose,该命令当前操作系统不支持。

#修改 common.sh
[root@docker harbor]# vim common.sh
#原 119 行 elif [[ $(docker-compose --version) =~ (([0-9]+)\.([0-9]+)([\.0-9]*)) ]]
#修改为 elif [[ $(docker compose version) =~ (([0-9]+)\.([0-9]+)([\.0-9]*)) ]]

#修改 install.sh
[root@docker harbor]# vim install.sh
#原 26 行 DOCKER_COMPOSE=docker-compose
#修改为 DOCKER_COMPOSE="docker compose"

3.3 安装 Harbor

[root@docker harbor]# ./install.sh

#日志流片段记录
[+] Running 10/10
 ✔ Network harbor_harbor        Created                                                             0.1s
 ✔ Container harbor-log         Started                                                             0.6s
 ✔ Container registryctl        Started                                                             1.3s
 ✔ Container registry           Started                                                             1.7s
 ✔ Container redis              Started                                                             1.5s
 ✔ Container harbor-portal      Started                                                             1.3s
 ✔ Container harbor-db          Started                                                             1.5s
 ✔ Container harbor-core        Started                                                             2.4s
 ✔ Container harbor-jobservice  Started                                                             3.2s
 ✔ Container nginx              Started                                                             3.3s
✔ ----Harbor has been installed and started successfully.----

3.4 登录 Harbor

默认管理员账号 admin,密码为 Harbor12345

image.png

image.png

4 测试

4.1 创建项目

访问级别设置为 公开,可以进行匿名拉取,存储容量默认 -1 表示大小没有限制

image.png

4.2 客户端登录

[root@knode2 ~]# docker login 192.168.44.150:5500
Username: admin
Password:
Error response from daemon: Get "https://192.168.44.150:5500/v2/": http: server gave HTTP response to HTTPS client

#报错解决方案:修改客户端/etc/docker/daemon.json,增加 insecure-registries 内容
{
  "registry-mirrors": ["https://cc2d8woc.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.44.150:5500"]
}

[root@knode2 ~]# systemctl daemon-reload
[root@knode2 ~]# systemctl restart docker.service

[root@knode2 ~]# docker login 192.168.44.150:5500
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

4.3 客户端推送镜像

[root@knode2 ~]# docker tag swr.cn-north-4.myhuaweicloud.com/cloudcs/mysql:888 192.168.44.150:5500/20240818/mysql:latest
[root@knode2 ~]# docker push 192.168.44.150:5500/20240818/mysql:latest
The push refers to repository [192.168.44.150:5500/20240818/mysql]
d67a9f3f6569: Pushed
fc8a043a3c75: Pushed
118fee5d988a: Pushed
c654c2afcbba: Pushed
1d1f48e448f9: Pushed
aad27784b762: Pushed
0d17fee8db40: Pushed
d7a777f6c3a4: Pushed
a0c2a050fee2: Pushed
0798f2528e83: Pushed
fba7b131c5c3: Pushed
ad6b69b54919: Pushed
latest: digest: sha256:238cf050a7270dd6940602e70f1e5a11eeaf4e02035f445b7f613ff5e0641f7d size: 2828

image.png


  • END