使用Harbor 搭建可视化仓库管理工具

1. 使用Harbor 搭建仓库

1.1 Harbor 简单介绍及安装前置环境

Harbor是VMware公司开源的企业级Docker Registry项目,其目标是帮助用户迅速搭建一个企业级的Docker registry服务。事实上,Habor是在Docker Registry上进行了相应的企业级扩展,从而获得了更加广泛的应用,这些新的企业级特性包括:管理用户界面,基于角色的访问控制 ,AD/LDAP集成以及审计日志等。
harbor英文单词的意思是:港湾。港湾用来存放集装箱(货物的),而docker的由来正是借鉴了集装箱的原理,所以harbor是用于存放docker的镜像,作为镜像仓库使用。作为一个企业级私有 Registry 服务器,Harbor 提供了更好的性能和安全。提升用户使用 Registry 构建和运行环境传输镜像的效率。

harbor官网:https://goharbor.io/

前置环境

  • Python >= 2.7
  • Docker >= 1.10,推荐使用阿里云加速器安装
  • Docker Compose >= 1.1.8(Harbor使用docker-compose以容器的形式运行)由于本次安装docker版本为18.03.1-ce,安装时提示要求Docker Compose版本大于等于1.1.8

1.2 下载及安装

安装Harbor时分为两种情况:

  • **在线安装程序:**在线安装程序从Docker集线器下载Harbor映像。因此,安装程序的尺寸非常小。
  • **脱机安装程序:**如果要向其部署Harbor的主机没有与Internet的连接,请使用脱机安装程序。脱机安装程序包含预构建的映像,因此它比联机安装程序大。

此处为离线安装步骤:

1.获取harbor安装包(最好选择版本号后面不带rc1标志,选择稳定版本最好),此处选择v1.9.3离线包

在这里插入图片描述

2.在系统中新建文件夹,我放在了usr/local/harbor

bash $ mkdir usr/local/harbor

3.解压已经下载的安装包

bash $ tar -xvf harbor-offline-installer-v1.9.3.tgz

4.修改配置文件并进行保存

bash $ cd harbor
bash $ vim  harbor.yml 

harbor.yml文件展示

# Configuration file of Harbor

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 144.34.211.158

# 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: /usr/local/harbor/cert/topcas.top.crt
   private_key: /usr/local/harbor/cert/topcas.top.key

# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345

# Harbor DB configuration
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: root123
  # The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
  max_idle_conns: 50
  # The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
  # Note: the default number of connections is 100 for postgres.
  max_open_conns: 100

# The default data volume
data_volume: /data

# Harbor Storage settings by default is using /data dir on local filesystem
# Uncomment storage_service setting If you want to using external storage
# storage_service:
#   # ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
#   # of registry's and chart repository's containers.  This is usually needed when the user hosts a internal storage with self signed certificate.
#   ca_bundle:

#   # storage backend, default is filesystem, options include filesystem, azure, gcs, s3, swift and oss
#   # for more info about this configuration please refer https://docs.docker.com/registry/configuration/
#   filesystem:
#     maxthreads: 100
#   # set disable to true when you want to disable registry redirect
#   redirect:
#     disabled: false

# Clair configuration
clair:
  # The interval of clair updaters, the unit is hour, set to 0 to disable the updaters.
  updaters_interval: 12

jobservice:
  # Maximum number of job workers in job service
  max_job_workers: 10

notification:
  # Maximum retry count for webhook job
  webhook_job_max_retry: 10

chart:
  # Change the value of absolute_url to enabled can enable absolute url in chart
  absolute_url: disabled

# Log configurations
log:
  # options are debug, info, warning, error, fatal
  level: info
  # configs for logs in local storage
  local:
    # Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
    rotate_count: 50
    # Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes.
    # If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G
    # are all valid.
    rotate_size: 200M
    # The directory on your host that store log
    location: /var/log/harbor

  # Uncomment following lines to enable external syslog endpoint.
  # external_endpoint:
  #   # protocol used to transmit log to external endpoint, options is tcp or udp
  #   protocol: tcp
  #   # The host of external endpoint
  #   host: localhost
  #   # Port of external endpoint
  #   port: 5140

