Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,经过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。做为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提高用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像所有保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。前端
●基于角色的访问控制 :用户与Docker镜像仓库经过“项目”进行组织管理,一个用户能够对多个镜像仓库在同一命名空间(project)里有不一样的权限。node
●镜像复制 : 镜像能够在多个Registry实例中复制(同步)。尤为适合于负载均衡,高可用,混合云和多云的场景。python
●图形化用户界面 : 用户能够经过浏览器来浏览,检索当前Docker镜像仓库,管理项目和命名空间。linux
AD/LDAP 支持 : Harbor能够集成企业内部已有的AD/LDAP,用于鉴权认证管理。nginx
●审计管理 : 全部针对镜像仓库的操做均可以被记录追溯,用于审计管理。git
●国际化 : 已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。github
●RESTful API : RESTful API 提供给管理员对于Harbor更多的操控, 使得与其它管理软件集成变得更容易。web
●部署简单 : 提供在线和离线两种安装工具, 也能够安装到vSphere平台(OVA方式)虚拟设备。redis
●Proxy:Harbor的registry, UI, token等服务,经过一个前置的反向代理统一接收浏览器、Docker客户端的请求,并将请求转发给后端不一样的服务。sql
●Registry: 负责储存Docker镜像,并处理docker push/pull 命令。因为咱们要对用户进行访问控制,即不一样用户对Docker image有不一样的读写权限,Registry会指向一个token服务,强制用户的每次docker pull/push请求都要携带一个合法的token, Registry会经过公钥对token 进行解密验证。
●Core services: 这是Harbor的核心功能,主要提供如下服务:
UI:提供图形化界面,帮助用户管理registry上的镜像(image), 并对用户进行受权。
webhook:为了及时获取registry 上image状态变化的状况, 在Registry上配置webhook,把状态变化传递给UI模块。
token 服务:负责根据用户权限给每一个docker push/pull命令签发token. Docker 客户端向Regiøstry服务发起的请求,若是不包含token,会被重定向到这里,得到token后再从新向Registry进行请求。
●Database:为core services提供数据库服务,负责储存用户权限、审计日志、Docker image分组信息等数据。
●Job Services:提供镜像远程复制功能,能够把本地镜像同步到其余Harbor实例中。
●Log collector:为了帮助监控Harbor运行,负责收集其余组件的log,供往后进行分析。
各个组件之间的关系以下图所示:
●nginx:nginx负责流量转发和安全验证,对外提供的流量都是从nginx中转,因此开放https的443端口,它将流量分发到后端的ui和正在docker镜像存储的docker registry。
●harbor-jobservice:harbor-jobservice 是harbor的job管理模块,job在harbor里面主要是为了镜像仓库以前同步使用的。
●harbor-ui:harbor-ui是web管理页面,主要是前端的页面和后端CURD的接口。
●registry:registry就是docker原生的仓库,负责保存镜像。
●harbor-adminserver:harbor-adminserver是harbor系统管理接口,能够修改系统配置以及获取系统信息。
●harbor-db:harbor-db是harbor的数据库,这里保存了系统的job以及项目、人员权限管理。因为本harbor的认证也是经过数据,在生产环节大多对接到企业的ldap中。
●harbor-log:harbor-log是harbor的日志服务,统一管理harbor的日志。经过inspect能够看出容器统一将日志输出的syslog。
这几个容器经过Docker link的形式链接在一块儿,这样,在容器之间能够经过容器名字互相访问。对终端用户而言,只须要暴露proxy (即Nginx)的服务端口。
环境名称 |
版本 |
系统版本 |
CentOS Linux release 7.5.1804 (Core) |
docker-ce |
19.03.1 |
docker-compose |
1.18.0 |
Harbor |
v1.8.1 |
主机名:node01 |
IP:10.0.0.50 |
yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
rpm -qa|grep docker|awk '{print "yum remove -y " $1}'|bash
yum install -y docker-ce systemctl start docker systemctl enable docker
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm yum install -y docker-compose
●下载二进制文件
curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
若是须要安装其余版本的话,请修改上面命令中的版本号。
●赋予二进制文件可执行权限
chmod +x /usr/local/bin/docker-compose
●安装命令补全功能(重启后生效)
yum install -y bash-completion curl -L https://raw.githubusercontent.com/docker/compose/1.18.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm yum install -y python-pip pip install docker-compose
这里有两个包Harbor offline installer 和 Harbor online installer,二者的区别的是 Harbor offline installer 里就包含的 Harbor 须要使用的镜像文件。
wget -P /opt/ https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.1.tgz
tar xf /opt/harbor-offline-installer-v1.8.1.tgz -C /usr/local/ cd /usr/local/harbor/ vim harbor.yml ****************************************** 设置HOSTNAME名和登陆密码,生产主机名为域名,这里使用主机名 hostname: node01 harbor_admin_password: 123456 ****************************************** ./prepare ./install.sh
在浏览器输入:http://10.0.0.50
账号密码为:admin/123456
Harbor 的平常运维管理是经过docker-compose来完成的,Harbor自己有多个服务进程,都放在docker容器之中运行,咱们能够经过docker ps 或docker-compose 命令查看,使用docker-compose查看须要在harbor目录下。
[root@node01 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f5936a159ea goharbor/nginx-photon:v1.8.1 "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes (healthy) 0.0.0.0:80->80/tcp nginx 6890e23d4e04 goharbor/harbor-jobservice:v1.8.1 "/harbor/start.sh" 2 minutes ago Up 2 minutes harbor-jobservice 46c7aa564fdc goharbor/harbor-portal:v1.8.1 "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes (healthy) 80/tcp harbor-portal 5cece92d1c77 goharbor/harbor-core:v1.8.1 "/harbor/start.sh" 2 minutes ago Up 2 minutes (healthy) harbor-core ddc4b133da6a goharbor/harbor-registryctl:v1.8.1 "/harbor/start.sh" 3 minutes ago Up 3 minutes (healthy) registryctl cc8a3188b58a goharbor/harbor-db:v1.8.1 "/entrypoint.sh post…" 3 minutes ago Up 3 minutes (healthy) 5432/tcp harbor-db 92a5e4c314f1 goharbor/redis-photon:v1.8.1 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 6379/tcp redis 2e4a6be26e7b goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1 "/entrypoint.sh /etc…" 3 minutes ago Up 3 minutes (healthy) 5000/tcp registry aff7569ea98b goharbor/harbor-log:v1.8.1 "/bin/sh -c /usr/loc…" 3 minutes ago Up 3 minutes (healthy) 127.0.0.1:1514->10514/tcp harbor-log [root@node01 ~]# cd /usr/local/harbor/ [root@node01 harbor]# docker-compose ps Name Command State Ports -------------------------------------------------------------------------------------- harbor-core /harbor/start.sh Up harbor-db /entrypoint.sh postgres Up 5432/tcp harbor-jobservice /harbor/start.sh Up harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp harbor-portal nginx -g daemon off; Up 80/tcp nginx nginx -g daemon off; Up 0.0.0.0:80->80/tcp redis docker-entrypoint.sh redis ... Up 6379/tcp registry /entrypoint.sh /etc/regist ... Up 5000/tcp registryctl /harbor/start.sh Up
启动Harbor # docker-compose start 中止Harbor # docker-comose stop 重启Harbor # docker-compose restart
因为docker push镜像到仓库默认须要HTTPS协议,这里修改docker服务配置,使用HTTP协议。
方法一:
vim /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 10.0.0.50
--insecure-registry 后面加的是私库的地址(这里的私库地址为:10.0.0.50)。
方法二:
vim /etc/docker/daemon.json ******************************* { "insecure-registries":["10.0.0.50"] } ******************************* #重启docker服务 systemctl daemon-reload systemctl restart docker
[root@node01 ~]# docker pull alpine Using default tag: latest latest: Pulling from library/alpine 050382585609: Pull complete Digest: sha256:6a92cd1fcdc8d8cdec60f33dda4db2cb1fcdcacf3410a8e05b3741f44a9b5998 Status: Downloaded newer image for alpine:latest docker.io/library/alpine:latest [root@node01 ~]# docker images alpine REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest b7b28af77ffe 3 weeks ago 5.58MB
[root@node01 ~]# docker login 10.0.0.50 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
[root@node01 ~]# docker tag b7b28af77ffe 10.0.0.50/library/alpine:latest [root@node01 ~]# docker push 10.0.0.50/library/alpine:latest The push refers to repository [10.0.0.50/library/alpine] 1bfeebd65323: Pushed latest: digest: sha256:57334c50959f26ce1ee025d08f136c2292c128f84e7b229d1b0da5dac89e9866 size: 528
注意:这里打tag必须是加上仓库的项目名,例如上面10.0.0.50/library/alpine:latest,不然会上传失败,示例以下:
[root@node01 ~]# docker tag b7b28af77ffe 10.0.0.50/wutao/alpine:latest [root@node01 ~]# docker push 10.0.0.50/wutao/alpine:latest The push refers to repository [10.0.0.50/wutao/alpine] 1bfeebd65323: Preparing denied: requested access to the resource is denied
[root@node01 ~]# docker rmi alpine Untagged: alpine:latest Untagged: alpine@sha256:6a92cd1fcdc8d8cdec60f33dda4db2cb1fcdcacf3410a8e05b3741f44a9b5998 [root@node01 ~]# docker pull 10.0.0.50/library/alpine:latest latest: Pulling from library/alpine 050382585609: Pull complete Digest: sha256:57334c50959f26ce1ee025d08f136c2292c128f84e7b229d1b0da5dac89e9866 Status: Downloaded newer image for 10.0.0.50/library/alpine:latest 10.0.0.50/library/alpine:latest [root@node01 ~]# docker images 10.0.0.50/library/alpine:latest REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.50/library/alpine latest b7b28af77ffe 3 weeks ago 5.58MB
vim /usr/local/harbor/harbor.ym ****************************************************************************************** #禁用HTTP协议,启用HTTPS协议 hostname: node01 # http related config #http: # port for http, default is 80. If https enabled, this port will redirect to https port # port: 80 # https related config https: # # https port for harbor, default is 443 port: 443 # # The path of cert and key files for nginx certificate: /root/certs/ca.crt private_key: /root/certs/ca.key harbor_admin_password: 123456
[root@node01 ]# mkdir /root/certs -p [root@node01 ]# openssl genrsa -out /root/certs/ca.key 2048 Generating RSA private key, 2048 bit long modulus ..+++ ..............+++ e is 65537 (0x10001)
[root@node01 ]# openssl req -x509 -new -nodes -key /root/certs/ca.key -subj "/CN=node01" -days 5000 -out /root/certs/ca.crt
[root@node01 ~]# cd /usr/local/harbor/ [root@node01 harbor]# ./prepare [root@node01 harbor]# ./install.sh ✔ ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at https://node01 . For more details, please visit https://github.com/goharbor/harbor .
能够看到已是启用HTTPS协议了。
客户端须要建立证书文件存放的位置,而且把服务端建立的证书拷贝到该目录下,而后重启客户端docker。咱们这里建立目录为:/etc/docker/certs.d/node01
[root@node01 ~]# mkdir /etc/docker/certs.d/node01 -p [root@node01 ~]# cp /root/certs/ca.crt /etc/docker/certs.d/node01/ [root@node01 ~]# systemctl restart docker [root@node01 ~]# cd /usr/local/harbor/ && docker-compose start Starting log ... done Starting registry ... done Starting registryctl ... done Starting postgresql ... done Starting core ... done Starting portal ... done Starting redis ... done Starting jobservice ... done Starting proxy ... done
[root@node01 harbor]# docker login node01 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
[root@node01 harbor]# ./install.sh ➜ Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients. Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under https. Please set --with-clair if needs enable Clair in Harbor Please set --with-chartmuseum if needs enable Chartmuseum in Harbor
解决方法:把Harbor配置文件hostname改成主机名或规则域名。