Harbor 简介
Harbor 是由 VMware 公司中国团队为企业用户设计的 Registry server 开源项目,包括了权限管理(RBAC)、LDAP、审计、管理界面、自我注册、HA 等企业必需的功能,同时针对中国用户的特点,设计镜像复制和中文支持等功能。
作为一个企业级私有 Registry 服务器,Harbor 提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor 支持安装在多个 Registry 节点的镜像资源复制,镜像全部保存在私有 Registry 中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor 也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。
基于角色的访问控制 - 用户与 Docker 镜像仓库通过"项目"进行组织管理,一个用户可以对多个镜像仓库在同一命名空间(project)里有不同的权限。
镜像复制 - 镜像可以在多个 Registry 实例中复制(同步)。尤其适合于负载均衡,高可用,混合云和多云的场景。
图形化用户界面 - 用户可以通过浏览器来浏览,检索当前 Docker 镜像仓库,管理项目和命名空间。
AD/LDAP 支持 - Harbor 可以集成企业内部已有的 AD/LDAP,用于鉴权认证管理。
审计管理 - 所有针对镜像仓库的操作都可以被记录追溯,用于审计管理。
国际化 - 已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。
RESTful API - RESTful API 提供给管理员对于 Harbor 更多的操控, 使得与其它管理软件集成变得更容易。
部署简单 - 提供在线和离线两种安装工具,也可以安装到 vSphere 平台(OVA 方式)虚拟设备。
项目介绍
优点:
本身自带 docker 私有仓库
支持基于角色的权限管理
支持 LDAP
安装
OS:Centos 7.8
前置条件
1)需要安装docker并运行,详情参考之前的文章
2)需要安装docker-compose
yum -y install docker-compose
如果提示没有可用的软件包则需自行手动下载安装
https://github.com/docker/compose/releases/
这里选择下载1.29.2版本
下载到linux终端
curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
下载完成后并授予执行权限
chmod 755 docker-compose
执行命令
[root@localhost ~]# docker-compose --version
docker-compose version 1.29.2, build 5becea4c
有输出结果即为安装成功
一、下载Harbor安装包,版本为1.10.3
[root@localhost ~]# wget https://github.com/goharbor/harbor/releases/download/v2.3.0/harbor-offline-installer-v2.3.0.tgz
二、解压
[root@localhost ~]# tar xf harbor-offline-installer-v2.3.0.tgz
三、安装
[root@localhost ~]# cd harbor
# 修改hostname
注意:如果是高版本的没有harbor.yml,有个harbor.yml.tmpl,需要将其修改后重命名为harbor.yml
[root@localhost ~]# vim harbor.yml
将hostname改成你本机IP即可
# 注释https,不然在安装的时候会报错:
ERROR:root:Error: The protocol is https but attribute ssl_cert is not set
其他配置保持默认
[root@localhost harbor]# ./install.sh
由于我这边将前边的jenkins、gitlab和现在的Harbor都装在一台机器上了,所以在执行./install.sh的时候在step5中出现了报错,因为Harbor会依赖自带创建的nginx,gitlab也会依赖自带创建的nginx。
要不然就需要修改一些乱七八糟的配置文件,要不然就新搞一台机子继续搞,我这里选择妥协新建了一台机子来搞。
在新的机器上安装完docker,docker-compose后下载Harbor的压缩包并解压后修改harbor.yml.tmpl下的相应配置后并重命名为harbor.yml后执行install.sh(有人说需要先执行prepare文件在执行install.sh,其实都一样,只不过prepare是一个准备工作)
./install.sh
当出现许多绿色的“done”和successfully字样的时候就是安装成功了,即可通过浏览器输入:http://localhost 访问
首次登录需要账号密码,默认的账号密码为:admin/Harbor12345
当出现如下界面时即为登录成功。
在终端查看Harbor的状态
[root@localhost harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------
harbor-core /harbor/entrypoint.sh Up (healthy)
harbor-db /docker-entrypoint.sh 96 13 Up (healthy)
harbor-jobservice /harbor/entrypoint.sh Up (healthy)
harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up (healthy)
nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp,:::80->8080/tcp
redis redis-server /etc/redis.conf Up (healthy)
registry /home/harbor/entrypoint.sh Up (healthy)
registryctl /home/harbor/start.sh Up (healthy)
# 配置客户端信任http
由于从docker1.3.2版本开始,使用registry时,必须使用TLS保证其安全。我们不用https的话,需要在客户端中增加一个配置文件。
[root@localhost ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["http://192.168.6.13:5000"]
}
{
“insecure-registries”:[“192.168.6.13:5000”]
}
# 重启Docker
[root@localhost ~]# systemctl restart docker
# 客户端登录Harbor
[root@localhost ~]# docker login -u admin -p Harbor12345 192.168.6.13
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.6.13/v2/: dial tcp 192.168.6.13:443: connect: connection refused
# 客户端修改docker.service
先查找docker.service 所在的位置
[root@localhost ~]# find / -name docker.service
/sys/fs/cgroup/memory/system.slice/docker.service
/sys/fs/cgroup/pids/system.slice/docker.service
/sys/fs/cgroup/blkio/system.slice/docker.service
/sys/fs/cgroup/devices/system.slice/docker.service
/sys/fs/cgroup/cpu,cpuacct/system.slice/docker.service
/sys/fs/cgroup/systemd/system.slice/docker.service
/usr/lib/systemd/system/docker.service
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service
在ExecStart后面加入--insecure-registry=192.168.6.13,如下:
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.6.13 --containerd=/run/containerd/containerd.sock
# 重新启动服务并登录Harbor私有仓库,当出现Login Succeeded时即为登录成功
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl reload docker
[root@localhost ~]# docker login -u admin -p Harbor12345 192.168.6.13
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@localhost ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
打标签并查看打完标签后的镜像
[root@localhost ~]# docker tag hello-world 192.168.6.3/library/hello-world:v1
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.6.13/library/hello-world v1 d1165f221234 3 months ago 13.3kB
hello-world latest d1165f221234 3 months ago 13.3kB
# 推送到Harbor
[root@localhost ~]# docker push 192.168.6.13/library/hello-world:v1
The push refers to repository [192.168.6.13/library/hello-world]
f22b99068db9: Pushed
v1: digest: sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792 size: 525
# 查看Harbor
显示已经成功上传了。
# 删除本地的镜像,从Harbor上pull
[root@localhost ~]# docker rmi -f d1165f221234
Untagged: 192.168.6.13/library/hello-world:v1
Untagged: 192.168.6.13/library/hello-world@sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792
Untagged: 192.168.6.3/library/hello-world:v1
Untagged: hello-world:latest
Untagged: hello-world@sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
# 从Harbor上pull镜像
[root@localhost ~]# docker pull 192.168.6.13/library/hello-world:v1
v1: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792
Status: Downloaded newer image for 192.168.6.13/library/hello-world:v1
192.168.6.13/library/hello-world:v1
# 查看镜像
当出现镜像时,docker私有仓库Harbor即为搭建成功
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.6.13/library/hello-world v1 d1165f221234 3 months ago 13.3kB