Harbor私有仓库搭建

一、docker环境安装

yum install docker-ce -y

二、离线安装harbor(主节点)

2.1、安装先决条件

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.2、下载harbor离线包

考虑到充分的灵活性,本次选择离线包安装。

#1、官方参考文档
https://gitee.com/project_harbor/harbor?utm_source=alading&utm_campaign=repo

#2、下载harbor离线包
wget https://github.com/goharbor/harbor/releases/download/v2.9.2/harbor-offline-installer-v2.9.2.tgz

#3、解压缩离线包
tar -xvf harbor-offline-installer-v2.9.2.tar 

#4、Optionally download the corresponding *.asc file to verify that the package is genuine
gpg --keyserver hkps://keyserver.ubuntu.com --receive-keys 644FF454C0B4115C
gpg -v --keyserver hkps://keyserver.ubuntu.com --verify harbor-offline-installer-version.tgz.asc

2.3、配置https

#1、Generate a CA certificate private key.
openssl genrsa -out ca.key 4096

#2、Generate the CA certificate.
openssl req -x509 -new -nodes -sha512 -days 3650 \
 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yuhaozhi.com" \
 -key ca.key \
 -out ca.crt
 
#3、Generate a Server Certificate
#Generate a private key.
openssl genrsa -out yuhaozhi.com.key 4096

#Generate a certificate signing request (CSR).
openssl req -sha512 -new \
    -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yuhaozhi.com" \
    -key yuhaozhi.com.key \
    -out yuhaozhi.com.csr


#4、Generate an x509 v3 extension file.
cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=yuhaozhi.com
DNS.2=yuhaozhi
DNS.3=hostname
DNS.4=192.168.1.230
DNS.5=192.168.1.231
DNS.6=192.168.1.250
DNS.7=harbor.yuhaozhi.com
EOF


#5、Use the v3.ext file to generate a certificate for your Harbor host.
openssl x509 -req -sha512 -days 3650 \
    -extfile v3.ext \
    -CA ca.crt -CAkey ca.key -CAcreateserial \
    -in yuhaozhi.com.csr \
    -out yuhaozhi.com.crt

#6、Provide the Certificates to Harbor and Docker
#Copy the server certificate and key into the certficates folder on your Harbor host.
mkdir -p /data/cert/
cp yuhaozhi.com.crt /data/cert/
cp yuhaozhi.com.key /data/cert/

#Convert yourdomain.com.crt to yourdomain.com.cert, for use by Docker.
openssl x509 -inform PEM -in yuhaozhi.com.crt -out yuhaozhi.com.cert

#Copy the server certificate, key and CA files into the Docker certificates folder on the Harbor host. You must create the appropriate folders first.
mkdir -p /etc/docker/certs.d/yuhaozhi.com/
cp yuhaozhi.com.cert /etc/docker/certs.d/yuhaozhi.com/
cp yuhaozhi.com.key /etc/docker/certs.d/yuhaozhi.com/
cp ca.crt /etc/docker/certs.d/yuhaozhi.com/

#7、Restart Docker Engine.
systemctl restart docker

2.4、修改harbor.yml文件

#1、进入harbor离线包,复制harbor.yml.tmpl并命名为harbor.yml
#2、修改harbor.yml
hostname: 192.168.1.230
certificate: /data/cert/yuhaozhi.com.crt
private_key: /data/cert/yuhaozhi.com.key

2.5、安装

./install.sh
#输出如下
[root@lvs1 harbor]# ./install.sh 

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

Note: docker version: 25.0.3

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

Note: Docker Compose version v2.24.6

