使用 Docker 搭建企业级私有仓库HARBOR

news2024/9/23 5:21:32

目录

1 HARBOR 的获取

1.1 下载软件包地址

1.2 HARBOR 的介绍

2 部署harbor

2.1 仓库端操作

2.1.1 修改harbor配置文件

2.1.2 生成服务端的证书与秘钥

2.1.3 管理HARBOR

2.1.4 查看是否运行

2.2 客户端操作

2.2.1 证书拷贝给客户端

 2.2.2 环境配置

2.2.3 批量读取本地镜像

2.2.4 批量打标签

2.2.5 批量上传打过标签的镜像

2.2.6 删除打过标签的镜像

3 编写自动化上传脚本


1 HARBOR 的获取

1.1 下载软件包地址

Releases · goharbor/harbor (github.com)icon-default.png?t=N7T8https://github.com/goharbor/harbor/releases

1.2 HARBOR 的介绍


Harbor 是由vmware公司开源的企业级 Docker Registry 项目。

它提供了以下主要功能和特点:

1. 基于角色的访问控制(RBAC):可以为不同的用户和用户组分配不同的权限,增强了安全性和管理的灵活性。

2. 镜像复制:支持在不同的 Harbor 实例之间复制镜像,方便在多个数据中心或环境中分发镜像。

3. 图形化用户界面(UI):提供了直观的 Web 界面,便于管理镜像仓库、项目、用户等。

4. 审计日志:记录了对镜像仓库的各种操作,有助于追踪和审查活动。

5. 垃圾回收:可以清理不再使用的镜像,节省存储空间。

2 部署harbor

2.1 仓库端操作

2.1.1 修改harbor配置文件

[root@complete ~]# tar xzf harbor-offline-installer-v2.11.1.tgz 
[root@complete ~]# ls
公共  视频  文档  音乐  anaconda-ks.cfg        certs   harbor-offline-installer-v2.11.1.tgz
模板  图片  下载  桌面  busybox-latest.tar.gz  harbor  script

[root@complete ~]# cd harbor/
[root@complete harbor]# cp harbor.yml.tmpl harbor.yml

# 打开yml管理文件修改以下参数
[root@complete harbor]# vim harbor.yml

harbor_admin_password: 123456        # 设置管理员密码
hostname: reg.shuyan.com             # 设置本机主机名
  certificate: /data/certs/shuyan.crt    # 证书地址
  private_key: /data/certs/shuyan.key    # 私钥地址

2.1.2 生成服务端的证书与秘钥

