ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Docker之分布式仓库Harbor部署

2021-11-05 13:33:45  阅读:428  来源: 互联网

标签:node01 goharbor Harbor config harbor Docker root docker 分布式


一  Harbor介绍

1.1 Harbor介绍

Harbor是一个用于存储和分发docker镜像的企业级Registry服务器,由VMware开源,其通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distrubution,作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升了用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中,确保数据和知识产权在公司内部网络中管理,另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。

vmware 官方开源服务:https://vmware.github.io

harbor 官方github地址:https://github.com/goharbor/harbor

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

harbor 官方文档: https://goharbor.io

github文档:https://goharbor.io/docs/2.4.0/

1.2 Harbor功能官方介绍

  • 基于角色的访问控制:用户与docker镜像仓库通过项目进行组织管理,一个用户可以对多个镜像仓库在同一命名空间里有不同的权限。
  • 镜像复制:镜像可在多个Registry实例中复制。尤其适合负载均衡,高可用,混合云和多云场景。
  • 图形化用户界面:用户可以通过浏览器来浏览,检索当前Docker镜像仓库,管理项目和命名空间。
  • AD/LDAP支持:Harbor可以集成企业内部已有的AD/LDAP,用于鉴权认证管理。
  • 审计管理:所有针对镜像仓库的操作都可以被记录追溯,用于审计管理。
  • 国际化:已拥有英文。中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。
  • RESTful API:提供给管理员对于Harbor更多的操控,使得与其它管理软件集成变得更容易。
  • 部署简单:提供在线和离线两种安装工具,也可以安装到vSphere平台虚拟设备。

1.3 Harbor组成

  • proxy:对应启动组件nginx。它是一个nginx反向代理,代理Notary client(镜像认证)、docker client(镜像上传下载)和浏览器的访问请求(Core Service)给后端的各服务器。
  • UI(Core Service):对应启动组件harbor-ui。底层数据存储使用mysql数据库,主要提供了四个子功能。
    • UI:一个web管理页面ui
    • API:Harbor暴露的API服务。
    • Auth:用户认证服务,decode后的token中的用户信息在这里进行认证;auth后端可以接db、ldap、uaa三种认证实现。
    • Token服务:负责根据用户在每个project中的role来为每个docker push/pull 命令发布一个token,如果docker client发送给registry的请求没有带token,registry会重定向请求到token服务创建token。
  • Registry:对应启动组件registry。负责存储镜像文件和处理镜像的pull/push命令。Harbor对镜像进行强制的访问控制,Registry会将每个客户端的每个pull/push请求转发到token服务来获取有效的token。
  • Admin Service:对应启动组件harbor-admin server。是系统的配置管理中心附带检查存储用量,ui和jobserver启动时需要加载adminserver配置。
  • job server:对应启动组件harbor-jobservice。负责镜像复制工作,塔河Registry通信。从一个Registry pull镜像然后push到另一个Registry,并记录job_log.
  • Log Collector:对应启动组件harbor-log。日志汇总组件,通过docker的log-driver把日志汇总到一起。
  • DB:对应启动组件harbor-db,负责存储project、user、role、replication、image_scan、access等的metadata数据。

二 环境准备

2.1 部署规划

类型 IP 主机名称 备注
harbor-01 192.168.75.157 node01  

2.2 时间同步

root@node01:~# apt -y install chrony
root@node01:~# systemctl enable chrony
root@node01:~# systemctl restart chrony

2.3 安装docker

点击查看代码
root@node01:~# apt-get -y install apt-transport-https ca-certificates curl software-properties-common
root@node01:~# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
root@node01:~# add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
root@node01:~# apt update
root@node01:~# apt-get -y install docker-ce
root@node01:/opt# docker version
Client: Docker Engine - Community
 Version:           20.10.10
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        b485636
 Built:             Mon Oct 25 07:42:59 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
Engine:
Version: 20.10.10
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: e2f740d
Built: Mon Oct 25 07:41:08 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.11
GitCommit: 5b46e404f6b9f661a205e28d59c982d3634148f8
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0