[Step 2]: loading Harbor images ...
0c24b8a9f174: Loading layer [==================================================>]  125.3MB/125.3MB
41f72377740a: Loading layer [==================================================>]  3.584kB/3.584kB
72e27f385ff0: Loading layer [==================================================>]  3.072kB/3.072kB
be826955adcb: Loading layer [==================================================>]   2.56kB/2.56kB
49cbeea0eb7e: Loading layer [==================================================>]  3.072kB/3.072kB
d196717f1202: Loading layer [==================================================>]  3.584kB/3.584kB
f51e7eb3ca9e: Loading layer [==================================================>]  20.48kB/20.48kB
Loaded image: goharbor/harbor-log:v2.9.2
40da7daf514d: Loading layer [==================================================>]     16MB/16MB
11a88f6050ab: Loading layer [==================================================>]  173.8MB/173.8MB
7fe17312fa57: Loading layer [==================================================>]  25.47MB/25.47MB
4d2876688e56: Loading layer [==================================================>]   18.2MB/18.2MB
6a6ca8a6ef4f: Loading layer [==================================================>]   5.12kB/5.12kB
2bfa7846e820: Loading layer [==================================================>]  6.144kB/6.144kB
3d2a0828852a: Loading layer [==================================================>]  3.072kB/3.072kB
fe85bfcde808: Loading layer [==================================================>]  2.048kB/2.048kB
4f8603d05e2d: Loading layer [==================================================>]   2.56kB/2.56kB
49398ca402ac: Loading layer [==================================================>]   7.68kB/7.68kB
Loaded image: goharbor/harbor-db:v2.9.2
127b0531272e: Loading layer [==================================================>]   8.57MB/8.57MB
6ce15517300e: Loading layer [==================================================>]  4.096kB/4.096kB
80f53fae1377: Loading layer [==================================================>]   17.4MB/17.4MB
4d4f26993587: Loading layer [==================================================>]  3.072kB/3.072kB
d33c4d5ccb71: Loading layer [==================================================>]  32.78MB/32.78MB
b9d780a3dc06: Loading layer [==================================================>]  50.97MB/50.97MB
Loaded image: goharbor/harbor-registryctl:v2.9.2
e254d8b97486: Loading layer [==================================================>]  115.6MB/115.6MB
Loaded image: goharbor/nginx-photon:v2.9.2
3fcfba466046: Loading layer [==================================================>]     16MB/16MB
a580266af25f: Loading layer [==================================================>]  110.6MB/110.6MB
f7f1d496f837: Loading layer [==================================================>]  3.072kB/3.072kB
d25c35042c59: Loading layer [==================================================>]   59.9kB/59.9kB
e49c186653b7: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.9.2
f858b7c7c4e1: Loading layer [==================================================>]   8.57MB/8.57MB
50a701ca846f: Loading layer [==================================================>]  4.096kB/4.096kB
e1b540d7b288: Loading layer [==================================================>]  3.072kB/3.072kB
0a49e7d3d12e: Loading layer [==================================================>]   17.4MB/17.4MB
5e291d456605: Loading layer [==================================================>]  18.19MB/18.19MB
Loaded image: goharbor/registry-photon:v2.9.2
9783c6f4e4d5: Loading layer [==================================================>]  9.089MB/9.089MB
6fe2864ec24e: Loading layer [==================================================>]  4.096kB/4.096kB
71a4b4cfb19a: Loading layer [==================================================>]  3.072kB/3.072kB
a133880768e1: Loading layer [==================================================>]  213.9MB/213.9MB
0dafcfde44bd: Loading layer [==================================================>]  17.37MB/17.37MB
d83f6b9f36cc: Loading layer [==================================================>]  232.1MB/232.1MB
Loaded image: goharbor/trivy-adapter-photon:v2.9.2
Loaded image: goharbor/prepare:v2.9.2
b1146ac47e49: Loading layer [==================================================>]  115.6MB/115.6MB
e2023d8c51de: Loading layer [==================================================>]   6.46MB/6.46MB
4a841311b599: Loading layer [==================================================>]  245.8kB/245.8kB
ed8a3388a990: Loading layer [==================================================>]  1.233MB/1.233MB
Loaded image: goharbor/harbor-portal:v2.9.2
edfb22fc6c66: Loading layer [==================================================>]  11.59MB/11.59MB
6fa5f1f326e0: Loading layer [==================================================>]  3.584kB/3.584kB
d6e19e0d42db: Loading layer [==================================================>]   2.56kB/2.56kB
89701473a9c4: Loading layer [==================================================>]  58.23MB/58.23MB
26e39d41755d: Loading layer [==================================================>]  5.632kB/5.632kB
179d6ec199b9: Loading layer [==================================================>]  122.4kB/122.4kB
22d269e7a077: Loading layer [==================================================>]  80.38kB/80.38kB
8b9d83795390: Loading layer [==================================================>]  59.23MB/59.23MB
da5a56c39c04: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.9.2
39f1a92272e6: Loading layer [==================================================>]  11.59MB/11.59MB
ae7f7a58aeca: Loading layer [==================================================>]  3.584kB/3.584kB
50d9cb47a7f8: Loading layer [==================================================>]   2.56kB/2.56kB
ebc3f21a90ec: Loading layer [==================================================>]  44.69MB/44.69MB
00961384c8a5: Loading layer [==================================================>]  45.48MB/45.48MB
Loaded image: goharbor/harbor-jobservice:v2.9.2
2bfb331e5709: Loading layer [==================================================>]  11.59MB/11.59MB
528004941363: Loading layer [==================================================>]  27.62MB/27.62MB
c8dfa643c6d1: Loading layer [==================================================>]  4.608kB/4.608kB
6de2b2fb651e: Loading layer [==================================================>]  28.41MB/28.41MB
Loaded image: goharbor/harbor-exporter:v2.9.2