[root@complete harbor]# mkdir /data/certs -p
[root@complete ~]# openssl req -newkey rsa:4096 \
-nodes -sha256 -keyout /data/certs/shuyan.key \
-addext "subjectAltName = DNS:reg.shuyan.com" \
-x509 -days 365 -out /data/certs/shuyan.crt
.......+.........+.........+..+.+.....+....+.....+.........+.......+..+...+....+.....+....+.....+....+......+..+...+.+...+..+.+..+......+......+...+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+.....+.......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+..+.......+........+......+..........+..+.........+..........+..................+......+..+...+.........+......+.......+..+.......+......+.....+....+.....+.+............+......+..............+......+............+.......+.....+.......+.....+..........+...........+.........................+............+..+...+...+.............+....................+.+..............+....+........+...+.+...+........+...+...................+.....+.......+..................+..+...............+.+.........+.....+......+...+..........+............+.....+.........+...+...............+.+.........+.......................+...+.......+.........+......+.....+...+....+........+.........+...+......................+......+.......................+.........+......+.......+.....+.......+..+.+..................+.................+...+.+.....................+..+.+.....+......+...+............+.+...+...........+.+..+.+...............+.....+..........+......+...+......+.....+.+...........+..........+..+...+...+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.......+...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+++++++++++++++++++++++++++++++++++++++++++...+......+...............+.+...............+..............+.+.....+......+...............+.............+.........+........+.....+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:guangxi
Locality Name (eg, city) [Default City]:wu'zhou
Organization Name (eg, company) [Default Company Ltd]:docker
Organizational Unit Name (eg, section) []:shuyan
Common Name (eg, your name or your server's hostname) []:reg.shuyan.com
Email Address []:admin@shuayn.com

2.1.3 管理HARBOR

管理harbor的容器:

[root@rockynode-1 harbor]# docker compose stop

[root@rockynode-1 harbor]# docker compose up -d

2.1.4 查看是否运行

[root@complete harbor]# docker compose -f /root/harbor/docker-compose.yml ps 
WARN[0000] /root/harbor/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
NAME                IMAGE                                 COMMAND                   SERVICE       CREATED       STATUS                 PORTS
harbor-core         goharbor/harbor-core:v2.11.1          "/harbor/entrypoint.…"   core          4 hours ago   Up 4 hours (healthy)   
harbor-db           goharbor/harbor-db:v2.11.1            "/docker-entrypoint.…"   postgresql    4 hours ago   Up 4 hours (healthy)   
harbor-jobservice   goharbor/harbor-jobservice:v2.11.1    "/harbor/entrypoint.…"   jobservice    4 hours ago   Up 4 hours (healthy)   
harbor-log          goharbor/harbor-log:v2.11.1           "/bin/sh -c /usr/loc…"   log           4 hours ago   Up 4 hours (healthy)   127.0.0.1:1514->10514/tcp
harbor-portal       goharbor/harbor-portal:v2.11.1        "nginx -g 'daemon of…"   portal        4 hours ago   Up 4 hours (healthy)   
nginx               goharbor/nginx-photon:v2.11.1         "nginx -g 'daemon of…"   proxy         4 hours ago   Up 4 hours (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp
redis               goharbor/redis-photon:v2.11.1         "redis-server /etc/r…"   redis         4 hours ago   Up 4 hours (healthy)   
registry            goharbor/registry-photon:v2.11.1      "/home/harbor/entryp…"   registry      4 hours ago   Up 4 hours (healthy)   
registryctl         goharbor/harbor-registryctl:v2.11.1   "/home/harbor/start.…"   registryctl   4 hours ago   Up 4 hours (healthy)   

 

其中library为默认的仓库,在里面的镜像不需要指定仓库名拉取镜像

2.2 客户端操作

2.2.1 证书拷贝给客户端

[root@complete harbor]# scp /data/certs/shuyan.crt root@192.168.239.10:~

 2.2.2 环境配置

# 删除原有的镜像
[root@rockynode-1 ~]# docker rmi `docker images | awk 'BEGIN{FS=" "} {if(NR>1)print $3}'`


[root@rockynode-1 ~]# mkdir -p /etc/docker/certs.d/reg.shuyan.com/
[root@rockynode-1 ~]# cp shuyan.crt /etc/docker/certs.d/reg.shuyan.com/

[root@rockynode-1 ~]# systemctl restart docker

# 增加客户端的域名解析
[root@rockynode-1 ~]# vim /etc/hosts 
192.168.239.20  reg.shuyan.com

2.2.3 批量读取本地镜像

# 批量读取镜像

[root@rockynode-1 docker-page]# ls
busybox-latest.tar.gz  game2048.tar.gz                      mario.tar.gz       nginx-latest.tar.gz       ubuntu-latest.tar.gz
centos-7.tar.gz        haproxy-2.3.tar.gz                   mysql-5.7.tar.gz   phpmyadmin-latest.tar.gz
debian11.tar.gz        harbor-offline-installer-v2.5.4.tgz  nginx-1.23.tar.gz  registry.tag.gz

[root@rockynode-1 docker-page]# for i in `ls`;do docker load -i $i;done

[root@rockynode-1 docker-page]# docker images 
REPOSITORY                        TAG       IMAGE ID       CREATED         SIZE
nginx                             latest    5ef79149e0ec   2 weeks ago     188MB
phpmyadmin                        latest    2b39e17532a1   2 weeks ago     562MB
ubuntu                            latest    edbfe74c41f8   4 weeks ago     78.1MB
mysql                             5.7       5107333e08a8   8 months ago    501MB
registry                          latest    cfb4d9904335   11 months ago   25.4MB
nginx                             1.23      a7be6198544f   15 months ago   142MB
busybox                           latest    65ad0d468eb1   15 months ago   4.26MB
haproxy                           2.3       7ecd3fda00f4   2 years ago     99.4MB
centos                            7         eeb6ee3f44bd   2 years ago     204MB
timinglee/game2048                latest    19299002fdbe   7 years ago     55.5MB
timinglee/mario                   latest    9a35a9e43e8c   9 years ago     198MB
gcr.io/distroless/base-debian11   latest    2a6de77407bf   N/A             20.6MB

2.2.4 批量打标签

[root@rockynode-1 ~]# docker images | awk '{if(NR>1) system("docker tag "$1":"$2" reg.shuyan.com/library/"$1":"$2"")}'

# 查看所有镜像
[root@rockynode-1 ~]# docker images 
REPOSITORY                                               TAG       IMAGE ID       CREATED         SIZE
nginx                                                    latest    5ef79149e0ec   2 weeks ago     188MB
reg.shuyan.com/library/nginx                             latest    5ef79149e0ec   2 weeks ago     188MB
phpmyadmin                                               latest    2b39e17532a1   2 weeks ago     562MB
reg.shuyan.com/library/phpmyadmin                        latest    2b39e17532a1   2 weeks ago     562MB
ubuntu                                                   latest    edbfe74c41f8   4 weeks ago     78.1MB
reg.shuyan.com/library/ubuntu                            latest    edbfe74c41f8   4 weeks ago     78.1MB
mysql                                                    5.7       5107333e08a8   8 months ago    501MB
reg.shuyan.com/library/mysql                             5.7       5107333e08a8   8 months ago    501MB
registry                                                 latest    cfb4d9904335   11 months ago   25.4MB
reg.shuyan.com/library/registry                          latest    cfb4d9904335   11 months ago   25.4MB
nginx                                                    1.23      a7be6198544f   15 months ago   142MB
reg.shuyan.com/library/nginx                             1.23      a7be6198544f   15 months ago   142MB
busybox                                                  latest    65ad0d468eb1   15 months ago   4.26MB
reg.shuyan.com/library/busybox                           latest    65ad0d468eb1   15 months ago   4.26MB
haproxy                                                  2.3       7ecd3fda00f4   2 years ago     99.4MB
reg.shuyan.com/library/haproxy                           2.3       7ecd3fda00f4   2 years ago     99.4MB
centos                                                   7         eeb6ee3f44bd   2 years ago     204MB
reg.shuyan.com/library/centos                            7         eeb6ee3f44bd   2 years ago     204MB
timinglee/game2048                                       latest    19299002fdbe   7 years ago     55.5MB
reg.shuyan.com/library/timinglee/game2048                latest    19299002fdbe   7 years ago     55.5MB
timinglee/mario                                          latest    9a35a9e43e8c   9 years ago     198MB
reg.shuyan.com/library/timinglee/mario                   latest    9a35a9e43e8c   9 years ago     198MB
gcr.io/distroless/base-debian11                          latest    2a6de77407bf   N/A             20.6MB
reg.shuyan.com/library/gcr.io/distroless/base-debian11   latest    2a6de77407bf   N/A             20.6MB

# 查看打过标签的镜像
[root@rockynode-1 ~]# docker images | awk '/reg.shuyan.com/{print $1":"$2}'
reg.shuyan.com/library/nginx:latest
reg.shuyan.com/library/phpmyadmin:latest
reg.shuyan.com/library/ubuntu:latest
reg.shuyan.com/library/mysql:5.7
reg.shuyan.com/library/registry:latest
reg.shuyan.com/library/nginx:1.23
reg.shuyan.com/library/busybox:latest
reg.shuyan.com/library/haproxy:2.3
reg.shuyan.com/library/centos:7
reg.shuyan.com/library/timinglee/game2048:latest
reg.shuyan.com/library/timinglee/mario:latest
reg.shuyan.com/library/gcr.io/distroless/base-debian11:latest

2.2.5 批量上传打过标签的镜像

# 将标签赋值给变量
 ~]# reg_shuyan=$(docker images | awk  -v store="$store" \
> -v ip="$hub_ip" '$1 ~ ip "/"store"/" {print $1":"$2}')

