harbor仓库部署

harbor仓库部署

Harbor简介

Harbor是由VMWare在Docker Registry的基础之上进行了二次封装,加进去了很多额外程序,而且提供了一个非常漂亮的web界面。

‎Project Harbor 是一个开源的可信云原生注册表项目,用于存储、签名和扫描上下文。‎
‎Harbor 通过添加用户通常需要的功能(如安全性、身份和管理)来扩展开源 Docker 分发版。‎
‎Harbor 支持高级功能,如用户管理、访问控制、活动监控和实例间复制‎.

Harbor的功能

‎羽毛:‎

  • ‎多租户内容签名和验证‎
    [En]

    ‎ multi-tenant content signing and verification ‎*

  • ‎安全性和漏洞分析‎
  • ‎审核日志记录‎
  • ‎身份集成和基于角色的访问控制‎
    [En]

    ‎ identity integration and role-based access control ‎*

  • ‎实例之间的映像复制‎
  • ‎可扩展的 API 和图形用户界面‎
  • ‎国际化(现为英文和中文)‎
    [En]

    ‎ internationalization (now English and Chinese) ‎*

Docker compose

Harbor在物理机上部署是非常难的,而为了简化Harbor的应用,Harbor官方直接把Harbor做成了在容器中运行的应用,而且这个容器在Harbor中依赖类似redis、mysql、pgsql等很多存储系统,所以它需要编排很多容器协同起来工作,因此VMWare Harbor在部署和使用时,需要借助于Docker的单机编排工具(Docker compose)来实现。

‎Compose 是用于定义和运行多容器 Docker 应用程序的工具。使用 Compose,您可以使用 YAML 文件来配置应用程序的服务。然后,使用单个命令,从配置中创建并启动所有服务。‎

Docker Compose官方文档

Harbor官方文档

部署harbor

部署服务端

安装docker

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
[root@localhost yum.repos.d]# sed -i 's@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g' docker-ce.repo
[root@localhost yum.repos.d]# dnf -y install docker-ce

配置镜像加速器

[root@localhost ~]# sudo mkdir -p /etc/docker
[root@localhost ~]# sudo tee /etc/docker/daemon.json <<-'eof'> {
>   "registry-mirrors": ["https://w673ojdv.mirror.aliyuncs.com"]
> }
> EOF
{
  "registry-mirrors": ["https://w673ojdv.mirror.aliyuncs.com"]
}
[root@localhost ~]# sudo systemctl daemon-reload
[root@localhost ~]# sudo systemctl restart docker
[root@localhost ~]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service &#x2192; /usr/lib/systemd/system/docker.service.

</-'eof'>

安装docker-compose

//&#x4FEE;&#x6539;&#x540D;&#x5B57;
[root@harbor ~]# hostnamectl set-hostname harbor.example.com
[root@harbor ~]# bash
[root@harbor ~]# hostname
harbor.example.com

//&#x5B89;&#x88C5;docker-compose&#x547D;&#x4EE4;
[root@harbor ~]# ls -a
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .config  .cshrc  .tcshrc  .viminfo  .wget-hsts  anaconda-ks.cfg
[root@harbor ~]# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}  //&#x521B;&#x5EFA;&#x4E00;&#x4E2A;.docker&#x76EE;&#x5F55;
[root@harbor ~]# mkdir -p $DOCKER_CONFIG/cli-plugins        //&#x521B;&#x5EFA;&#x4E00;&#x4E2A;cli-plugins&#x76EE;&#x5F55;
[root@harbor ~]# ls -a
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .config  .cshrc  .docker  .tcshrc  .viminfo  .wget-hsts  anaconda-ks.cfg
[root@harbor ~]# cd .docker/
[root@harbor .docker]# ls
cli-plugins
[root@harbor .docker]# curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose     //docker-compose&#x4E0B;&#x8F7D;&#x8DEF;&#x5F84;

//&#x5DF2;&#x7ECF;&#x4E0B;&#x8F7D;&#x597D;&#x7684;&#x4E0A;&#x4F20;&#x81F3;root&#x4E0B;
[root@harbor ~]# ls
anaconda-ks.cfg  docker-compose-linux-x86_64.octet-stream
[root@harbor ~]# mv docker-compose-linux-x86_64.octet-stream /root/.docker/cli-plugins/docker-compose

//&#x914D;&#x7F6E;docker-compose
[root@harbor ~]# cd /root/.docker/cli-plugins/
[root@harbor cli-plugins]# ls
docker-compose
[root@harbor cli-plugins]# chmod +x docker-compose
[root@harbor cli-plugins]# ll
total 25188
-rwxr-xr-x. 1 root root 25792512 Aug 11 18:31 docker-compose
[root@harbor cli-plugins]# ./docker-compose         //&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E86;
[root@harbor cli-plugins]# pwd
/root/.docker/cli-plugins       //&#x76EE;&#x524D;&#x53EA;&#x80FD;&#x5728;&#x6587;&#x4EF6;&#x5939;&#x91CC;&#x4F7F;&#x7528;
[root@harbor cli-plugins]# ln -s /root/.docker/cli-plugins/docker-compose /usr/bin/     //&#x521B;&#x5EFA;&#x8F6F;&#x94FE;&#x63A5;
[root@harbor cli-plugins]# cd
[root@harbor ~]# which docker-compose
/usr/bin/docker-compose
[root@harbor ~]# docker compose version
Docker Compose version v2.7.0

安装harbor

[root@harbor ~]# wget https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-offline-installer-v2.5.3.tgz

//&#x5DF2;&#x7ECF;&#x4E0B;&#x8F7D;&#x597D;&#x7684;&#x4E0A;&#x4F20;&#x81F3;root&#x4E0B;
[root@harbor ~]# ls
anaconda-ks.cfg  harbor-offline-installer-v2.5.3.tgz
[root@harbor ~]# tar xf harbor-offline-installer-v2.5.3.tgz -C /usr/local/

//&#x914D;&#x7F6E;harbor
[root@harbor ~]# cd /usr/local/
[root@harbor local]# ls
bin  etc  games  harbor  include  lib  lib64  libexec  sbin  share  src
[root@harbor local]# cd harbor/
[root@harbor harbor]# ls
LICENSE  common.sh  harbor.v2.5.3.tar.gz  harbor.yml.tmpl  install.sh  prepare
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
[root@harbor harbor]# vim harbor.yml
hostname: harbor.example.com        //&#x4FEE;&#x6539;&#x4E3A;&#x57DF;&#x540D;&#x6216;&#x8005;IP

#https:                     //&#x6CE8;&#x91CA;&#x6389;
  # https port for harbor, default is 443
  #port: 443
  # The path of cert and key files for nginx
  #certificate: /your/certificate/path      //&#x6CE8;&#x91CA;&#x6389;
  #private_key: /your/private/key/path      //&#x6CE8;&#x91CA;&#x6389;
[root@harbor harbor]# ./install.sh      //&#x62C9;&#x53D6;&#x955C;&#x50CF;
[+] Running 10/10
 &#x283F; Network harbor_harbor        Created                                                                                                     0.2s
 &#x283F; Container harbor-log         Started                                                                                                     0.5s
 &#x283F; Container registryctl        Started                                                                                                     2.0s
 &#x283F; Container registry           Started                                                                                                     2.0s
 &#x283F; Container redis              Started                                                                                                     2.1s
 &#x283F; Container harbor-db          Started                                                                                                     2.0s
 &#x283F; Container harbor-portal      Started                                                                                                     1.6s
 &#x283F; Container harbor-core        Started                                                                                                     2.4s
 &#x283F; Container nginx              Started                                                                                                     3.2s
 &#x283F; Container harbor-jobservice  Started                                                                                                     3.2s
&#x2714; ----Harbor has been installed and started successfully.----
[root@harbor harbor]# ss -anlt
State            Recv-Q           Send-Q                     Local Address:Port                     Peer Address:Port          Process
LISTEN           0                128                            127.0.0.1:1514                          0.0.0.0:*
LISTEN           0                128                              0.0.0.0:22                            0.0.0.0:*
LISTEN           0                128                              0.0.0.0:443                           0.0.0.0:*
LISTEN           0                128                                 [::]:22                               [::]:*
LISTEN           0                128                                 [::]:443                              [::]:*

访问测试

harbor仓库部署

harbor仓库部署

设置开机自启动

[root@harbor harbor]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                   PORTS                                   NAMES
39dd86d1eec2   goharbor/harbor-jobservice:v2.5.3    "/harbor/entrypoint.&#x2026;"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-jobservice
71bf08bfd7da   goharbor/nginx-photon:v2.5.3         "nginx -g 'daemon of&#x2026;"   3 minutes ago   Up 3 minutes (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp   nginx
61c050421868   goharbor/harbor-core:v2.5.3          "/harbor/entrypoint.&#x2026;"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-core
664cf7c60665   goharbor/redis-photon:v2.5.3         "redis-server /etc/r&#x2026;"   3 minutes ago   Up 3 minutes (healthy)                                           redis
60a295df8091   goharbor/registry-photon:v2.5.3      "/home/harbor/entryp&#x2026;"   3 minutes ago   Up 3 minutes (healthy)                                           registry
37374fefa729   goharbor/harbor-portal:v2.5.3        "nginx -g 'daemon of&#x2026;"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-portal
8530ed5fdee7   goharbor/harbor-db:v2.5.3            "/docker-entrypoint.&#x2026;"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-db
a1741a70ff7d   goharbor/harbor-registryctl:v2.5.3   "/home/harbor/start.&#x2026;"   3 minutes ago   Up 3 minutes (healthy)                                           registryctl
5d7a2d387ec8   goharbor/harbor-log:v2.5.3           "/bin/sh -c /usr/loc&#x2026;"   3 minutes ago   Up 3 minutes (healthy)   127.0.0.1:1514->10514/tcp               harbor-log

//&#x521B;&#x5EFA;&#x811A;&#x672C;&#x8FDB;&#x884C;&#x81EA;&#x542F;&#x52A8;
[root@harbor ~]# vim /etc/rc.local
#!/bin/bash                     //&#x5F00;&#x5934;&#x4F4D;&#x7F6E;
cd /usr/lcoal/harbor            //&#x6DFB;&#x52A0;
docker-compose start            //&#x6DFB;&#x52A0;
[root@harbor ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 517 Aug 11 19:26 /etc/rc.d/rc.local
[root@harbor ~]# chmod +x /etc/rc.d/rc.local

//&#x91CD;&#x542F;&#x67E5;&#x770B;&#x662F;&#x5426;&#x5F00;&#x673A;&#x81EA;&#x542F;&#x52A8;
[root@harbor ~]# reboot
[root@harbor ~]# ss -anlt
State            Recv-Q           Send-Q                     Local Address:Port                     Peer Address:Port          Process
LISTEN           0                128                            127.0.0.1:1514                          0.0.0.0:*
LISTEN           0                128                              0.0.0.0:80                            0.0.0.0:*
LISTEN           0                128                              0.0.0.0:22                            0.0.0.0:*
LISTEN           0                128                                 [::]:80                               [::]:*
LISTEN           0                128                                 [::]:22                               [::]:*
[root@harbor ~]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                             PORTS                                   NAMES
39dd86d1eec2   goharbor/harbor-jobservice:v2.5.3    "/harbor/entrypoint.&#x2026;"   5 minutes ago   Up 10 seconds (health: starting)                                           harbor-jobservice
71bf08bfd7da   goharbor/nginx-photon:v2.5.3         "nginx -g 'daemon of&#x2026;"   5 minutes ago   Up 10 seconds (health: starting)   0.0.0.0:80->8080/tcp, :::80->8080/tcp   nginx
61c050421868   goharbor/harbor-core:v2.5.3          "/harbor/entrypoint.&#x2026;"   5 minutes ago   Up 12 seconds (health: starting)                                           harbor-core
664cf7c60665   goharbor/redis-photon:v2.5.3         "redis-server /etc/r&#x2026;"   5 minutes ago   Up 11 seconds (health: starting)                                           redis
60a295df8091   goharbor/registry-photon:v2.5.3      "/home/harbor/entryp&#x2026;"   5 minutes ago   Up 11 seconds (health: starting)                                           registry
37374fefa729   goharbor/harbor-portal:v2.5.3        "nginx -g 'daemon of&#x2026;"   5 minutes ago   Up 11 seconds (health: starting)                                           harbor-portal
8530ed5fdee7   goharbor/harbor-db:v2.5.3            "/docker-entrypoint.&#x2026;"   5 minutes ago   Up 12 seconds (health: starting)                                           harbor-db
a1741a70ff7d   goharbor/harbor-registryctl:v2.5.3   "/home/harbor/start.&#x2026;"   5 minutes ago   Up 11 seconds (health: starting)                                           registryctl
5d7a2d387ec8   goharbor/harbor-log:v2.5.3           "/bin/sh -c /usr/loc&#x2026;"   5 minutes ago   Up 12 seconds (health: starting)   127.0.0.1:1514->10514/tcp               harbor-log

使用Harbor的注意事项:

  1. 在客户端上传镜像时一定要记得执行docker login进行用户认证,否则无法直接push
  2. 在客户端使用的时候如果不是用的https则必须要在客户端的/etc/docker/daemon.json配置文件中配置insecure-registries参数
  3. 数据存放路径应在配置文件中配置到一个容量比较充足的共享存储中
  4. Harbor是使用docker-compose命令来管理的,如果需要停止Harbor也应用docker-compose stop来停止,其他参数请–help

部署客户端

也是需要在安装了docker的环境下部署

//&#x4FEE;&#x6539;&#x540D;&#x5B57;
[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# bash

//&#x6DFB;&#x52A0;&#x670D;&#x52A1;&#x7AEF;IP
[root@client ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.111.135 harbor.example.com      //&#x6DFB;&#x52A0;
[root@client ~]# ping 192.168.111.135
PING 192.168.111.135 (192.168.111.135) 56(84) bytes of data.

64 bytes from 192.168.111.135: icmp_seq=1 ttl=64 time=0.633 ms
64 bytes from 192.168.111.135: icmp_seq=2 ttl=64 time=0.728 ms

//&#x767B;&#x5F55;harbor
[root@client ~]# vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://w673ojdv.mirror.aliyuncs.com"],     //&#x8FD9;&#x91CC;&#x52A0;&#x4E2A;&#x9017;&#x53F7;
  "insecure-registries": ["harbor.example.com"]     //&#x6DFB;&#x52A0;
}
[root@client ~]# systemctl restart docker
[root@client ~]# docker login harbor.example.com
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
[root@client ~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED        SIZE
xinruizhong/httpd   v1.1      65836c550784   37 hours ago   789MB
httpd               latest    dabbfbe0c57b   7 months ago   144MB

//&#x5C06;&#x81EA;&#x5DF1;&#x521B;&#x5EFA;&#x7684;&#x955C;&#x50CF;&#x4E0A;&#x4F20;&#x5230;harbor&#x4E0A;
[root@client ~]# docker tag xinruizhong/httpd:v1.1 harbor.example.com/library/httpd:v1.1            //&#x6253;&#x4E0A;&#x6807;&#x7B7E;
[root@client ~]# docker images
REPOSITORY                         TAG       IMAGE ID       CREATED        SIZE
xinruizhong/httpd                  v1.1      65836c550784   37 hours ago   789MB
harbor.example.com/library/httpd   v1.1      65836c550784   37 hours ago   789MB
httpd                              latest    dabbfbe0c57b   7 months ago   144MB
[root@client ~]# docker push harbor.example.com/library/httpd:v1.1      //&#x4E0A;&#x4F20;&#x955C;&#x50CF;
The push refers to repository [harbor.example.com/library/httpd]
a3705dc88dcd: Pushed
74ddd0ec08fa: Pushed
v1.1: digest: sha256:a5b133a68e0bb18860b7c9361e32ae93943f95c188bf0d126d1995d4f16d02b7 size: 742

查看效果

可以显示什么时间上传的

harbor仓库部署

测试是否能拉取下来

[root@client ~]# docker images
REPOSITORY                         TAG       IMAGE ID       CREATED        SIZE
xinruizhong/httpd                  v1.1      65836c550784   37 hours ago   789MB
harbor.example.com/library/httpd   v1.1      65836c550784   37 hours ago   789MB
httpd                              latest    dabbfbe0c57b   7 months ago   144MB
[root@client ~]# docker rmi -f harbor.example.com/library/httpd:v1.1
Untagged: harbor.example.com/library/httpd:v1.1
Untagged: harbor.example.com/library/httpd@sha256:a5b133a68e0bb18860b7c9361e32ae93943f95c188bf0d126d1995d4f16d02b7
[root@client ~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED        SIZE
xinruizhong/httpd   v1.1      65836c550784   37 hours ago   789MB
httpd               latest    dabbfbe0c57b   7 months ago   144MB
[root@client ~]# docker pull harbor.example.com/library/httpd:v1.1  //&#x62C9;&#x53D6;&#x955C;&#x50CF;
v1.1: Pulling from library/httpd
Digest: sha256:a5b133a68e0bb18860b7c9361e32ae93943f95c188bf0d126d1995d4f16d02b7
Status: Downloaded newer image for harbor.example.com/library/httpd:v1.1
harbor.example.com/library/httpd:v1.1
[root@client ~]# docker images
REPOSITORY                         TAG       IMAGE ID       CREATED        SIZE
harbor.example.com/library/httpd   v1.1      65836c550784   37 hours ago   789MB
xinruizhong/httpd                  v1.1      65836c550784   37 hours ago   789MB
httpd                              latest    dabbfbe0c57b   7 months ago   144MB

Original: https://www.cnblogs.com/Their-own/p/16577761.html
Author: 事愿人为
Title: harbor仓库部署

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/522886/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球