#This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
_version: 1.9.0

# Uncomment external_database if using external database.
# external_database:
#   harbor:
#     host: harbor_db_host
#     port: harbor_db_port
#     db_name: harbor_db_name
#     username: harbor_db_username
#     password: harbor_db_password
#     ssl_mode: disable
#     max_idle_conns: 2
#     max_open_conns: 0
#   clair:
#     host: clair_db_host
#     port: clair_db_port
#     db_name: clair_db_name
#     username: clair_db_username
#     password: clair_db_password
#     ssl_mode: disable
#   notary_signer:
#     host: notary_signer_db_host
#     port: notary_signer_db_port
#     db_name: notary_signer_db_name
#     username: notary_signer_db_username
#     password: notary_signer_db_password
#     ssl_mode: disable
#   notary_server:
#     host: notary_server_db_host
#     port: notary_server_db_port
#     db_name: notary_server_db_name
#     username: notary_server_db_username
#     password: notary_server_db_password
#     ssl_mode: disable

# Uncomment external_redis if using external Redis server
# external_redis:
#   host: redis
#   port: 6379
#   password:
#   # db_index 0 is for core, it's unchangeable
#   registry_db_index: 1
#   jobservice_db_index: 2
#   chartmuseum_db_index: 3

# Uncomment uaa for trusting the certificate of uaa instance that is hosted via self-signed cert.
# uaa:
#   ca_file: /path/to/ca

# Global proxy
# Config http proxy for components, e.g. http://my.proxy.com:3128
# Components doesn't need to connect to each others via http proxy.
# Remove component from `components` array if want disable proxy
# for it. If you want use proxy for replication, MUST enable proxy
# for core and jobservice, and set `http_proxy` and `https_proxy`.
# Add domain to the `no_proxy` field, when you want disable proxy
# for some special registry.
proxy:
  http_proxy:
  https_proxy:
  no_proxy: 127.0.0.1,localhost,.local,.internal,log,db,redis,nginx,core,portal,postgresql,jobservice,registry,registryctl,clair
  components:
    - core
    - jobservice
    - clair

在配置文件中我们可以修改很多参数,Harbor默认为http请求访问,当在测试或者开发环境中我们可以使用http模式进行配置访问。只要修改hostname即可,更多完善的配置信息及介绍,则在下面做展示。但是生产环境建议使用https配置。此次配置我们采用https配置,所以在yml文件中已经修改了https的配置。https配置详情见官方网站,由于为测试配置,证书及签名都是根据官方文档进行生成,在正式环境中请使用正确的生成表。

配置地址: https://github.com/goharbor/harbor/blob/master/docs/configure_https.md

harbor.yml配置信息:

重要信息**:Harbor不附带任何证书。在1.9.x(含)以下的版本中,默认情况下,Harbour使用HTTP服务于注册表请求。这仅在有空隙的测试或开发环境中可接受。在生产环境中,请始终使用HTTPS。如果启用Content Trust with Notary来正确签名所有图像,则必须使用HTTPS。

您可以使用由受信任的第三方CA签名的证书,也可以使用自签名证书。有关如何创建CA以及如何使用CA签署服务器证书和客户端证书的信息,请参阅“ 使用HTTPS访问配置Harbor”