2.4 安装docker-compose

root@node02:/opt# wget https://github.com/docker/compose/releases/download/v2.1.0/docker-compose-linux-x86_64
root@node02:/opt# mv docker-compose-linux-x86_64 /usr/local/sbin/docker-compose
root@node02:/opt# chmod +x /usr/local/sbin/docker-compose
root@node02:/opt# docker-compose -v
Docker Compose version v2.1.0

三 harbor安装

下载地址:https://github.com/goharbor/harbor/releases

安装文档:https://github.com/goharbor/harbor/blob/master/docs/install-config/_index.md

3.1 下载harbor安装包

3.1.1 下载离线安装包

推荐使用离线安装包

root@node01:~# cd /opt/
root@node01:/opt# wget https://github.com/goharbor/harbor/releases/download/v1.10.9/harbor-offline-installer-v1.10.9.tgz

3.1.2 下载在线安装包

 不推荐在线安装

root@node01:~# cd /opt/
root@node01:/opt# wet https://github.com/goharbor/harbor/releases/download/v1.10.9/harbor-online-installer-v1.10.9.tgz

3.2 配置harbor

3.2.1 解压harbor

root@node01:/opt# tar xf harbor-offline-installer-v1.10.9.tgz -C /usr/local/
root@node01:~# ls -l /usr/local/harbor/
total 585880
-rw-r--r-- 1 root root     11347 Oct 28 13:24 LICENSE
-rw-r--r-- 1 root root      3398 Oct 28 13:24 common.sh
-rw-r--r-- 1 root root 599900167 Oct 28 13:25 harbor.v1.10.9.tar.gz
-rw-r--r-- 1 root root      5882 Oct 28 13:24 harbor.yml
-rwxr-xr-x 1 root root      2284 Oct 28 13:24 install.sh
-rwxr-xr-x 1 root root      1749 Oct 28 13:24 prepare

3.2.2 编辑配置文件

官方配置文档:https://goharbor.io/docs/1.10/install-config/

root@node01:~# vim /usr/local/harbor/harbor.yml 
hostname: 192.168.75.157    #修改此行,指向当前主机IP或FQDN  
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

#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
harbor_admin_password: Harbor12345
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
data_volume: /data/harbor

3.2.3 运行安装脚本

运行install.sh, 注意运行时加上--with-clair 选项,启动clair镜像扫描功能。
ChartMuseum是一个用Go(Golang)编写的开源Helm Chart Repository服务器。

点击查看代码
root@node01:~# mkdir -pv /data/harbor
root@node01:~# mkdir -pv /var/log/harbor
root@node01:~# /usr/local/harbor/install.sh  --with-clair --with-chartmuseum

[Step 0]: checking if docker is installed ...

Note: docker version: 20.10.10

[Step 1]: checking docker-compose is installed ...

Note: docker-compose version: 2.1.0

[Step 2]: loading Harbor images ...
Loaded image: goharbor/harbor-core:v1.10.9
Loaded image: goharbor/harbor-jobservice:v1.10.9
Loaded image: goharbor/notary-signer-photon:v1.10.9
Loaded image: goharbor/nginx-photon:v1.10.9
Loaded image: goharbor/chartmuseum-photon:v1.10.9
Loaded image: goharbor/registry-photon:v1.10.9
Loaded image: goharbor/clair-photon:v1.10.9
Loaded image: goharbor/clair-adapter-photon:v1.10.9
Loaded image: goharbor/prepare:v1.10.9
Loaded image: goharbor/harbor-portal:v1.10.9
Loaded image: goharbor/harbor-db:v1.10.9
Loaded image: goharbor/notary-server-photon:v1.10.9
Loaded image: goharbor/harbor-log:v1.10.9
Loaded image: goharbor/harbor-registryctl:v1.10.9
Loaded image: goharbor/redis-photon:v1.10.9

[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /usr/local/harbor
/usr/src/app/utils/configs.py

标签:node01,goharbor,Harbor,config,harbor,Docker,root,docker,分布式
来源: https://www.cnblogs.com/wangguishe/p/15466771.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有