[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /root/k8s/harbor/harbor
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/jobservice/config.yml
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/nginx/nginx.conf
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
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 9/10
 ⠙ Network harbor_harbor        Created                                                                                                                                                                                                                    2.1s 
 ✔ Container harbor-log         Started                                                                                                                                                                                                                    0.4s 
 ✔ Container registry           Started                                                                                                                                                                                                                    1.2s 
 ✔ Container redis              Started                                                                                                                                                                                                                    1.0s 
 ✔ Container harbor-db          Started                                                                                                                                                                                                                    1.1s 
 ✔ Container harbor-portal      Started                                                                                                                                                                                                                    1.2s 
 ✔ Container registryctl        Started                                                                                                                                                                                                                    1.1s 
 ✔ Container harbor-core        Started                                                                                                                                                                                                                    1.5s 
 ✔ Container harbor-jobservice  Started                                                                                                                                                                                                                    2.0s 
 ✔ Container nginx              Started                                                                                                                                                                                                                    1.9s 
✔ ----Harbor has been installed and started successfully.----

2.6、验证

注意:本机测试暂时未配置dns,因此可在本地配置静态hosts记录如下
192.168.1.250 harbor.yuhaozhi.com

并在浏览器输入:
https://harbor.yuhaozhi.com

用户密码配置在2.4 harbor.yml文件中(用户名:admin):
harbor_admin_password: Harbor12345

2.7、如需配置主从harbor节点则继续跳转至下一章节

三、离线安装harbor(从节点)

3.1-3.5章节参考主节点2.1-2.5安装步骤

3.4、修改harbor.yml

#1、进入harbor离线包,复制harbor.yml.tmpl并命名为harbor.yml
#2、修改harbor.yml
hostname: 192.168.1.231
certificate: /data/cert/yuhaozhi.com.crt
private_key: /data/cert/yuhaozhi.com.key

3.6、docker-compose安装

#官网下载地址
wget https://github.com/docker/compose/releases/download/v2.24.6/docker-compose-linux-x86_64
cp docker-compose-linux-x86_64 /usr/local/bin/docker-compose
 chmod 755 /usr/local/bin/docker-compose 

3.7、主备复杂配置

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3.8、验证

往主库推送镜像:
在这里插入图片描述

#主动触发同步任务
在这里插入图片描述

#从库状态
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 您可以通过以下步骤来搭建Harbor私有仓库: 1. 安装DockerDocker-compose 2. 下载Harbor镜像并启动容器 3. 访问Harbor Web界面并进行初始化设置 4. 创建用户帐户并登录 5. 推送和下载镜像 请注意,Harbor的安装和配置可能需要一些技术知识,并且应根据您的系统环境进行适当的调整。有关更详细的信息,请参阅Harbor官方文档。 ### 回答2: Docker是一项非常受欢迎的容器化技术,它使得应用开发和部署非常方便,而Harbor是一款优秀的开源Docker私有仓库软件,它提供了安全、可靠、灵活的私有容器仓库解决方案,是非常适合企业内部使用的仓库软件。 搭建Harbor私有仓库的过程可以分为以下几个步骤: 1. 安装Docker:在安装Harbor之前,你需要先安装好Docker,确保Docker已经正确安装、运行,并且网络已经配置好。 2. 下载并解压Harbor安装包:从Harbor的官方网站(https://goharbor.io/)下载Harbor的安装包,然后解压到指定目录中。 3. 配置Harbor:在解压后的目录中,找到harbor.cfg文件,按照需求修改该文件中的配置选项,例如端口、数据存储目录、认证方式、管理员密码等。 4. 启动Harbor:运行docker-compose up -d命令即可启动Harbor私有仓库,启动后可以使用docker ps命令查看状态。 5. 配置Docker客户端:在启动Harbor后,你需要配置Docker客户端的认证信息,才能访问Harbor仓库。在Docker客户端中使用docker login命令,输入用户名、密码和仓库地址即可。 6. 使用Harbor:在配置完成后,你可以使用docker命令或者Harbor的Web UI界面来管理和使用你的私有仓库了。 总之,在使用Harbor搭建私有仓库时,需要先安装好Docker,并在运行Harbor之前进行配置,配置好认证信息,才能正常访问私有仓库Harbor还提供了丰富的权限管理、镜像管理、日志管理等功能,非常适合用于企业内部应用的私有容器仓库解决方案。 ### 回答3: Docker是一种轻便的容器技术,Harbor是一种用于Docker注册表和管理系统的私有仓库Harbor私有仓库可以极大地方便企业级应用程序的构建、部署和管理,特别适用于A DevOps和微服务架构。要搭建Harbor私有仓库,步骤如下: 第一步,安装DockerDocker Compose。在安装完Docker后,可以使用以下命令来安装Docker Compose: curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose 第二步,下载并安装Harbor私有仓库。从Harbor的官方网站上下载和安装最新版本的Harbor软件包: wget https://api.github.com/repos/goharbor/harbor/releases/latest -O harbor.json RELEASE_VERSION=$(cat harbor.json|jq ".name"|sed 's/"//g') echo "Harbor Version: ${RELEASE_VERSION}" wget https://github.com/goharbor/harbor/releases/download/${RELEASE_VERSION}/harbor-online-installer-${RELEASE_VERSION}.tgz tar zxvf harbor-online-installer-${RELEASE_VERSION}.tgz -C /opt 第三步,创建并编辑Harbor配置文件。在Harbor的安装目录下,创建一个名为harbor.cfg的配置文件: cd /opt/harbor cp harbor.cfg.tmpl harbor.cfg vi harbor.cfg 在配置文件中,指定Harbor的主机名、端口和数据存储路径等细节。你可以调整这些设置来适应你的特定需求。 第四步,启动Harbor容器。使用Docker Compose和Harbor配置文件来创建Harbor的运行环境: docker-compose up -d 第五步,使用浏览器访问Harbor私有仓库。在浏览器中访问http://localhost:8888,你会看到Harbor的登录页面。输入管理员账户和密码,即可进入Harbor管理界面。 第六步,使用Harbor私有仓库。使用Docker Registry API或Docker客户端命令行工具,与你的Harbor私有仓库进行交互。将部署在Harbor私有仓库中的镜像下载并使用在你的应用程序中。 总之,搭建Harbor私有仓库非常不错,它提供了一个安全、集中和可扩展的Docker仓库,并支持自动构建和镜像扫描等高级功能。随着DevOps和微服务的兴起,Harbor私有仓库将成为企业应用的关键组成部分,也值得我们深入探索和研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值