目录
一.Harbor简介
二.Harbor私有仓库的部署
三.Harbor的维护管理
harbor背景
harbor的特性
harbor的架构组成
harbor配置文件解析(harbor.cfg)
对于harbor.cfg中有可选参数和所需参数
(1)所需参数,这些参数需要在配置文件Harbor.cfg中配置。
如果用户更新它们并且运行install.sh脚本重新安装Harbor参数将会生效,具体参数如下:
hostname:用于访问用户界面和register服务。它应该是目标机器的IP地址或者完全限定的域名(FQDN)
不能使用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时才应用。
(一些大的网站使用https)
ssl_cert_key:SSL密钥的路劲,仅当协议设置为https时才应用。
secretkey_path:用于复制策略中加密或者解密远程register密码的密钥路径。
(2)可选参数
这些参数对于更新是可选的,即用户可以将其保留为默认值,并且在启动Harbor后再web 界面上进行更新。
如果进入Harbor.cfg,只会再第一次启动harbor时生效,随后对这些参数的更新,harbor.cfg将被忽略
注意:如果选择通过UI设置这些参数,请确保在启动harbor后立即执行此操作。具体来说,必须在注册或者在harbor中
创建任何新的用户之前设置所需的auth_mode。当系统中有用户时(除了默认的admin用户),auth_mode不能被修改。
具体参数如下:
Email:Harbor需要该参数才能向用户发送"密码重置"电子邮件,并且只有在需要该功能时才需要。
但是,在默认情况下SSL连接时没有启用。如果SMTP服务器需要SSL,但是不支持STARTTLS,那么应该通过设置SSL email_ssl=TRUE.
harbor_admin_password:管理员的初始密码,只在harbor第一次启动时生效。之后。此设置将被忽略,并且应该在UI中设置管理员的
密码。此外,默认的用户名、密码分别是 admin、Harbor12345。
auth_mode:使用的认证类型,默认情况下,它是db_auth(验证数据库),即凭据存储在数据库中。对于LDAP身份验证,请将其设置为ldap_auth(目录验证).
self_registration:启用/禁用用户注册功能。禁用时,新用户只能由Admin用户创建,只有管理员用户可以在Harbor中创建新的用户。
注意:当auth_mode设置为ldap_auth时,自动注册功能将处于禁用状态,并且该标志被忽略。
Token_expiration:由令牌服务创建的令牌的到期时间(分钟),默认为30分钟。
project_creation_restriction:用于控制哪些用户有权创建项目的标志。默认情况下,每个人都可以创建一个项目。
如果将其设置为adminonly,那么只有admin可以创建项目。
verify_remote_cert: 打开或者关闭,默认打开。此标志决定了当harbor与远程register实例通信时是否验证SSL/TLS证书。
将此属性设置为off将绕过SSL/TLS验证,这在远程实例具有自签名或不可信证书时经常使用。
此外,默认情况下,harbor将镜像存储在本地文件系统上,在生成环境中,可以考虑使用其他存储后端而不是本地的文件系统。
比如:S3、OpenstackSwif、CEPH、OSS(阿里云)等。但是需要更新common/templates/registry/config.yml文件。
实验环境分析
角色 | IP地址 | 软件包 |
harbor(harbor服务端,用于搭建私有仓库) | 192.168.43.101/24 | docker-ce、Harbor、docker-compose |
client(客户端,用于远程私有仓库) | 192.168.43.102/24 | docker-ce |
部署Harbor服务器
wget http://harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
##解压到/usr/local中
tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/
[root@harbor opt]# cd /usr/local/harbor/
[root@harbor harbor]# ls
common harbor_1_1_0_template LICENSE
docker-compose.clair.yml harbor.cfg NOTICE
docker-compose.notary.yml harbor.v1.2.2.tar.gz prepare
docker-compose.yml install.sh upgrade
[root@harbor ~]# cd /usr/local/harbor/
[root@harbor harbor]# vi harbor.cfg
5 hostname = 192.168.43.101 ##修改为监听本地地址
启动harbor,这里启动harbor会直接调用docker-compose.yml,进行编排容器服务
[root@harbor harbor]# sh /usr/local/harbor/install.sh
[Step 0]: checking installation environment ...
Note: docker version: 19.03.8
Note: docker-compose version: 1.21.1
[Step 1]: loading Harbor images ...
dd60b611baaa: Loading layer 133.2MB/133.2MB
abf0579c40fd: Loading layer 1.536kB/1.536kB
ea1fc7bed9c5: Loading layer 22.48MB/22.48MB
1d6671367c69: Loading layer 7.168kB/7.168kB
b322bb3e4765: Loading layer 5.339MB/5.339MB
0cf512d418ac: Loading layer 9.728kB/9.728kB
4a7cdc0b1a2b: Loading layer 2.56kB/2.56kB
ef1130526636: Loading layer 22.48MB/22.48MB
Loaded image: vmware/harbor-ui:v1.2.2
4a050fccec52: Loading layer 12.16MB/12.16MB
d918d73369ec: Loading layer 17.3MB/17.3MB
22898836924e: Loading layer 15.87kB/15.87kB
Loaded image: vmware/notary-photon:server-0.5.0
76c156eab077: Loading layer 134MB/134MB
1eae6563289a: Loading layer 16.42MB/16.42MB
Loaded image: vmware/nginx-photon:1.11.13
2e814f7ef645: Loading layer 2.048kB/2.048kB
bc5742b580db: Loading layer 2.048kB/2.048kB
5413bcdb81b0: Loading layer 2.56kB/2.56kB
c4e2be066795: Loading layer 3.584kB/3.584kB
a4ea62be60b0: Loading layer 22.8MB/22.8MB
800a351ae5da: Loading layer 22.8MB/22.8MB
Loaded image: vmware/registry:2.6.2-photon
Loaded image: photon:1.0
a39bd6a7f897: Loading layer 10.95MB/10.95MB
6f79b8337a1f: Loading layer 17.3MB/17.3MB
74bbd0e81dd0: Loading layer 15.87kB/15.87kB
Loaded image: vmware/notary-photon:signer-0.5.0
2202528221a2: Loading layer 7.07MB/7.07MB
4fe250d3c912: Loading layer 7.07MB/7.07MB
Loaded image: vmware/harbor-adminserver:v1.2.2
9463fb852970: Loading layer 75.37MB/75.37MB
d2c9a2a395d9: Loading layer 3.584kB/3.584kB
b08aea2a8a82: Loading layer 3.072kB/3.072kB
103e65a1013b: Loading layer 3.072kB/3.072kB
Loaded image: vmware/harbor-log:v1.2.2
5d6cbe0dbcf9: Loading layer 129.2MB/129.2MB
435f2dfbd884: Loading layer 344.6kB/344.6kB
814d7b59f0cc: Loading layer 4.657MB/4.657MB
aae399245bd0: Loading layer 1.536kB/1.536kB
21e2ae955f72: Loading layer 33.84MB/33.84MB
a2d0f7b84059: Loading layer 25.09kB/25.09kB
819fa6af55b8: Loading layer 3.584kB/3.584kB
78914c99a468: Loading layer 167.7MB/167.7MB
36e79c658afb: Loading layer 6.144kB/6.144kB
f73503aca003: Loading layer 9.216kB/9.216kB
a21b39f6da59: Loading layer 1.536kB/1.536kB
ef81eb7c77b3: Loading layer 8.704kB/8.704kB
08d0cfe60b0d: Loading layer 4.608kB/4.608kB
0864dda8f611: Loading layer 4.608kB/4.608kB
Loaded image: vmware/harbor-db:v1.2.2
29d1f4ae97dd: Loading layer 18.31MB/18.31MB
7caf936e1402: Loading layer 18.31MB/18.31MB
Loaded image: vmware/harbor-jobservice:v1.2.2
78dbfa5b7cbc: Loading layer 130.9MB/130.9MB
5f70bf18a086: Loading layer 1.024kB/1.024kB
8deec01122be: Loading layer 344.6kB/344.6kB
574ab36807f2: Loading layer 1.536kB/1.536kB
d8f2cde2eef8: Loading layer 20.48kB/20.48kB
eaa3924b054e: Loading layer 5.12kB/5.12kB
8aa2c772121c: Loading layer 184.3MB/184.3MB
c3014bbccb0b: Loading layer 8.704kB/8.704kB
978a35efaa8c: Loading layer 4.608kB/4.608kB
c2385ae7d6e5: Loading layer 16.6MB/16.6MB
Loaded image: vmware/harbor-notary-db:mariadb-10.1.10
c192a34d4ff4: Loading layer 155.2MB/155.2MB
d012a9276a83: Loading layer 10.75MB/10.75MB
b8befd881cb5: Loading layer 10.75MB/10.75MB
Loaded image: vmware/clair:v2.0.1-photon
bbda1562018e: Loading layer 101.6MB/101.6MB
1171ab08cc04: Loading layer 6.656kB/6.656kB
6df81d3a0683: Loading layer 6.656kB/6.656kB
Loaded image: vmware/postgresql:9.6.4-photon
[Step 2]: preparing environment ...
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.
[Step 3]: checking existing instance of Harbor ...
[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-adminserver ... done
Creating harbor-db ... done
Creating registry ... done
Creating harbor-ui ... done
Creating nginx ... done
Creating harbor-jobservice ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.43.101.
For more details, please visit https://github.com/vmware/harbor .
[root@harbor harbor]#
查看Harbor启动的镜像和容器服务
[root@harbor ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vmware/harbor-log v1.2.2 36ef78ae27df 2 years ago 200MB
vmware/harbor-jobservice v1.2.2 e2af366cba44 2 years ago 164MB
vmware/harbor-ui v1.2.2 39efb472c253 2 years ago 178MB
vmware/harbor-adminserver v1.2.2 c75963ec543f 2 years ago 142MB
vmware/harbor-db v1.2.2 ee7b9fa37c5d 2 years ago 329MB
vmware/nginx-photon 1.11.13 6cc5c831fc7f 2 years ago 144MB
vmware/registry 2.6.2-photon 5d9100e4350e 2 years ago 173MB
vmware/postgresql 9.6.4-photon c562762cbd12 2 years ago 225MB
vmware/clair v2.0.1-photon f04966b4af6c 2 years ago 297MB
vmware/harbor-notary-db mariadb-10.1.10 64ed814665c6 2 years ago 324MB
vmware/notary-photon signer-0.5.0 b1eda7d10640 3 years ago 156MB
vmware/notary-photon server-0.5.0 6e2646682e3c 3 years ago 157MB
photon 1.0 e6e4e4a2ba1b 3 years ago 128MB
[root@harbor ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7b6d0b348275 vmware/nginx-photon:1.11.13 "nginx -g 'daemon of…" 27 seconds ago Up 25 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx
9b4833349bd9 vmware/harbor-jobservice:v1.2.2 "/harbor/harbor_jobs…" 27 seconds ago Up 26 seconds harbor-jobservice
f8ef31935095 vmware/harbor-ui:v1.2.2 "/harbor/harbor_ui" 27 seconds ago Up 27 seconds harbor-ui
7ac3449a49fc vmware/registry:2.6.2-photon "/entrypoint.sh serv…" 29 seconds ago Up 27 seconds 5000/tcp registry
db783fe72ae9 vmware/harbor-adminserver:v1.2.2 "/harbor/harbor_admi…" 29 seconds ago Up 28 seconds harbor-adminserver
3737c444834c vmware/harbor-db:v1.2.2 "docker-entrypoint.s…" 29 seconds ago Up 27 seconds 3306/tcp harbor-db
a4e715830447 vmware/harbor-log:v1.2.2 "/bin/sh -c 'crond &…" 29 seconds ago Up 29 seconds 127.0.0.1:1514->514/tcp harbor-log
//也可以使用docker-compose ps查看容器状态,但是需要在/usr/local/harbor目录下执行
[root@harbor harbor]# pwd
/usr/local/harbor
[root@harbor harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/harbor_adminserver Up
harbor-db docker-entrypoint.sh mysqld Up 3306/tcp
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
[root@harbor harbor]#
镜像在私有仓库的上传与下载
在harbor服务器上上传镜像
docker login -u admin -p Harbor12345 http://127.0.0.1 //登录harbor的字符界面
docker pull cirros //先下载一个镜像
[root@harbor ~]# docker tag cirros 127.0.0.1/myproject/cirros:v1 //修改特定的标签,这个标签不能改,127.0.0.1代表本地地址,myproject指定项目,cirros:v1指定具体镜像名称和版本
[root@harbor ~]# docker push 127.0.0.1/myproject/cirros:v1 //上传镜像到私有仓库
The push refers to repository [127.0.0.1/myproject/cirros]
858d98ac4893: Pushed
aa107a407592: Pushed
b993cfcfd8fd: Pushed
v1: digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a size: 943
[root@harbor ~]#
##这里我们需要注意的是,在harbor服务器上登录、定制tag、上传镜像都需要使用127.0.0.1,而不可以使用192.168.43.101,否则会出现错误
在UI界面查看
在client下载这个镜像,且上传镜像
//先要指定私有仓库的地址
vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// insecure-registry 192.168.43.101 --containerd=/run/containerd/containerd.sock //添加
//重启服务
[root@client ~]# systemctl daemon-reload
[root@client ~]# systemctl restart docker.service
[root@client ~]#
//登录
[root@client ~]# docker login -u admin -p Harbor12345 http://192.168.43.101
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@client ~]#
//在客户端下载上传镜像到私有仓库
//下载
[root@client ~]# docker pull 192.168.43.101/myproject/cirros:v1
v1: Pulling from myproject/cirros
Digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a
Status: Downloaded newer image for 192.168.43.101/myproject/cirros:v1
192.168.43.101/myproject/cirros:v1
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.43.101/myproject/cirros v1 3c82e4d066cf 3 weeks ago 12.6MB
cirros latest 3c82e4d066cf 3 weeks ago 12.6MB
[root@client ~]#
//上传镜像到私有仓库(v1和v2作为区别,且上传镜像的地址必须写harbor服务器的地址)
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.43.101/myproject/cirros v1 3c82e4d066cf 3 weeks ago 12.6MB
cirros latest 3c82e4d066cf 3 weeks ago 12.6MB
[root@client ~]# docker tag cirros:latest 192.168.43.101/myproject/cirros:v2
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.43.101/myproject/cirros v1 3c82e4d066cf 3 weeks ago 12.6MB
192.168.43.101/myproject/cirros v2 3c82e4d066cf 3 weeks ago 12.6MB
cirros latest 3c82e4d066cf 3 weeks ago 12.6MB
[root@client ~]# docker push 192.168.43.101/myproject/cirros:v2
The push refers to repository [192.168.43.101/myproject/cirros]
858d98ac4893: Layer already exists
aa107a407592: Layer already exists
b993cfcfd8fd: Layer already exists
v2: digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a size: 943
[root@client ~]#
在UI界面查看
1.//关闭所有容器
[root@harbor harbor]# pwd
/usr/local/harbor
[root@harbor harbor]# docker-compose down -v
Stopping nginx ... done
Stopping harbor-jobservice ... done
Stopping harbor-ui ... done
Stopping registry ... done
Stopping harbor-adminserver ... done
Stopping harbor-db ... done
Stopping harbor-log ... done
Removing nginx ... done
Removing harbor-jobservice ... done
Removing harbor-ui ... done
Removing registry ... done
Removing harbor-adminserver ... done
Removing harbor-db ... done
Removing harbor-log ... done
Removing network harbor_harbor
[root@harbor harbor]#
2.修改配置文件
[root@harbor harbor]# pwd
/usr/local/harbor
[root@harbor harbor]# vi harbor.cfg ##修改配置参看现实需求
[root@harbor 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@harbor harbor]# ./prepare ##重新加载配置文件
systemctl restart docker ##重启docker服务
docker-compose up -d ##启动容器服务,此处需要防火墙开启,否则开启错误
[root@harbor harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/harbor_adminserver Up
harbor-db docker-entrypoint.sh mysqld Up 3306/tcp
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
[root@harbor harbor]#
//先退出已登陆的账号
[root@client ~]# docker logout http://192.168.43.101
Removing login credentials for 192.168.43.101
[root@client ~]#
//使用新的账户登录
[root@client ~]# docker login http://192.168.43.101
Username: zhangsan
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 ~]#
//下载harbor仓库内的镜像
[root@client ~]# docker pull 192.168.43.101/myproject/cirros:v1
v1: Pulling from myproject/cirros
f513001ba4ab: Pull complete
8da581cc9286: Pull complete
856628d95d17: Pull complete
Digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a
Status: Downloaded newer image for 192.168.43.101/myproject/cirros:v1
192.168.43.101/myproject/cirros:v1
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.43.101/myproject/cirros v1 3c82e4d066cf 3 weeks ago 12.6MB
[root@client ~]#
//上传镜像
因为我把zhangsan这个用户的角色调整为访客,而访客是没有权限上传镜像的
//如果要移除Harbor服务器同时保留数据/数据库
//先要在harbor服务器上操作,关闭所有工作容器服务,再做其他操作
docker-compose down -v
//如果需要重新部署,需要移除Harbor服务器全部数据
[root@harbor harbor]# cd /var/log/harbor/ ##harbor服务器的相关日志
[root@harbor harbor]# ls
2020-04-02
[root@harbor harbor]# cd /data/ ##持久化数据,如镜像、数据库等在harbor的/data目录下
[root@harbor data]# ls
ca_download config database job_logs psc registry secretkey
[root@harbor data]#
//如果删除持久化数据,需要先关闭容器
cd /usr/local/harbor
docker-compose down -v
rm -rf /data/database/ /data/registry/