Harbor部署

Harbor仓库部署

Harbor

无论是使用Docker-distribution去自建仓库,还是通过官方镜像跑容器的方式去自建仓库,通过前面的演示我们可以发现其是非常的简陋的,还不如直接使用官方的Docker Hub去管理镜像来得方便,至少官方的Docker Hub能够通过web界面来管理镜像,还能在web界面执行搜索,还能基于Dockerfile利用Webhooks和Automated Builds实现自动构建镜像的功能,用户不需要在本地执行docker build,而是把所有build上下文的文件作为一个仓库推送到github上,让Docker Hub可以从github上去pull这些文件来完成自动构建。

但无论官方的Docker Hub有多强大,它毕竟是在国外,所以速度是最大的瓶颈,我们很多时候是不可能去考虑使用官方的仓库的,但是上面说的两种自建仓库方式又十分简陋,不便管理,所以后来就出现了一个被 CNCF 组织青睐的项目,其名为Harbor。

Harbor简介

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

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

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

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

Harbor的功能

Feathers:

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

Docker compose

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

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

Docker Compose官方文档

Harbor部署

安装docker-compose

[root@localhost ~]# hostnamectl set-hostname harbor.example.com
[root@localhost ~]# bash
[root@harbor ~]# 
[root@harbor ~]# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
[root@harbor ~]# mkdir -p $DOCKER_CONFIG/cli-plugins
[root@harbor ~]# ls -a
.   .bash_history  .bash_profile  .config  .docker  .wget-hsts
..  .bash_logout   .bashrc        .cshrc   .tcshrc  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
[root@harbor ~]# ls
anaconda-ks.cfg  docker-compose-linux-x86_64.octet-stream
[root@harbor ~]# 
[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]# 
[root@harbor cli-plugins]# chmod +x docker-compose 
[root@harbor cli-plugins]# ll
total 25188
-rwxr-xr-x. 1 root root 25792512 Aug 12 09:03 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
[root@harbor ~]# 

部署harbor

安装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 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]# vi harbor.yml
hostname: harbor.example.com
# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80
# 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
[root@harbor harbor]# ./install.sh
[+] Running 10/10
 ⠿ Network harbor_harbor        Created                                       0.2s
 ⠿ Container harbor-log         Started                                       0.6s
 ⠿ Container harbor-portal      Started                                       2.2s
 ⠿ Container registryctl        Started                                       2.2s
 ⠿ Container redis              Started                                       2.4s
 ⠿ Container registry           Started                                       2.2s
 ⠿ Container harbor-db          Started                                       2.4s
 ⠿ Container harbor-core        Started                                       2.8s
 ⠿ Container nginx              Started                                       3.6s
 ⠿ Container harbor-jobservice  Started                                       3.3s
✔ ----Harbor has been installed and started successfully.----
[root@harbor harbor]# 
[root@harbor harbor]# 
[root@harbor harbor]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port      Peer Address:Port   Process   
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            127.0.0.1:1514           0.0.0.0:*                
LISTEN   0        128                 [::]:80                [::]:*                
LISTEN   0        128                 [::]:22                [::]:*                
[root@harbor harbor]# 


访问测试

image

image

设置为开机自启