# 遍历变量批量上传
 ~]# for i in $reg_shuyan
> do
>     docker push $i
> done

2.2.6 删除打过标签的镜像

~]# docker images | awk '$1 ~ /reg\.shuyan\.com/ {print $1":"$2}'

3 编写自动化上传脚本

# 演示
[root@rockynode-1 ~]# reg_shuyan=$(docker images | awk '/reg.shuyan.com/{print $1":"$2}')
[root@rockynode-1 ~]# echo -e "$reg_shuyan"
reg.shuyan.com/library/nginx:latest
reg.shuyan.com/library/phpmyadmin:latest
reg.shuyan.com/library/ubuntu:latest
reg.shuyan.com/library/mysql:5.7
reg.shuyan.com/library/registry:latest
reg.shuyan.com/library/nginx:1.23
reg.shuyan.com/library/busybox:latest
reg.shuyan.com/library/haproxy:2.3
reg.shuyan.com/library/centos:7
reg.shuyan.com/library/timinglee/game2048:latest
reg.shuyan.com/library/timinglee/mario:latest
reg.shuyan.com/library/gcr.io/distroless/base-debian11:latest



[root@rockynode-1 script]# vim hub.sh

#!/bin/bash

hub_ip=reg.shuyan.com
store=shuyan
docker images | awk -v ip="$hub_ip" -v store="$store" 'NR > 1 {
    system("docker tag " $1 ":" $2 " " ip "/"store"/" $1 ":" $2)
}'

