它的功能如下
Harbor的特点
harbor.cfg
所需参数:修改参数数,服务需要重新安装
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:镜像复制作业线程
customize_crt:该属性可设置为打开或关闭,默认打开。打开此属性时,准备脚本创建私钥和根证书,用于生成/验证注册表令牌。
当由外部来源提供密钥和根证书时,将此属性设置为 off。
db_password:用于db_auth 的MySQL数据库root 用户的密码。
ssl_cert:SSL 证书的路径,仅当协议设置为 https 时才应用。
ssl_cert_key:SSL 密钥的路径,仅当协议设置为 https 时才应用。
secretkey_path:用于在复制策略中加密或解密远程 register 密码的密钥路径。
可选参数:修改参数时,服务重启即可使用
Email:Harbor需要该参数才能向用户发送“密码重置”电子邮件,并且只有在需要该功能时才需要。
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 验证,这在远程实例具有自签名或不可信证书时经常使用。
角色 | IP | 需要安装的服务 |
服务端(创建私有仓库) | 192.168.179.160 | Docker-ce,Docker Compose,Harbor |
客户端(登录仓库上传和下载镜像) | 192.168.179.170 | Docker-ce |
下载harbor和docker-compose
[root@localhost mnt]# wget http:// harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
[root@localhost mnt]# curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
赋予执行权限
[root@localhost mnt]#chmod +x /usr/bin/docker-compose
安装harbor
[root@localhost mnt]# tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/
修改配置文件
[root@localhost opt]# vim /usr/local/harbor/harbor.cfg
#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 = 192.168.179.169 不可以更改为localhost和127.0.0.1
启动Harbor
[root@localhost local]# sh /usr/local/harbor/install.sh
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-adminserver ... done
Creating registry ... done
Creating harbor-db ... done
Creating harbor-ui ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.179.169.
For more details, please visit https://github.com/vmware/harbor .
[root@localhost local]# 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 3 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@localhost local]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9418f5f8a6a vmware/nginx-photon:1.11.13 "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx
7c4ef6f41c22 vmware/harbor-jobservice:v1.2.2 "/harbor/harbor_jobs…" About a minute ago Up About a minute harbor-jobservice
b5c7abcd6d9f vmware/harbor-ui:v1.2.2 "/harbor/harbor_ui" About a minute ago Up About a minute harbor-ui
5727a1eb2131 vmware/harbor-db:v1.2.2 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp harbor-db
e251117237ca vmware/harbor-adminserver:v1.2.2 "/harbor/harbor_admi…" About a minute ago Up About a minute harbor-adminserver
7293689ae82a vmware/registry:2.6.2-photon "/entrypoint.sh serv…" About a minute ago Up About a minute 5000/tcp registry
68defca3bf25 vmware/harbor-log:v1.2.2 "/bin/sh -c 'crond &…" About a minute ago Up About a minute 127.0.0.1:1514->514/tcp harbor-log
查看配置文件中的默认用户名密码
[root@localhost local]# vim /usr/local/harbor/harbor.cfg
##The initial password of Harbor admin, only works for the first time when Harbor starts.
#It has no effect after the first launch of Harbor.
#Change the admin password from UI after launching Harbor.
harbor_admin_password = Harbor12345
用户名为admin,密码是Harbor12345
[root@localhost local]# 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@localhost local]# docker pull cirros
[root@localhost local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cirros latest 3c82e4d066cf 6 weeks ago 12.6MB
更改标签
[root@localhost local]# docker tag cirros:latest 127.0.0.1/mydocker-db/cirros:v1
[root@localhost local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1/mydocker-db/cirros v1 3c82e4d066cf 6 weeks ago 12.6MB
上传镜像到Harbor仓库中
[root@localhost local]# docker push 127.0.0.1/mydocker-db/cirros:v1
The push refers to repository [127.0.0.1/mydocker-db/cirros]
858d98ac4893: Pushed
aa107a407592: Pushed
b993cfcfd8fd: Pushed
v1: digest: sha256:c7d58d6d463247a2540b8c10ff012c34fd443426462e891b13119a9c66dfd28a size: 943
[root@client docker]# docker login -u admin -p Harbor12345 http://192.168.179.169
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.179.169/v2/: dial tcp 192.168.179.169:443: connect: connection refused
登录失败
如果其他客户端上传镜像到 Harbor,就会报 如下错误。出现这问题的原因 Docker Registry 交互默认使用的是 HTTPS,但是搭建私有镜 像默认使用的是 HTTP 服务,所以与私有镜像交互时出现以下错误。
解决方法
[root@client docker]# vim /usr/lib/systemd/system/docker.service
重启服务
[root@client docker]# systemctl daemon-reload
[root@client docker]# systemctl restart docker
登录私有仓库
[root@client docker]# docker login -u admin -p Harbor12345 http://192.168.179.169
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 docker]# docker pull nginx
[root@client docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 602e111c06b6 14 hours ago 127MB
更改标签上传镜像
[root@client docker]# docker tag nginx:latest 192.168.179.169/mydocker-db/nginx:v1
[root@client docker]# docker push 192.168.179.169/mydocker-db/nginx
The push refers to repository [192.168.179.169/mydocker-db/nginx]
b3003aac411c: Pushed
216cf33c0a28: Pushed
c2adabaecedb: Pushed
v1: digest: sha256:cccef6d6bdea671c394956e24b0d0c44cd82dbe83f543a47fdc790fadea48422 size: 948
修改 Harbor.cfg 配置文件
要更改 Harbour 的配置文件时,请先停止现有的 Harbour 实例并更新 Harbor.cfg;然
后运行 prepare 脚本来填充配置;最后重新创建并启动 Harbour 的实例。