CentOS 7.3部署Harbor镜像仓库(4)

#"docker-compose"可以对harbor服务整个生命周期进行管理; #必须在"docker-compose.yml"文件所在目录执行相关操作 [root@harbor ~]# cd /usr/local/src/harbor [root@harbor harbor]# docker-compose stop | start | restart

2. 修改harbor.cfg的操作

#停止服务 [root@harbor ~]# cd /usr/local/src/harbor [root@harbor harbor]# docker-compose -v #修改harbor.cfg文件 [root@harbor harbor]# vim harbor.cfg #运行prepare脚本更新配置 [root@harbor harbor]# ./prepare #重启服务 [root@harbor harbor]# docker-compose up -d

3. 移除harbor服务容器同时保留镜像数据/数据库

[root@harbor harbor]# docker-compose down -v

4. 移除harbor服务容器全部数据(重新部署时采用)

#持久数据,如镜像,数据库等在宿主机的/data/目录下; #日志在宿主机的/var/log/harbor/目录下 [root@harbor harbor]# rm -r /data/database [root@harbor harbor]# rm -r /data/registry

五.Harbor mirror registry

Mirror是registry的一种特殊类型,起到类似代理服务器的缓存作用,在docker hub与client之间做镜像的缓存。

基本工作原理:client pull 1个镜像时,若镜像在mirror服务器存在,则直接从mirror服务器拉取;若不存在则由mirror服务器自动代理从docker hub(可配置)中拉取镜像,并缓存到mirror服务器中;当client再次拉取这个镜像时,直接从mirror服务器中拉取,不需要再次从docker hub中拉取。

1. 配置mirror server

#修改在解压目录中”common/templates/registry/config.yml”,在最后追加“proxy”字段; #在运行“./prepare”之前做追加操作 [root@harbor ~]# cd /usr/local/src/harbor [root@harbor harbor]# vim common/config/registry/config.yml proxy: remoteurl: https://registry-1.docker.io #如果访问私有仓库,需要带上docker hub(指定的仓库)的账号/密码 #username: [username] #password: [password]

2. 重启harbor服务

#不执行“./prepare” [root@harbor ~]# cd /usr/local/src/harbor [root@harbor harbor]# docker-compose stop [root@harbor harbor]# docker-compose rm -f [root@harbor harbor]# docker-compose up -d

CentOS 7.3部署Harbor镜像仓库

3. 修改客户端docker启动参数

#修改docker启动文件”[service]”字段 [root@test ~]# vim /usr/lib/systemd/system/docker.service [Service] EnvironmentFile=/etc/sysconfig/docker ExecStart=/usr/bin/dockerd $OPTIONS #定义启动参数,添加“--registry-mirror”“--insecure-registry”参数 [root@test ~]# vim /etc/sysconfig/docker OPTIONS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --registry-mirror=http://10.11.51.71 --insecure-registry 10.11.51.71" #重启docker服务 [root@test ~]# systemctl restart docker

4. 验证 1)client拉取镜像

#在client服务器拉取镜像,108Mb的nginx镜像用时36min左右; #虽然宿主机有做加速处理,但做harbor registry的容器没有加速,所以时间较长 [root@test ~]# date ; docker pull nginx ; date

CentOS 7.3部署Harbor镜像仓库

#在client删除nginx镜像,再拉取1次,时间缩短到11min,证明mirror缓存生效; #效果依然不理想,但的确是生效了 [root@test ~]# docker rmi nginx [root@test ~]# date ; docker pull nginx ; date

CentOS 7.3部署Harbor镜像仓库

 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d9d4d63f716c790dbdd759985683bcec.html