reg_shuyan=$(docker images | awk  -v store="$store" -v ip="$hub_ip" '$1 ~ ip "/"store"/" {print $1":"$2}')

for i in $reg_shuyan; do
    docker push $i
done

docker rmi $(docker images | awk -v ip="$hub_ip" -v store="$store" '$1 ~ ip "/"store"/" {print $1":"$2}')

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2095914.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Transformer面试真题详解——覆盖99%的Transformer面试问题(建议收藏)

文章目录 1. 请简述一下Transformer的基本结构和原理2. Transformer为什么使用多头注意力机制3. Transformer计算attention为什么选择点乘而不是加法?两个计算复杂度和效果上有什么区别?4. 为什么在softmax之后要对attention进行scaled(为什么…

dubbo之时间轮算法分析

文章目录 前言一、参数说明二、具体实现1、HashedWheelTimer2、createWheel3、newTimeout4、start5、run6、waitForNextTick7、transferTimeoutsToBuckets8、expireTimeouts 总结 前言 时间轮(TimingWheel)是一种高效利用线程资源进行批量化调度的算法&…

ffmpeg音频编码

音视频播放的流程 根据我之前的文章 我们已经从解复用,解码得到原始数据,现在我们逆向,将frame转化packet。也就是原始数据转化为压缩后的数据文件。 介绍 PCM样本格式 PCM(Pulse Code Modulation,脉冲编码调制)⾳频数据是未经…

离散数学------关系理论

一、序偶和笛卡尔积 序偶 两个序偶如果相等,那么他们相对应的第一第二元素分别相等 笛卡尔积 笛卡尔积是集合之间的一种运算,运算的结果是个序偶,第一元素来自前面的集合,第二元素来自后面的集合。 两集合进行笛卡尔积运算后集合…

UE5学习笔记20-给游戏添加声音

一、准备音频资源 1.Jump文件夹中有跳跃的音频资源wav文件夹中是SoundCue的音波资源 2.音乐衰减文件,右键->音频->音效衰减 二、 在对应的动画资源处将音频添加 1.找到对应的动画帧 2.在对应的行右键添加通知->播放音效 3、选中添加的音效选择对应的音频资…

拦截通信助理,拦截小秘书技术

有人叫做空号识别,有人称为彩铃识别,磐石云通过嵌入软交换进行实时识别前期媒体 案例: 王总公司有20坐席的员工回访用户服务满意度业务,由于用户开通了语音秘书和通信助理,漏话提醒等等,坐席拨打时对方由…

【HTML】开源模拟输入框动画

代码地址: https://uiverse.io/eslam-hany/strange-goose-48代码地址: https://uiverse.io/vnuny/moody-swan-60代码地址: https://uiverse.io/boryanakrasteva/hard-pig-16代码地址: https://uiverse.io/Harsha2lucky/lovely…

TCP和UDP的主要区别以及应用场景

目录 1.主要区别 2.应用场景 1.主要区别 TCP(Transmission Control Protocol):有连接,可靠传输,面向字节流,全双工通讯; UDP(User Datagram Protocol):无连…

树莓派的启动

我的板子是树莓派3B。 [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 6.6.31rpt-rpi-v7 (sergeraspberrypi.com) (gcc-12 (Raspbian 12.2.0-14rpi1) 12.2.0, GNU ld (GNU Binutils for Raspbian) 2.40) #1 SMP Raspbian 1:6.6.31-1rpt1 (202…

【C++ Primer Plus习题】8.6

问题: 解答: #include <iostream> using namespace std;template <typename T> T maxn(T arr[], int len)//通用 {T max 0;for (int i 0; i < len; i){if (max < arr[i]){max arr[i];}}return max; }template<> const char* maxn<const char*&g…

SpringBoot+Vue实现大文件上传(断点续传-后端控制(一))

SpringBootVue实现大文件上传&#xff08;断点续传&#xff09; 1 环境 SpringBoot 3.2.1&#xff0c;Vue 2&#xff0c;ElementUI&#xff0c;spark-md5 2 问题 在前一篇文章&#xff0c;我们写了通过在前端控制的断点续传&#xff0c;但是有两个问题&#xff0c;第一个问题&…

怎么在Windows操作系统部署阿里开源版通义千问(Qwen2)

怎么在Windows操作系统部署阿里开源版通义千问&#xff08;Qwen2&#xff09; | 原创作者/编辑&#xff1a;凯哥Java | 分类&#xff1a;人工智能学习系列教程 添加图片注释&#xff0c;不超过 140 字&#xff08;可选&#xff09; GitHub上qwen2截图 随着人工智能技术的不断…

【华为】轻松get!eNSP登录无线AC Web界面的新姿势

【华为】轻松get&#xff01;eNSP登录无线AC Web界面的新姿势 无线AC&#xff1a;web界面实验准备华为云配置01 拉取设备02添加UDP端口03再添加VMnet1(VMnet8 也行)网段连接AC的端口04最后设置端口映射 无线AC配置01拉取AC设备和连接华为云02配置AC的g0/0/1端口&#xff08;SVI…

AI时代,需要什么样的服务器操作系统?

文&#xff5c;刘俊宏 编&#xff5c;王一粟 AI时代&#xff0c;中国的服务器系统正在面临一场双重挑战。 今年6月底&#xff0c;最主流的开源服务器操作系统CentOS正式停服&#xff0c;找一个合适的操作系统进行迁移成为了必选项。同时&#xff0c;AI时代的到来&#xff0c…

笔记:《利用Python进行数据分析》之数据聚合

观前提示&#xff1a;这节内容不多&#xff0c;但难度较大&#xff0c;尤其是要能熟练运用时很不容易的 数据聚合 聚合指的是任何能够从数组产生标量值的数据转换过程。之前的例子已经用过一些&#xff0c;比如mean、count、min以及sum等。你可能想知道在GroupBy对象上调用me…

网络原理 - 初识

文章目录 局域网(LAN)广域网(WAN)网络设备IP地址格式 端口号格式 认识网络协议协议分层 OSI七层模型(只是理论,没有实际运用)TCP/IP五层&#xff08;或四层&#xff09;模型网络设备所在分层 封装和分用 计算机之间通过网络来传输数据&#xff0c;也称为网络通信。 根据网络互连…

AI问答:.NET核心组成概要、程序运行步骤和查询SDK版本的方法

.NET三大组成 ①Runtime (运行时)&#xff1a; CLR&#xff1a;公共语言运行时&#xff0c;执行程序、内存管理、垃圾回收&#xff08;GC&#xff09;、安全性检查、异常处理&#xff0c;是跨平台的关键要素。 JIT&#xff1a;实时编译器&#xff0c;将中间语言…

JDBC与数据库之间的操作(增删改查、获取主键、业务逻辑分离、属性文件配置)

参考视频哔哩哔哩 1、Service和Servicelmpl的概念 java中service和servicelmpl是常见的代码组织方式 Service是指业务逻辑的接口&#xff0c;定义了系统对外提供的功能。Servicelmpl是Service接口的具体实现&#xff0c;实现了具体的业务逻辑。 Service和Servicelmpl的好处…

Android自定义View实现不同朝向字体变色

实现效果&#xff1a; 1.一个文字两种颜色 2.实现不同朝向 3.结合ViewPager 思路&#xff1a;TextView可行&#xff1f;系统提供的只能够显示一种颜色&#xff0c;需要自定义View extends TextView&#xff1a;onMeasure()不需要实现 textColor颜色&#xff0c;textSize字体大小…

OpenAI Whisper API (InvalidRequestError)

题意: OpenAI Whisper API&#xff08;无效请求错误&#xff09; 问题背景&#xff1a; Im trying to use OpenAI Whisper API to transcribe my audio files. When I run it by opening my local audio files from disk, it worked perfectly. Now Im developing a FastAPI e…