簡介html
Harbor是VMware公司開源的企業級DockerRegistry項目,項目地址爲https://github.com/vmware/harbor。其目標是幫助用戶迅速搭建一個企業級的Dockerregistry服務。它以Docker公司開源的registry爲基礎,提供了管理UI,基於角色的訪問控制(Role Based Access Control),AD/LDAP集成、以及審計日誌(Auditlogging) 等企業用戶需求的功能,同時還原生支持中文。Harbor的每一個組件都是以Docker容器的形式構建的,使用Docker Compose來對它進行部署。用於部署Harbor的Docker Compose模板位於 /Deployer/docker-compose.yml,由5個容器組成:node
Proxy:由Nginx 服務器構成的反向代理。mysql
Registry:由Docker官方的開源registry鏡像構成的容器實例。nginx
UI:即架構中的core services, 構成此容器的代碼是Harbor項目的主體。git
MySQL:由官方MySQL鏡像構成的數據庫容器。github
Log:運行着rsyslogd的容器,經過log-driver的形式收集其餘容器的日誌。web
這幾個容器經過Docker link的形式鏈接在一塊兒,在容器之間經過容器名字互相訪問。對終端用戶而言,只須要暴露proxy (即Nginx)的服務端口。sql
Harbor特性docker
基於角色控制數據庫
用戶和倉庫都是基於項目進行組織的, 而用戶基於項目能夠擁有不一樣的權限。
基於鏡像的複製策略
鏡像能夠在多個Harbor實例之間進行復制。
支持LDAP
Harbor的用戶受權可使用已經存在LDAP用戶。
鏡像刪除 & 垃圾回收
Image能夠被刪除而且回收Image佔用的空間。
用戶UI
用戶能夠輕鬆的瀏覽、搜索鏡像倉庫以及對項目進行管理。
鏡像刪除 & 垃圾回收
絕大部分的用戶操做API, 方便用戶對系統進行擴展。
輕鬆的部署功能
Harbor提供了online、offline安裝,除此以外還提供了virtualappliance安裝。
Harbor和docker registry關係
Harbor實質上是對docker registry作了封裝,擴展了本身的業務模塊.下面展現一下docker registry和Harbor的架構圖用以說明。
一、dockerdaemon從docker registry拉取鏡像。
二、若是dockerregistry須要進行受權時,registry將會返回401 Unauthorized響應,同時在響應中包含了docker client如何進行認證的信息。
三、dockerclient根據registry返回的信息,向auth server發送請求獲取認證token。
四、auth server則根據本身的業務實現去驗證提交的用戶信息是否存符合業務要求。
五、用戶數據倉庫返回用戶的相關信息。
六、auth server將會根據查詢的用戶信息,生成token令牌,以及當前用戶所具備的相關權限信息。
上述就是完整的受權過程.當用戶完成上述過程之後即可以執行相關的pull/push操做。認證信息會每次都帶在請求頭中。
Harbor總體架構
Harbor認證流程
A、首先,請求被代理容器監聽攔截,並跳轉到指定的認證服務器。
B、 若是認證服務器配置了權限認證,則會返回401。通知dockerclient在特定的請求中須要帶上一個合法的token。而認證的邏輯地址則指向架構圖中的core services。
C、 當docker client接受到錯誤code。client就會發送認證請求(帶有用戶名和密碼)到coreservices進行basic auth認證。
D、 當C的請求發送給ngnix之後,ngnix會根據配置的認證地址將帶有用戶名和密碼的請求發送到core serivces。
E、 coreservices獲取用戶名和密碼之後對用戶信息進行認證(本身的數據庫或者介入LDAP均可以)。成功之後,返回認證成功的信息。
從上面的docker registry 和 Harbor的架構圖、流程圖能夠看出Harbor的擴展部分爲coreservices。這部分實現了用戶的認證,添加了UI模塊已經webhook。
· hostname 運行Harbor的主機地址(域名或者IP地址,不能是localhostor 127.0.0.1)。 · ui_url_protocol url協議(http或者https) 默認爲http。 https配置能夠參考Configuring Harbor with HTTPS Access。 https://github.com/vmware/harbor/blob/master/docs/configure_https.md · Email設定 配置的郵件能夠用戶Harbor進行密碼重置處理。 #Email accountsettings for sending out password resetting emails. email_server =smtp.mydomain.com email_server_port= 25 email_username =sample_admin@mydomain.com email_password =abc email_from =admin <sample_admin@mydomain.com> email_ssl =false · harbor_admin_password admin初始化密碼Harbor12345。 · auth_mode 認證方式,默認爲db_auth。也可使用ldap_auth因爲參數太多就不一一列舉了。 Harbor安裝手冊講的很清楚。 · 持久化data和日誌文件 默認狀況下data是被存儲在Harbor host機的/data目錄.無論harborcontainer是刪除仍是從新建立這裏的數據都是一致存在的。另外harbor的日誌文件默認狀況下是存在/var/log/harbor/目錄下的。 · 自定義ngnix監聽端口 一、修改docker-compose.yml文件。 替換80端口爲任意存在未被佔用的端口,好比28080 proxy: image: nginx:1.9 container_name: nginx restart: always volumes: -./common/config/nginx:/etc/nginx ports: - 28080:80 - 443:443 depends_on: - mysql - registry - ui - log logging: driver: "syslog" options: syslog-address:"tcp://127.0.0.1:1514" tag: "proxy"
一、 修改common/templates/registry/config.yml文件
auth: token: issuer:registry-token-issuer realm: $ui_url:28080/service/token rootcertbundle:/etc/registry/root.crt service: token-service
二、 運行install.sh來更新並啓動Harbor
docker-compose down ./install.sh
HTTPS 協議的修改和自定義監聽端口修改同樣的操做
· storage配置
· Harbor的Docker鏡像存放路徑修改
Harbor是一個Docker鏡像的託管系統,幫助用戶創建本身的相似於Docker Hub的鏡像託管和分享服務。Harbor的默認鏡像存儲路徑在/data/registry目錄下,映射到docker容器裏面的/storage目錄下。
這個參數是在docker-compose.yml中指定的,在docker-compose up -d運行以前修改。
若是但願將Docker鏡像存儲到其餘的磁盤路徑,能夠修改這個參數。
Harbor的運行時由多個DockerContainer組成,包括:Nginx、MySQL、UI、Proxy、log、JobService六個主要組成部分。
Harbor安裝有三種方式,這裏以offline安裝的方式爲例,另外兩種能夠參考Harbor的官方文檔。
默認狀況下,Harbor是把鏡像存儲在本地文件系統中的。可是在生產環境中你可能會考慮到使用其餘的存儲方案來代替本地存儲。好比S三、Openstack Swift、Ceph等等。那麼這個時候你就須要更改common/templates/registry/config.yml中的存儲配置部分。例如: storage: cache: layerinfo: inmemory filesystem: rootdirectory: /storage maintenance: uploadpurging: enabled: false delete: enabled: true
前提條件:
Harbor使用幾個Docker容器來部署的,所以部署Harbor的節點上要求安裝好Docker服務,同時要求安裝好Python,DockerCompose,以下:
l Python應該在2.7或以上版本
l Docker engine應該在1.10或以上版本
l Docker Compose須要在1.6.0或以上版本
Harbor的安裝:
一、下載安裝包
tar xvfharbor-offline-installer-<version>.tgz
二、配置harbor.cfg文件
三、執行install.sh腳本安裝並啓動Harbor
./install.sh
登陸並建立本身的鏡像倉庫(初始用戶名/密碼初始化爲:admin/Harbor12345)。
這裏咱們使用HTTP方式,那麼訪問地址爲:
若是開啓HTTPS時,在使用過程當中,發現若是Registry的5000端口沒有映射出來時,報以下錯誤:
[root@docker02harbor]# docker login xx.xxx.xx.xx
Username: admin
Password:
Error responsefrom daemon: Get https://xx.xxx.xx.xx/v1/users/: dial tcp xx.xxx.xx.xx:443:getsockopt: connection refused
[root@docker02harbor]# docker login xx.xxx.xx.xx:5000
Username: admin
Password:
Error responsefrom daemon: Get http://xx.xxx.xx.xx:5000/v1/users/: dial tcp xx.xxx.xx.xx:5000:getsockopt: connection refused
咱們修改docker-compose.yml文件,添加Registry端口號映射出來,部份內容以下:
registry:
image: library/registry:2.5.0
container_name: registry
restart: always
volumes:
- /data/registry:/storage
-./common/config/registry/:/etc/registry/
ports:
- 5000:5000
environment:
- GODEBUG=netdns=cgo
command:
["serve","/etc/registry/config.yml"]
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address:"tcp://127.0.0.1:1514"
tag: "registry"
修改docker-compose.yml配置文件後,咱們執行:
docker-composestop ./install.sh
再次登陸就OK了:
[root@docker02appl]# docker login xx.xxx.xx.xx:5000
Username(admin): admin
Password:
Login Succeeded
Harbor的生命週期管理 你可使用docker-compose來管理Harbor的生命週期,下面列舉一些有用的經常使用的命令。
中止Harbor:
#中止服務 docker-compose stop #中止服務而且刪除containers, networks, images, and volumes docker-compose down
移除docker container 可是保留相關鏡像文件:
docker-compose rm
若是想刪除數據的話,執行:
rm -r/data/database rm -r/data/registry
中止:
docker-compose -f docker-compose.yml stop
啓動:
docker-compose -f docker-compose.yml start
若是修改了配置文件,執行以下步驟:
docker-compose down vim harbor.cfg ./install.sh
查看容器狀態:
[root@docker02 harbor]# docker-compose ps Name Command State Ports ----------------------------------------------------------------------------------------------------- harbor-db docker-entrypoint.sh mysqld Up 3306/tcp harbor-jobservice /harbor/harbor_jobservice Up harbor-log /bin/sh -c crond && rsyslo... Up 0.0.0.0:1514->514/tcp harbor-ui /harbor/harbor_ui Up nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp,0.0.0.0:80->80/tcp registry /entrypoint.sh serve /etc/ ... Up 0.0.0.0:5000->5000/tcp
問題記錄1:
[root@docker02 ~]# docker push xx.xxx.xx.xx/calico/node
The push refers to a repository [xx.xxx.xx.xx/calico/node]
5a5054a0b567: Preparing
dc759f36d103: Preparing
0ae8598a5313: Preparing
b7fc58bf47e2: Preparing
799d9a47057e: Waiting
503925f2fc18: Waiting
unauthorized: authentication required
若是權限都沒有問題的話,那就是在Harbor裏面沒有calico項目,Harbor要求xx.xxx.xx.xx/calico/node中第一個/後面的爲項目名稱,要求Harbor中存在這個項目名稱,不然就會報這個錯誤。
問題記錄2:
Harbor只支持Registry V2 API,所以你須要使用Docker1.6以及以上的客戶端。
問題記錄3:
[root@docker02 harbor]# curl https://192.168.1.200/v2/
curl: (60) Peer's Certificate issuer is notrecognized.
More details here:http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verificationby default, using a "bundle"
ofCertificate Authority (CA) public keys (CA certs). If the default
bundlefile isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificatesigned by a CA represented in
thebundle, the certificate verification probably failed due to a
problem with the certificate (it might beexpired, or the name might
notmatch the domain name in the URL).
If you'd like to turn off curl'sverification of the certificate, use
the-k (or --insecure) option.
此種狀況多發生在自簽名的證書,報錯含義是簽發證書機構未經認證,沒法識別。
解決辦法是將簽發該證書的私有CA公鑰ca.crt文件內容,追加到/etc/pki/tls/certs/ca-bundle.crt。
[root@docker02 harbor]# cat/etc/docker/certs.d/192.168.1.200/ca.crt >>/etc/pki/tls/certs/ca-bundle.crt
[root@docker02 harbor]# curl https://192.168.1.200/v2/
{"errors":[{"code":"UNAUTHORIZED","message":"authenticationrequired","detail":null}]}
問題記錄4:
若是出現以下錯誤:
[root@docker01 harbor]# docker pull xx.xxx.xx.xx:5000/vmware/harbor-db:0.4.5
Error response from daemon: Get https://xx.xxx.xx.xx:5000/v1/_ping:http: server gave HTTP response to HTTPS client
解決方法:
修改/usr/lib/systemd/system/docker.service文件,在ExecStart中添加--insecure-registry內容:
ExecStart=/usr/bin/dockerd--insecure-registry=xx.xxx.xx.xx:5000
而後重啓Docker服務:
systemctl restart docker
而後再登陸執行pull就能夠了:
[root@docker01 harbor]# docker login xx.xxx.xx.xx:5000
Username: admin
Password:
Login Succeeded
[root@docker01 harbor]# docker pull xx.xxx.xx.xx:5000/calico/node
Using default tag: latest
latest: Pulling from calico/node
dd951796ec8a: Pull complete
2ed92f708362: Pull complete
1703d9b705ad: Pull complete
a45fbe27e680: Pull complete
8c874d304eb0: Pull complete
0b3e16347231: Pull complete
4670f2d45133: Pull complete
Digest:sha256:2585b48d929f6279637b27c85725cef44ec4cafaee3dafaa99ca3b1756e5a525
Status: Downloaded newer image for xx.xxx.xx.xx:5000/calico/node:latest