harbor仓库部署,‎ProjectHa


harbor仓库部署

目录
  • harbor仓库部署
    • 部署harbor
      • 部署服务端
      • 部署客户端
      • 查看效果

Harbor简介

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

‎Project Harbor 是一个开源的可信云原生注册表项目,用于存储、签名和扫描上下文。‎

‎Harbor 通过添加用户通常需要的功能(如安全性、身份和管理)来扩展开源 Docker 分发版。‎

‎Harbor 支持高级功能,如用户管理、访问控制、活动监控和实例间复制‎.

Harbor的功能

‎羽毛:‎

  • ‎多租户内容签名和验证‎
  • ‎安全性和漏洞分析‎
  • ‎审核日志记录‎
  • ‎身份集成和基于角色的访问控制‎
  • ‎实例之间的映像复制‎
  • ‎可扩展的 API 和图形用户界面‎
  • ‎国际化(现为英文和中文)‎

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 → /usr/lib/systemd/system/docker.service.

安装docker-compose

//修改名字
[root@harbor ~]# hostnamectl set-hostname harbor.example.com
[root@harbor ~]# bash
[root@harbor ~]# hostname
harbor.example.com

//安装docker-compose命令
[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}	//创建一个.docker目录
[root@harbor ~]# mkdir -p $DOCKER_CONFIG/cli-plugins		//创建一个cli-plugins目录
[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下载路径

//已经下载好的上传至root下
[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

//配置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 		//可以使用了
[root@harbor cli-plugins]# pwd
/root/.docker/cli-plugins		//目前只能在文件夹里使用
[root@harbor cli-plugins]# ln -s /root/.docker/cli-plugins/docker-compose /usr/bin/		//创建软链接
[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

//已经下载好的上传至root下
[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/

//配置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		//修改为域名或者IP

#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		//注释掉
[root@harbor harbor]# ./install.sh 		//拉取镜像
[+] Running 10/10
 ⠿ Network harbor_harbor        Created                                                                                                     0.2s
 ⠿ Container harbor-log         Started                                                                                                     0.5s
 ⠿ Container registryctl        Started                                                                                                     2.0s
 ⠿ Container registry           Started                                                                                                     2.0s
 ⠿ Container redis              Started                                                                                                     2.1s
 ⠿ Container harbor-db          Started                                                                                                     2.0s
 ⠿ Container harbor-portal      Started                                                                                                     1.6s
 ⠿ Container harbor-core        Started                                                                                                     2.4s
 ⠿ Container nginx              Started                                                                                                     3.2s
 ⠿ Container harbor-jobservice  Started                                                                                                     3.2s
✔ ----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                              [::]:*                               

访问测试

设置开机自启动

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

//创建脚本进行自启动
[root@harbor ~]# vim /etc/rc.local 
#!/bin/bash						//开头位置
cd /usr/lcoal/harbor			//添加
docker-compose start			//添加
[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 

//重启查看是否开机自启动
[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.…"   5 minutes ago   Up 10 seconds (health: starting)                                           harbor-jobservice
71bf08bfd7da   goharbor/nginx-photon:v2.5.3         "nginx -g 'daemon of…"   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.…"   5 minutes ago   Up 12 seconds (health: starting)                                           harbor-core
664cf7c60665   goharbor/redis-photon:v2.5.3         "redis-server /etc/r…"   5 minutes ago   Up 11 seconds (health: starting)                                           redis
60a295df8091   goharbor/registry-photon:v2.5.3      "/home/harbor/entryp…"   5 minutes ago   Up 11 seconds (health: starting)                                           registry
37374fefa729   goharbor/harbor-portal:v2.5.3        "nginx -g 'daemon of…"   5 minutes ago   Up 11 seconds (health: starting)                                           harbor-portal
8530ed5fdee7   goharbor/harbor-db:v2.5.3            "/docker-entrypoint.…"   5 minutes ago   Up 12 seconds (health: starting)                                           harbor-db
a1741a70ff7d   goharbor/harbor-registryctl:v2.5.3   "/home/harbor/start.…"   5 minutes ago   Up 11 seconds (health: starting)                                           registryctl
5d7a2d387ec8   goharbor/harbor-log:v2.5.3           "/bin/sh -c /usr/loc…"   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的环境下部署

//修改名字
[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# bash

//添加服务端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		//添加
[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

//登录harbor
[root@client ~]# vim /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://w673ojdv.mirror.aliyuncs.com"],		//这里加个逗号
  "insecure-registries": ["harbor.example.com"]		//添加
}
[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


//将自己创建的镜像上传到harbor上
[root@client ~]# docker tag xinruizhong/httpd:v1.1 harbor.example.com/library/httpd:v1.1			//打上标签
[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		//上传镜像
The push refers to repository [harbor.example.com/library/httpd]
a3705dc88dcd: Pushed 
74ddd0ec08fa: Pushed 
v1.1: digest: sha256:a5b133a68e0bb18860b7c9361e32ae93943f95c188bf0d126d1995d4f16d02b7 size: 742

查看效果

可以显示什么时间上传的

测试是否能拉取下来

[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	//拉取镜像
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

相关内容