部署所需的参数
参数子参数说明和附加参数
hostname没有指定要在其上部署Harbor的目标主机的IP地址或标准域名(FQDN)。这是您访问Harbor Portal和注册表服务的地址。例如,192.168.1.10reg.yourdomain.com。注册表中的服务必须是外部客户端访问,因此不指定localhost127.0.0.10.0.0.0作为主机名。
https使用HTTPS访问Harbor Portal和令牌/通知服务。始终在生产环境和没有空隙的环境中使用HTTPS。
portHTTPS的端口号。默认值为443。
certificateSSL证书的路径。
private_keySSL密钥的路径。
harbor_admin_password没有为Harbor管理员设置初始密码。仅在首次启动Harbor时使用此密码。在后续登录时,此设置将被忽略,并且管理员密码在Harbor Portal中设置。默认的用户名和密码为adminHarbor12345
database使用本地PostgreSQL数据库。您可以选择配置外部数据库,在这种情况下,可以禁用此选项。
password设置本地数据库的根密码。您必须为生产部署更改此密码。
max_idle_conns空闲连接池中的最大连接数。如果设置为<= 0,则不会保留任何空闲连接。默认值为50。如果未配置,则值为2。
max_open_conns与数据库的最大打开连接数。如果<= 0,则打开的连接数没有限制。到Harbor数据库的最大连接数的默认值为100。如果未配置,则值为0。
data_volume没有目标主机上用于存储Harbor数据的位置。您可以选择配置外部存储,在这种情况下,请禁用此选项并启用storage_service。默认值为/data
clairupdaters_interval设置Clair更新的时间间隔(以小时为单位)。设置为0以禁用更新。默认值为12小时。
jobservicemax_job_workers作业服务中复制工作者的最大数量。对于每个图像复制作业,工作人员会将存储库的所有标签同步到远程目标。增加此数目将允许系统中进行更多并发复制作业。但是,由于每个工作人员都会消耗一定数量的网络/ CPU / IO资源,因此请根据主机的硬件资源设置此属性的值。预设值为10。
notificationwebhook_job_max_retry设置Web挂钩作业的最大重试次数。预设值为10。
chartabsolute_url设置enabled为Chart以使用绝对URL。设置disabled为Chart以使用相对URL。
log配置日志记录。
level设置日志级别debuginfowarningerror,或fatal。默认值为info
local设置日志保留参数:rotate_count:日志文件被轮换rotate_count删除之前。如果count为0,则将删除旧版本,而不是旋转旧版本。默认值为50。rotate_size:仅当日志文件大于rotate_size字节时才旋转。使用k千字节,M兆字节和G千兆字节。 100100k100M100G都是有效的值。默认值为200M。location:设置存储日志的目录。默认值为/var/log/harbor
external_endpoint启用此选项可将日志转发到syslog服务器。protocol:syslog服务器的传输协议。默认为TCP。host:syslog服务器的URL。port:syslog服务器侦听的端口
proxy配置Clair,复制作业服务和Harbor使用的代理。如果不需要代理,请保留空白。
http_proxy配置一个HTTP代理,例如 http://my.proxy.com:3128
https_proxy配置HTTPS代理,例如 http://my.proxy.com:3128
no_proxy配置何时不使用代理,例如127.0.0.1,localhost,core,registry
可选参数

下表列出了其他可选参数,您可以设置这些参数,以配置超出最低必需设置的Harbor部署。要启用设置,您必须harbor.yml通过删除前导#字符来取消注释。

港口的可选参数