[root@harbor ~]# vi /etc/rc.local
[root@harbor ~]# cat /etc/rc.local
#!/bin/bash
cd /usr/local/harbor
docker-compose start
[root@harbor ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 516 Aug 12 09:33 /etc/rc.d/rc.local
[root@harbor ~]# chmod +x /etc/rc.d/rc.local
[root@harbor ~]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                   PORTS                                   NAMES
ecf0ca6e7cd6   goharbor/harbor-jobservice:v2.5.3    "/harbor/entrypoint.…"   7 minutes ago   Up 7 minutes (healthy)                                           harbor-jobservice
68a0b4121311   goharbor/nginx-photon:v2.5.3         "nginx -g 'daemon of…"   7 minutes ago   Up 7 minutes (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp   nginx
70f59712d6e0   goharbor/harbor-core:v2.5.3          "/harbor/entrypoint.…"   7 minutes ago   Up 7 minutes (healthy)                                           harbor-core
8e52560a8cda   goharbor/harbor-registryctl:v2.5.3   "/home/harbor/start.…"   7 minutes ago   Up 7 minutes (healthy)                                           registryctl
f829a9ab9741   goharbor/harbor-portal:v2.5.3        "nginx -g 'daemon of…"   7 minutes ago   Up 7 minutes (healthy)                                           harbor-portal
69187d5adafa   goharbor/harbor-db:v2.5.3            "/docker-entrypoint.…"   7 minutes ago   Up 7 minutes (healthy)                                           harbor-db
af9090006939   goharbor/redis-photon:v2.5.3         "redis-server /etc/r…"   7 minutes ago   Up 7 minutes (healthy)                                           redis
d35c468de7ad   goharbor/registry-photon:v2.5.3      "/home/harbor/entryp…"   7 minutes ago   Up 7 minutes (healthy)                                           registry
1e6d4f41833a   goharbor/harbor-log:v2.5.3           "/bin/sh -c /usr/loc…"   7 minutes ago   Up 7 minutes (healthy)   127.0.0.1:1514->10514/tcp               harbor-log
[root@harbor ~]# 

使用Harbor的注意事项:

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

部署客户端

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

虚拟机名字 IP 安装软件
服务端 harbor 192.168.10.145 docker ,harbor
客户端 client 192.168.10.150 docker
[root@client ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.145 harbor.example.com
[root@client ~]# ping 192.168.10.145
PING 192.168.10.145 (192.168.10.145) 56(84) bytes of data.
64 bytes from 192.168.10.145: icmp_seq=1 ttl=64 time=0.501 ms
64 bytes from 192.168.10.145: icmp_seq=2 ttl=64 time=0.262 ms
64 bytes from 192.168.10.145: icmp_seq=3 ttl=64 time=0.200 ms
64 bytes from 192.168.10.145: icmp_seq=4 ttl=64 time=0.238 ms
^C
--- 192.168.10.145 ping statistics ---

client登录harbor

[root@client ~]# vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://t82gwevc.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 ~]# 
[root@client ~]# docker images
REPOSITORY       TAG       IMAGE ID       CREATED      SIZE
daojiang/httpd   v1.1      f814a5a32437   2 days ago   789MB
[root@client ~]# 

将自己创建的镜像上传到harbor上

[root@client ~]# docker tag daojiang/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      f814a5a32437   2 days ago   789MB
daojiang/httpd                     v1.1      f814a5a32437   2 days ago   789MB
[root@client ~]# docker push harbor.example.com/library/httpd:v1.1 
The push refers to repository [harbor.example.com/library/httpd]
c84be8057ecf: Pushed 
74ddd0ec08fa: Pushed 
v1.1: digest: sha256:3d3e53cd6fc63785829a6c65d9e54cf835a4a592d371ca9eef67a54e469697b1 size: 742
[root@client ~]# 

image

测试能否拉取镜像

[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:3d3e53cd6fc63785829a6c65d9e54cf835a4a592d371ca9eef67a54e469697b1
[root@client ~]# docker images
REPOSITORY       TAG       IMAGE ID       CREATED      SIZE
daojiang/httpd   v1.1      f814a5a32437   2 days ago   789MB
[root@client ~]# 
[root@client ~]# docker pull harbor.example.com/library/httpd:v1.1
v1.1: Pulling from library/httpd
Digest: sha256:3d3e53cd6fc63785829a6c65d9e54cf835a4a592d371ca9eef67a54e469697b1
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
daojiang/httpd                     v1.1      f814a5a32437   2 days ago   789MB
harbor.example.com/library/httpd   v1.1      f814a5a32437   2 days ago   789MB
[root@client ~]# 

posted @   niebangrui  阅读(104)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示