图解
所有的请求都经过proxy代理,proxy代理转发给Core services和Registry,其中Core services包括UI界面、token令牌和webhook网页服务功能,Registry主要提供镜像存储功能。如果要进行下载上传镜像,要经过token令牌验证然后从Registry获取或上传镜像,每一次下载或上传都会生成日志记录,会记入Log collector,而用户身份权限及一些镜像语言信息会被存储在Database中。
(1)所需参数
修改此参数后,需要运行 install.sh脚本重新安装 Harbour,参数才会生效。
(2)可选参数
这些参数对于更新是可选的,即用户可以将其保留为默认值,并在启动 Harbor 后在 Web UI 上进行更新。
如果进入 Harbor.cfg,只会在第一次启动 Harbor 时生效,随后对这些参数 的更新,Harbor.cfg 将被忽略。
注意:如果选择通过UI设置这些参数,请确保在启动Harbour后立即执行此操作。具体来说,必须在注册或在 Harbor 中创建任何新用户之前设置所需的
auth_mode
harbour_admin_password
auth_mode
self_registration
Token_expiration
project_creation_restriction
verify_remote_cert
另外,默认情况下,Harbour 将镜像存储在本地文件系统上。在生产环境中,可以考虑 使用其他存储后端而不是本地文件系统,如 S3、Openstack Swif、Ceph 等。但需要更新common/templates/registry/config.yml 文件。
案例环境
主机 | 操作系统 | 主机名/IP地址 | 主要软件及版本 |
---|---|---|---|
Harbor(服务端) | Centos 7 | 192.168.10.100 | docker docker-compose harbor-offline-v1.1.2 |
client(客户端) | Centos 7 | 192.168.10.15 | docker |
案例需求
通过Harbor创建Docker私有仓库
使用图形化管理Docker私有仓库镜像
实验准备
在服务端安装docker和docker-compose
客户端上安装docker
关闭防火墙
修改主机名
放入命令压缩包
cp -p docker-compose /usr/local/bin/
chmod +x /usr/local/bin/docker-compose
下载 Harbor 安装程序
Harbor:192.168.10.100
//在线下载
wget http:// harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
//如果在先下载慢,可以使用上面的链接下载,在拖入
tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/
配置 Harbor 参数文件
Harbor:192.168.10.100
vim /usr/local/harbor/harbor.cfg
//第5行
hostname = 192.168.10.100
启动 Harbor
Harbor:192.168.10.100
sh /usr/local/harbor/install.sh
查看 Harbor 启动镜像和容器
Harbor:192.168.10.100
查看镜像
docker images
docker ps -a
#-----------------------------输出内容---------------------------------------
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e2940a0d0c7 vmware/nginx-photon:1.11.13 "nginx -g 'daemon of…" 13 minutes ago Up 13 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx
2aa1257ff3c2 vmware/harbor-jobservice:v1.2.2 "/harbor/harbor_jobs…" 13 minutes ago Up 13 minutes harbor-jobservice
19c8fc2c6e83 vmware/harbor-ui:v1.2.2 "/harbor/harbor_ui" 13 minutes ago Up 13 minutes harbor-ui
8fe0eed3aa85 vmware/registry:2.6.2-photon "/entrypoint.sh serv…" 13 minutes ago Up 13 minutes 5000/tcp registry
ac68e32fac3f vmware/harbor-db:v1.2.2 "docker-entrypoint.s…" 13 minutes ago Up 13 minutes 3306/tcp harbor-db
d8a1d21defc4 vmware/harbor-adminserver:v1.2.2 "/harbor/harbor_admi…" 13 minutes ago Up 13 minutes harbor-adminserver
496ccc523f5d vmware/harbor-log:v1.2.2 "/bin/sh -c 'crond &…" 13 minutes ago Up 13 minutes 127.0.0.1:1514->514/tcp harbor-log
cd /usr/local/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
在UI界面创建项目
宿主机
上图检查一切正常,此时可以打开浏览器访问 http://192.168.10.100 的管理页面,默认的管理员用户名和密码是 admin/Harbor12345。
添加项目并且填写项目名称
在本地测试仓库功能
Harbor:192.168.10.100
登录
docker login -u admin -p Harbor12345 http://127.0.0.1
docker pull nginx
docker tag nginx 127.0.0.1/testproject/nginx:v1
docker push 127.0.0.1/testproject/nginx:v1
在客户端上传镜像
client:192.168.10.15
上述操作都是在 Harbor 服务器本地操作。如果其他客户端上传镜像到 Harbor,就会报
如下错误。出现这问题的原因 Docker Registry 交互默认使用的是 HTTPS,但是搭建私有镜
像默认使用的是 HTTP 服务,所以与私有镜像交互时出现以下错误。
docker login -u admin -p Harbor12345 http://192.168.163.100
#-------------------输出内容------------------------------------------
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.10.100/v2/: dial tcp 192.168.10.100:443: connect: connection refused
解决方法
vim /usr/lib/systemd/system/docker.service
#--------------------修改内容-----------------------------------
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.10.100 --containerd=/run/containerd/containerd.sock
#---------------------------------------------------------------
//重启服务
systemctl daemon-reload
systemctl restart docker
//再次登录
docker login -u admin -p Harbor12345 http://192.168.10.100
#----------------------输出内容--------------------------------------------
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
#--------------------------------------------------------------------
docker pull tomcat
docker images
docker tag tomcat 192.168.10.100/testproject/tomcat:v2
docker push 192.168.10.100/testproject/tomcat:v2
停止现有的 Harbor 实例
docker-compose down -v
#---------------输出内容--------------------
Stopping nginx ... done
Stopping harbor-jobservice ... done
Stopping harbor-ui ... done
Stopping registry ... done
Stopping harbor-db ... done
Stopping harbor-adminserver ... done
Stopping harbor-log ... done
Removing nginx ... done
Removing harbor-jobservice ... done
Removing harbor-ui ... done
Removing registry ... done
Removing harbor-db ... done
Removing harbor-adminserver ... done
Removing harbor-log ... done
Removing network harbor_harbor
vim harbor.cfg
./prepare
#---------------------------输出内容----------------------------
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/app.conf
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/nginx.conf
loaded secret from 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.
docker-compose up -d
#-----------输出内容-----------------------------------
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registry ... done
Creating harbor-adminserver ... done
Creating harbor-db ... done
Creating harbor-ui ... done
Creating harbor-jobservice ... done
Creating nginx ... done
docker rmi 192.168.10.100/testproject/tomcat:v2
#----------------------输出内容-----------------------------
Untagged: 192.168.10.100/testproject/tomcat:v2
Untagged: 192.168.10.100/testproject/tomcat@sha256:8b42182fb220374cc8be73fbf4d9dba5946c9e6cb024c19f8470a27a6557e364
//注销登录
docker logout 192.168.10.100
#------------------输出内容--------------------------------
Removing login credentials for 192.168.10.100
#--------------------------------------------------------
//使用新创建的用户和密码登录私有仓库
docker login 192.168.10.100
#------------------输出内容-------------------------
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
#--------------------------------------------------
//从私有仓库下载镜像
docker pull 192.168.10.100/testproject/nginx:v1
#-----------------------输出内容-----------------------------
v1: Pulling from testproject/nginx
a076a628af6f: Pull complete
0732ab25fa22: Pull complete
d7f36f6fe38f: Pull complete
f72584a26f32: Pull complete
7125e4df9063: Pull complete
Digest: sha256:0b159cd1ee1203dad901967ac55eee18c24da84ba3be384690304be93538bea8
Status: Downloaded newer image for 192.168.10.100/testproject/nginx:v1
192.168.10.100/testproject/nginx:v1
//查看镜像
docker images
#-------------------输出内容---------------------------------
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 040bdb29ab37 2 months ago 649MB
192.168.10.100/testproject/nginx v1 f6d0b4767a6c 2 months ago 133MB
移除 Harbor 服务容器同时保留镜像数据/数据库
在Harbor服务器上操作
docker-compose down -v
Stopping nginx ... done
Stopping harbor-jobservice ... done
Stopping harbor-ui ... done
Stopping registry ... done
Stopping harbor-db ... done
Stopping harbor-adminserver ... done
Stopping harbor-log ... done
Removing nginx ... done
Removing harbor-jobservice ... done
Removing harbor-ui ... done
Removing registry ... done
Removing harbor-db ... done
Removing harbor-adminserver ... done
Removing harbor-log ... done
Removing network harbor_harbor
如需重新部署,需要移除 Harbor 服务容器全部数据
持久数据,如镜像,数据库等在宿主机的/data/目录下,日志在宿主机的
/var/log/Harbor/目录下。
rm -rf /data/database/
rm -rf /data/registry/