参数子参数说明和附加参数
http不要在生产环境中使用HTTP。仅在没有连接到外部Internet的空白测试或开发环境中,才可以使用HTTP。在没有空隙的环境中使用HTTP会使您遭受中间人攻击。
portHTTP的端口号
external_url没有启用此选项以使用外部代理。启用后,将不再使用主机名。
storage_service默认情况下,Harbor将图像和图表存储在本地文件系统上。在生产环境中,您可能要使用另一个存储后端而不是本地文件系统。下面列出的参数是注册表的配置。有关如何配置其他后端的更多信息,请参见下面的“配置存储后端”。
ca_bundle定制根CA证书的路径,该路径已注入注册表和图表存储库容器的信任存储中。如果内部存储使用自签名证书,通常需要这样做。
filesystem默认值是filesystem,但你可以设置azuregcss3swiftoss。有关如何配置其他后端的信息,请参阅下面的配置存储后端。设置maxthreads为将线程数限制为外部提供程序。默认值为100。
redirect要禁用注册表重定向时设置disabletrue
external_database如果禁用本地数据库选项,请配置外部数据库设置。Harbor目前仅支持POSTGRES。
harbor配置用于港口数据的外部数据库。host:Harbor数据库的主机名。port:数据库端口。db_name: 数据库名称。username:用于连接到核心Harbor数据库的用户名。password:您在中设置的帐户的密码usernamessl_mode:启用SSL模式。max_idle_conns:空闲连接池中的最大连接数。如果<= 0,则不保留任何空闲连接。预设值为2。max_open_conns:到数据库的最大打开连接数。如果<= 0,则打开的连接数没有限制。默认值为0。
clair为Clair配置一个外部数据库。host:Clair数据库的主机名port:数据库端口。db_name: 数据库名称。username:用于连接到Clair数据库的用户名。password:您在中设置的帐户的密码usernamessl_mode:启用SSL模式。
notary_signer为公证人签名者数据库配置外部数据库host:公证人签名者数据库的主机名port:数据库端口。db_name: 数据库名称。username:用于连接到公证人签名者数据库的用户名。password:您在中设置的帐户的密码usernamessl_mode:启用SSL模式。
notary_serverhost:公证服务器数据库的主机名。port:数据库端口。db_name: 数据库名称。username:用于连接到公证服务器数据库的用户名。password:您在中设置的帐户的密码usernamessl_mode:启用SSL模式。e
external_redis配置外部Redis实例
host外部Redis实例的主机名。
portRedis实例端口。
password连接外部Redis实例的密码。
registry_db_indexHarbor注册中心的数据库索引。
jobservice_db_indexJobservice的数据库索引。
chartmuseum_db_index海图博物馆的数据库索引。
uaa使UAA信任通过自签名证书托管的UAA实例的证书。
ca_fileUAA实例的自签名证书的路径,例如/path/to/ca
特别提醒

Harbor配置中常见的错误及解决方案可以在Harbor官网的ISSUES中找到

测试及启动Harbor

$ sudo ./install.sh

启动之后我们可以根据配置的ip或者域名进行访问:

在这里插入图片描述

当出现这个界面时表示harbor配置已经成功。当出现上述图中描述情况请在生成的证书中找到.crt文件,将其加入浏览器受信任区中。

1.3 Harbor 特性及使用

Harbor的特性

  • 基于角色控制
    用户和仓库都是基于项目进行组织的, 而用户基于项目可以拥有不同的权限。
  • 基于镜像的复制策略
    镜像可以在多个Harbor实例之间进行复制。
  • 支持LDAP
    Harbor的用户授权可以使用已经存在LDAP用户。
  • 镜像删除 & 垃圾回收
    Image可以被删除并且回收Image占用的空间。
  • 友好UI
    用户可以轻松的浏览、搜索镜像仓库以及对项目进行管理。
  • 便于扩展
    绝大部分的用户操作API, 方便用户对系统进行扩展。
  • 轻松部署
    Harbor提供了online、offline安装,除此之外还提供了virtualappliance安装。

Harbor的使用

接下来我们对本地仓库进行测试及上传镜像

本地登录并且上传镜像

docker login 144.34.211.158

docker tag centos:latest   144.34.211.158:443/test/centos:latest  #test为Harbor中的项目名称,Harbor中不存在会报错,需要提前建立。
docker  push  144.34.211.158:443/test/centos:latest

下载镜像

docker pull 144.34.211.158/test/centos:latest

问题记载:

在这里插入图片描述

出现问题:

Error response from daemon: Get https://144.34.211.158/v2/: x509: cannot validate certificate for 144.34.211.158 because it doesn't contain any IP SANs

解决方案:

在/etc/docker目录下查找daemon.json文件,如果文件不存在,则新建文件,在文件里面添加

{
  "insecure-registries":["144.34.211.158:443"] 
}

最好在配置时配置ip,包括在harbor.yml中的hostname也配置为ip。这个地方尝试了很多种方式,但这种方式很幸运成功了!如果有其他问题参考官网

在这里插入图片描述

接下来重新启动docker

systemctl daemon-reload
systemctl restart docker
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值