Harbor 被部署为多个 Docker 容器,因此可以部署在任何支持 Docker 的 Linux 发行版 上。
服务端主机需要安装 Python、Docker 和 Docker Compose。
关于 Harbor.cfg 配置文件中有两类参数:所需参数和可选参数
所需参数
- 这些参数需要在配置文件 Harbor.cfg 中设置。
- 如果用户更新它们并运行 install.sh脚本重新安装 Harbour,
参数将生效。具体参数如下:
hostname | 用于访问用户界面和 register 服务。它应该是目标机器的 IP 地址或完全限 定的域名(FQDN)例如 192.168.195.128 或 hub.kgc.cn。不要使用 localhost 或 127.0.0.1 为主机名 |
ui_url_protocol | (http 或 https,默认为 http)用于访问 UI 和令牌/通知服务的协议。如果公证处于启用状态,则此参数必须为 https。 |
max_job_workers | 镜像复制作业线程。 |
db_password | 用于db_auth 的MySQL数据库root 用户的密码。 |
customize_crt | 该属性可设置为打开或关闭,默认打开。打开此属性时,准备脚本创建私钥和根证书,用于生成/验证注册表令牌。当由外部来源提供密钥和根证书时,将此属性设置为 off。 |
ssl_cert | SSL 证书的路径,仅当协议设置为 https 时才应用。 |
ssl_cert_key | SSL 密钥的路径,仅当协议设置为 https 时才应用。 |
secretkey_path | 用于在复制策略中加密或解密远程 register 密码的密钥路径。 |
可选参数
- 这些参数对于更新是可选的,即用户可以将其保留为默认值,并在启动 Harbor 后在 Web UI 上进行更新。
- 如果进入 Harbor.cfg,只会在第一次启动 Harbor 时生效,随后对这些参数 的更新,Harbor.cfg 将被忽略。
注意:如果选择通过UI设置这些参数,请确保在启动Harbour后立即执行此操作。具体来说,必须在注册或在 Harbor 中创建任何新用户之前设置所需的auth_mode。当系统中有用户时(除了默认的 admin 用户),auth_mode 不能被修改。
具体参数如下:
Email | Harbor需要该参数才能向用户发送“密码重置”电子邮件,并且只有在需要该功能时才需要。 | 请注意,在默认情况下SSL连接时没有启用。如果SMTP服务器需要SSL,但不支持STARTTLS,那么应该通过设置启用SSL email_ssl = TRUE。 |
harbour_admin_password | 管理员的初始密码,只在Harbour第一次启动时生效。之后,此设置将被忽略,并且应 UI中设置管理员的密码。 | 请注意,默认的用户名/密码是 admin/Harbor12345。 |
auth_mode | 使用的认证类型,默认情况下,它是 db_auth,即凭据存储在数据库中。对于LDAP身份验证,请将其设置为 ldap_auth。 | |
self_registration | 启用/禁用用户注册功能。禁用时,新用户只能由 Admin 用户创建,只有管理员用户可以在 Harbour中创建新用户 | 注意当 auth_mode 设置为 ldap_auth 时,自注册功能将始终处于禁用状态,并且该标志被忽略。 |
Token_expiration | 由令牌服务创建的令牌的到期时间(分钟),默认为 30 分钟。 | |
project_creation_restriction | 用于控制哪些用户有权创建项目的标志。默认情况下, 每个人都可以创建一个项目。 | 如果将其值设置为“adminonly”,那么只有 admin 可以创建项目。 |
verify_remote_cert | 打开或关闭,默认打开。此标志决定了当Harbor与远程 register 实例通信时是否验证 SSL/TLS 证书。将此属性设置为 off 将绕过 SSL/TLS 验证,这在远程实例具有自签名或不可信证书时经常使用。 | 另外,默认情况下,Harbour 将镜像存储在本地文件系统上。在生产环境中,可以考虑 使用其他存储后端而不是本地文件系统,如 S3、Openstack Swif、Ceph 等。但需要更新 common/templates/registry/config.yml 文件。 |
搭建Harbor
环境
IP地址 | 所需环境 |
20.0.0.10 | Docker-compose3、Harbor |
20.0.0.20 | Docker-ce |
查看Docker-compose版本需要版本三
[root@server1 ~]# docker-compose version
docker-compose version 1.21.1, build 5a3f1a3
docker-py version: 3.3.0
CPython version: 3.6.5
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
安装Harbor
将安装包拖入root下,解压到指定目录
[root@server1 ~]# tar zxf harbor-offline-installer-v1.2.2.tgz -C /usr/local
[root@server1 ~]# vim /usr/local/harbor/harbor.cfg
hostname = 20.0.0.10
[root@server1 ~]# cd /usr/local/harbor/
[root@server1 harbor]# ls -lh
总用量 516M
-rwxr-xr-x. 1 root root 5.3K 10月 20 2017 install.sh
[root@server1 harbor]# ./install.sh
✔ ----Harbor has been installed and started successfully.----
输入IP查看Harbor首页
- 用户名:admin
- 密码:Harbor12345
查看Harbor启动镜像及容器
[root@server1 harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx web a2a3ec303c94 6 days ago 267MB
<none> <none> ed426aa87a0a 6 days ago 0B
nginx latest bc9a0695f571 6 days ago 133MB
centos 7 8652b9f0cb4c 2 weeks ago 204MB
vmware/harbor-log v1.2.2 36ef78ae27df 3 years ago 200MB
vmware/harbor-jobservice v1.2.2 e2af366cba44 3 years ago 164MB
vmware/harbor-ui v1.2.2 39efb472c253 3 years ago
[root@server1 harbor]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6cd9ad8e1d11 vmware/harbor-jobservice:v1.2.2 "/harbor/harbor_jobs…" 3 minutes ago Up 3 minutes harbor-jobservice
18a81e6cf148 vmware/nginx-photon:1.11.13 "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx
f22f34d50e98 vmware/harbor-ui:v1.2.2 "/harbor/harbor_ui" 3 minutes ago Up 3 minutes harbor-ui
c1f681c55306 vmware/harbor-db:v1.2.2 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp harbor-db
f2938e20df8f vmware/registry:2.6.2-photon "/entrypoint.sh serv…" 3 minutes ago Up 3 minutes 5000/tcp registry
6a6654d4fb32 vmware/harbor-adminserver:v1.2.2 "/harbor/harbor_admi…" 3 minutes ago Up 3 minutes harbor-adminserver
[root@server1 harbor]# docker-compose ps
Name Command State Ports
------------------------------------------------------------------------------------
harbor-adminserver /harbor/harbor_adminserver Up
harbor-db docker-entrypoint.sh Up 3306/tcp
mysqld
harbor-jobservice /harbor/harbor_jobservice Up
harbor-log /bin/sh -c crond && rm -f Up 127.0.0.1:1514->514/tcp
...
harbor-ui /harbor/harbor_ui Up
nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp,
0.0.0.0:4443->4443/tcp,
0.0.0.0:80->80/tcp
registry /entrypoint.sh serve /etc/ Up 5000/tcp
...
登录Harbor官网并管理
服务器登录Harbor下载并打包上传到新建库中
root@server1 harbor]# docker login -u admin -p Harbor12345 http://127.0.0.1
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@server1 harbor]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
Digest: sha256:6b1daa9462046581ac15be20277a7c75476283f969cb3a61c8725ec38d3b01c3
Status: Image is up to date for nginx:latest
docker.io/library/nginx:latest
[root@server1 harbor]# docker tag nginx 127.0.0.1/nvdia/nginx:v1
[root@server1 harbor]# docker push 127.0.0.1/nvdia/nginx:v1
The push refers to repository [127.0.0.1/nvdia/nginx]
7e914612e366: Pushed
f790aed835ee: Pushed
850c2400ea4d: Pushed
7ccabd267c9f: Pushed
f5600c6330da: Pushed
v1: digest: sha256:99d0a53e3718cef59443558607d1e100b325d6a2b678cd2a48b05e5e22ffeb49 size: 1362
默认客户机无法登录Harbor以下是解决方案
[root@server2 ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 20.0.0.10 --containerd=/run/containerd/containerd.sock
[root@server2 ~]# systemctl daemon-reload
[root@server2 ~]# systemctl restart docker
[root@server2 ~]# docker login -u admin -p Harbor12345 http://20.0.0.10
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@server2 ~]# docker pull tomcat
[root@server2 ~]# docker tag tomcat 20.0.0.10/nvdia/tomcat:v1
[root@server2 ~]# docker push 20.0.0.10/nvdia/tomcat:v1
The push refers to repository [20.0.0.10/nvdia/tomcat]
3be17d77a93a: Pushed
a84354b89db3: Pushed
438ec47051c4: Pushed
94982bbe98d5: Pushed
39341dafb261: Pushed
4b9227ba273c: Pushed
712264374d24: Pushed
475b4eb79695: Pushed
f3be340a54b9: Pushed
114ca5b7280f: Pushed
v1: digest: sha256:4527a552568f7d706173d8065278cd1abaa7edce186a149a5a2de251e12e6c3c size: 2421
刷新网页并查看
Harbor基本管理命令
停止现有的 Harbor 实例(服务器端)
[root@server1 harbor]# docker-compose down -v
更新 Harbor.cfg
[root@server1 harbor]# ls
common docker-compose.yml harbor.v1.2.2.tar.gz NOTICE
docker-compose.clair.yml harbor_1_1_0_template install.sh prepare
docker-compose.notary.yml harbor.cfg LICENSE upgrade
[root@server1 harbor]# vim harbor.cfg
运行 prepare 脚本来填充配置
[root@server1 harbor]# ./prepare
The configuration files are ready, please use docker-compose to start the service.
重新创建并启动 Harbor 的实例
[root@localhost harbor]# docker-compose up -d
如果出现如下报错:
Creating network "harbor_harbor" with the default driver
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables -- wait -t nat -I DOCKER -i br-25094fc09b3c -j RETURN: iptables: No chain/target/match by that name.
(exit status 1))
解决方法:关闭防火墙后, 解决:关闭防火墙后, docker需要重启
systemctl restart docker
docker-compose up -d
[root@server1 harbor]# docker-compose up -d
harbor-log is up-to-date
harbor-db is up-to-date
Recreating harbor-adminserver ...
Recreating harbor-adminserver ... done
Recreating harbor-ui ... done
Recreating harbor-jobservice ... done
Recreating nginx ... done
[root@server1 harbor]#
在客户端使用新创建的开发人员用户登录并下载镜像
[root@server2 ~]# docker login http://20.0.0.10
Username: zz
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@server2 ~]# docker pull 20.0.0.10/nvdia/nginx:v1
[root@server2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
20.0.0.10/nvdia/nginx v1 bc9a0695f571 6 days ago 133MB
20.0.0.10/nvdia/tomcat v1 e0bd8b34b4ea 12 days ago 649MB
tomcat latest e0bd8b34b4ea 12 days ago 649MB
[root@server2 ~]#