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改成主機名或規則域名。