搭建背景
企业环境中使用 Docker 环境, 一般出于安全考虑, 业务使用的镜像一般不会从第三方公共仓库下载. 那么就要引出今天的主题
企业级环境中基于 Harbor 搭建自己的安全认证仓库
介绍
名称: Harbor
官网: https://github.com/vmware/harbor
简介: Harbor 是一个用于存储和分发 Docker 镜像的企业级 Registry 服务器, 通过添加一些企业必需的功能特性, 例如安全, 标识和管理等, 扩展了开源 Docker Distribution. 作为一个企业级私有 Registry 服务器, Harbor 提供了更好的性能和安全. 提升用户使用 Registry 构建和运行环境传输镜像的效率. Harbor 支持安装在多个 Registry 节点的镜像资源复制, 镜像全部保存在私有 Registry 中, 确保数据和知识产权在公司内部网络中管控. 另外, Harbor 也提供了高级的安全特性, 诸如用户管理, 访问控制和活动审计等.
部署 Harbor
Harbor 是基于 Docker-Compose 进行编排的, 需要配合 Docker 和 Docker-compose 使用. Docker 的安装可以看我的另一篇文章
下载 Docker-Compose 最新稳定版
[root@harbor-01 hub]# pwd/opt/hub[root@harbor-01 hub]# curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
ps: 可能会报错 Peer reports incompatible or unsupported protocol version., 升级下 curl 就行
添加可执行权限
[root@harbor-01 hub]# chmod +x /usr/local/bin/docker-compose
验证版本
[root@harbor-01 hub]# docker-compose -vdocker-compose version 1.23.2, build 1110ad01
解压安装包
[root@harbor-01 hub]# ls-rw-r--r-- 1 root root 541535889 Mar 4 18:52 harbor-offline-installer-v1.7.3.tgz[root@harbor-01 hub]# tar xf harbor-offline-installer-v1.7.3.tgz
修改配置
主要修改 hostname 字段配置
[root@harbor-01 hub]# cd harbor/[root@harbor-01 hub]# VIM harbor.cfghostname = hub.test.tech # 本机外网 IP 或域名, 该地址供用户通过 UI 进行访问, 不要使用 127.0.0.1ui_url_protocol = http # 用户访问私仓时使用的协议, 默认时 httpdb_password = root123 # 指定 MySQL 数据库管理员密码 harbor_admin_password:Harbor12345 # harbor 的管理员账户密码
通过官方一键脚本安装
[root@harbor-01 hub]#./install.sh......[Step 4]: starting Harbor ...Creating network "harbor_harbor" with the default driverCreating harbor-log ... doneCreating harbor-db ... doneCreating registryctl ... doneCreating registry ... doneCreating harbor-adminserver ... doneCreating Redis ... doneCreating harbor-core ... doneCreating harbor-portal ... doneCreating harbor-jobservice ... doneCreating nginx ... done ----Harbor has been installed and started successfully.----Now you should be able to visit the admin portal at http://hub.test.tech. For more details, please visit https://github.com/goharbor/harbor .
测试登陆
[root@harbor-01 harbor]# docker login hub.test.techUsername: adminPassword: WARNING! Your password will be stored unencrypted in /root/.docker/config.JSON.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
在 Windows 上用域名访问需要绑定下 hosts 即可
默认账号密码 admin Harbor12345
使用
我这里创建个 mytest 的公开项目做测试 (不使用默认的 library). 公开项目 pull 不需要登录, push 需要登录
接下来我们试下推个镜像到 Harbor 的 mytest 项目中, 这里我以公共镜像 goharbor/nginx-photon:v1.7.3 镜像为例 , 需要注意的是要往私有仓库推镜像就得打个 tag 才行 指明要推往哪个仓库并标注标签
注意: 我这里使用的这个域名是自定义的, 那么需要在需要上传下载镜像的机器上添加 hosts 绑定, 因为我这没开启 https 所有也要修改 docker 配置
[root@harbor-01 ~]# cat /etc/docker/daemon.JSON {"insecure-registries": ["hub.test.tech"]}
重启 docker 即可
[root@harbor-01 harbor]# docker images|grep nginx-photongoharbor/nginx-photon v1.7.3 9d8222585538 3 weeks ago 35.6MB[root@hub harbor]# docker tag goharbor/nginx-photon:v1.7.3 hub.test.tech/mytest/nginx-photon:v1[root@harbor-01 harbor]# docker push hub.test.tech/mytest/nginx-photon:v1The push refers to repository [hub.test.tech/mytest/nginx-photon]f08bfdb20f6f: Pushed 8e45c790c209: Pushed v1: digest: sha256:03d473217d79c40c3b4e0d6015098f8d16364707980e12b5e7330ac76938d16a size: 739
可以看到 push 成功, 我们去页面上看看
pull 演示
点击镜像详情可以看到具体标签版本, 鼠标放在 "pull 命令" 图标上可以获取命令
[root@harbor-01 harbor]# docker pull hub.test.tech/mytest/nginx-photon:v1v1: Pulling from mytest/nginx-photonDigest: sha256:03d473217d79c40c3b4e0d6015098f8d16364707980e12b5e7330ac76938d16aStatus: Downloaded newer image for hub.test.tech/mytest/nginx-photon:v1
本篇介绍了 Harbor 的基本部署和使用, 更多高级使用方法后续会分享. 下一章介绍部署 Etcd 集群, 敬请期待, 谢谢!
往期文章一览
1,Kubernetes 集群搭建之系统初始化配置篇
END
如果你觉得文章还不错, 请大家点『好看』分享下. 你的肯定是我最大的鼓励和支持.
来源: https://www.cnblogs.com/guigujun/p/10504184.html