Harbor和Registry都是Docker的镜像仓库,可是Harbor做为更多企业的选择,是由于相比较于Regisrty来讲,它具备不少的优点。前端
1.提供分层传输机制,优化网络传输
Docker镜像是是分层的,而若是每次传输都使用全量文件(因此用FTP的方式并不适合),显然不经济。必须提供识别分层传输的机制,以层的UUID为标识,肯定传输的对象。
2.提供WEB界面,优化用户体验
只用镜像的名字来进行上传下载显然很不方便,须要有一个用户界面能够支持登录、搜索功能,包括区分公有、私有镜像。
3.支持水平扩展集群
当有用户对镜像的上传下载操做集中在某服务器,须要对相应的访问压力做分解。
4.良好的安全机制
企业中的开发团队有不少不一样的职位,对于不一样的职位人员,分配不一样的权限,具备更好的安全性。
5.Harbor提供了基于角色的访问控制机制,并经过项目来对镜像进行组织和访问权限的控制。kubernetes中经过namespace来对资源进行隔离,在企业级应用场景中,经过将二者进行结合能够有效将kubernetes使用的镜像资源进行管理和访问控制,加强镜像使用的安全性。尤为是在多租户场景下,能够经过租户、namespace和项目相结合的方式来实现对多租户镜像资源的管理和访问控制。node
在真正安装以前,咱们还要安装下面这几个组件python
更新apt源,并添加https支持linux
sudo apt-get update && sudo apt-get install apt-transport-https ca-certificates curl software-properties-common -y
使用utc源添加GPG Keynginx
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add
添加Docker-ce稳定版源地址git
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
安装docker-cegithub
目前最新版本是19.03.1web
sudo apt-get update sudo apt install -y docker-ce=5:19.03.1~3-0~ubuntu-xenial
参考官方连接:https://docs.docker.com/compose/install/docker
运行此命令下载docker compose的当前稳定版本:json
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
对二进制文件应用可执行权限
sudo chmod +x /usr/local/bin/docker-compose
因为ubuntu 16.04,默认已经有了python3,openssl也已经安装好了。
root@ubuntu:~# dpkg -l |grep openssl ii libgnutls-openssl27:amd64 3.4.10-4ubuntu1.4 amd64 GNU TLS library - OpenSSL wrapper ii openssl 1.0.2g-1ubuntu4.10 amd64 Secure Sockets Layer toolkit - cryptographic utility
https://github.com/vmware/harbor/releases
安装有两种方式,一种是off-line ,一种是on-line,即离线和在线安装,离线安装须要下载的安装包较大,在线安装下载的安装包很小,课题根据本身的状况选择,我选择的是1.8.1版本
下载在线安装包
wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-online-installer-v1.8.1.tgz
若是没法访问google,我已经上传到百度网盘了,可自行下载
连接:https://pan.baidu.com/s/1mRtaFNfYViz5xywYB9GnXw
提取码:xsc0
解压安装包
tar zxvf harbor-online-installer-v1.8.1.tgz -C /usr/src/ cd /usr/src/harbor
编辑配置文件
vim harbor.yml
修改hostname为本机ip地址
hostname: 192.168.10.122
其它参数,能够根据实际状况修改,去除多余的注释和空行,配置文件以下:
root@ubuntu:/usr/src/harbor# cat harbor.yml |grep -v "^#"|grep -v " #"|grep -v "^$" hostname: 192.168.10.122 http: port: 80 harbor_admin_password: Harbor12345 database: password: root123 data_volume: /data clair: updaters_interval: 12 http_proxy: https_proxy: no_proxy: 127.0.0.1,localhost,core,registry jobservice: max_job_workers: 10 chart: absolute_url: disabled log: level: info rotate_count: 50 rotate_size: 200M location: /var/log/harbor _version: 1.8.0
以后直接执行
./install.sh
出现如下提示,表示安装成功
✔ ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at http://192.168.10.122. For more details, please visit https://github.com/goharbor/harbor .
以后若是你想修改某一个配置好比你要把域名修改一下,我是这么作的先修改上面harbor.cfg这个文件,以后从新执行install.sh这个文件就能够了
http://192.168.10.122
使用默认的帐号:admin,密码:Harbor12345登陆验证
登陆成功以后,效果以下:
登陆到另一台服务器,确保docker已经安装好了。
因为默认的harbor,已经建立了一个公开项目 libary。
vim /etc/docker/daemon.json
内容以下:
{"insecure-registries": ["192.168.10.122"]}
接着重启服务
systemctl restart docker
登陆仓库,admin密码仍是Harbor12345
root@k8s-node1:~# docker login 192.168.10.122 Username: admin 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
如今下载一个镜像alpine
docker pull alpine
给镜像打tag
docker tag alpine:latest 192.168.10.122/library/alpine
推送镜像
root@k8s-node1:~# docker push 192.168.10.122/library/alpine The push refers to repository [192.168.10.122/library/alpine] 1bfeebd65323: Pushed latest: digest: sha256:57334c50959f26ce1ee025d08f136c2292c128f84e7b229d1b0da5dac89e9866 size: 528
pull一次仓库上镜像的pulls就会加一次,能够在web界面上看的
增长开机启动
vi /etc/rc.local
最后一行添加
#harbor start
cd /usr/src/harbor && docker-compose up -d
公开的项目,推送镜像时,docker必需要登陆。
下载镜像时,无须登陆。
非公开项目,下载和推送,必须docker登陆才行。
本文参考连接: