新聞中心
Harbor是一個(gè)用于存儲(chǔ)和分發(fā)Docker鏡像的企業(yè)級(jí)Registry服務(wù)器,可以用來構(gòu)建企業(yè)內(nèi)部的Docker鏡像倉庫。

汝州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
它在Docker的開源項(xiàng)目 Distribution的基礎(chǔ)上,添加了一些企業(yè)需要的功能特性,如鏡像同步復(fù)制、漏洞掃描和權(quán)限管理等。
配置
架構(gòu)圖
如上圖所示,harbor由6大模塊級(jí)成:
Proxy: Harbor的registry、UI、token services等組件,都處在一個(gè)反向代理后邊。該代理將來自瀏覽器、docker clients的請求轉(zhuǎn)發(fā)到后端服務(wù)上。
Registry: 負(fù)責(zé)存儲(chǔ)Docker鏡像,以及處理Docker push/pull請求。因?yàn)镠arbor強(qiáng)制要求對鏡像的訪問做權(quán)限控制, 在每一次push/pull請求時(shí),Registry會(huì)強(qiáng)制要求客戶端從token service那里獲得一個(gè)有效的token。
Core services: Harbor的核心功能,主要包括如下3個(gè)服務(wù):
UI: 作為Registry Webhook, 以圖像用戶界面的方式輔助用戶管理鏡像。
\1) WebHook是在registry中配置的一種機(jī)制, 當(dāng)registry中鏡像發(fā)生改變時(shí),就可以通知到Harbor的webhook endpoint。Harbor使用webhook來更新日志、初始化同步j(luò)ob等。
\2) Token service會(huì)根據(jù)該用戶在一個(gè)工程中的角色,為每一次的push/pull請求分配對應(yīng)的token。假如相應(yīng)的請求并沒有包含token的話,registry會(huì)將該請求重定向到token service。
\3) Database 用于存放工程元數(shù)據(jù)、用戶數(shù)據(jù)、角色數(shù)據(jù)、同步策略以及鏡像元數(shù)據(jù)。
Job services: 主要用于鏡像復(fù)制,本地鏡像可以被同步到遠(yuǎn)程Harbor實(shí)例上。
Log collector: 負(fù)責(zé)收集其他模塊的日志到一個(gè)地方
組件說明
需要說明的是,harbor的每個(gè)組件都是以Docker容器的形式構(gòu)建的,可以使用Docker Compose來進(jìn)行部署,當(dāng)然,如果你的環(huán)境中使用了kubernetes,harbor也提供了kubernetes的配置文件。
harbor共有8個(gè)容器組成:
ui:harbor的核心服務(wù)。
log:運(yùn)行著rsyslog的容器,進(jìn)行日志收集。
mysql:由官方mysql鏡像構(gòu)成的數(shù)據(jù)庫容器
nginx:使用Nginx做反向代理
registry:官方的Docker registry
adminserver:harbor的配置數(shù)據(jù)管理器
jobservice:Harbor的任務(wù)管理服務(wù)。
redis:用于存儲(chǔ)session
下面我們所有的配置都以harbor 1.5.2版本作配置說明。
harbor可以支持http和https,建議使用https,https證書最好是受信任的ca頒發(fā)的證書,這樣,在配置docker的時(shí)候,就不需要添加”insecure-registries”配置項(xiàng)。我們這里就直接使用自簽名證書。
生成證書:
openssl genrsa -des3 -out server.key 1024
openssl rsa -in server.key -out server.key #去除server.key的加密口令
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
將證書放入/data/certs/目錄下:
cp server.crt server.key /data/certs
harbor.cfg配置文件示例
harbor的核心配置文件是harbor.cfg,路徑在源碼目錄下的make目錄下,示例配置如下:
_version = 1.5.0
# harbor的訪問地址
hostname = hub.dz11.com
# 使用https協(xié)議
ui_url_protocol = https
# harbor的數(shù)據(jù)庫密碼
db_password = xxxxx
max_job_workers = 50
customize_crt = on
# 證書相關(guān)路徑
ssl_cert = /data/certs/dz11.com.crt
ssl_cert_key = /data/certs/dz11.com.key
secretkey_path = /data
admiral_url = NA
# 定義日志滾動(dòng)
log_rotate_count = 50
log_rotate_size = 200M
http_proxy =
https_proxy =
no_proxy = 127.0.0.1,localhost,ui
# email相關(guān)配置
email_identity =
email_server = smtp.163.com
email_server_port = 25
email_username = [email protected]
email_password = yan_ruo_gu0711
email_from = admin
email_ssl = false
# 登錄harbor的管理員密碼
harbor_admin_password = xxxxxx
# harbor的驗(yàn)證方式,支持db_auth和ldap_auth,這里使用的是ldap_auth,如果使用db_auth的話,直接將auth_mode修改為db_auth即可,ldap的配置不再需要。
auth_mode = ldap_auth
ldap_url = ldap://10.1.1.1:389
ldap_searchdn = CN=jenkins,OU=LDAP,OU=Dev-wh.xxx.com,DC=dev-wh,DC=xxx,DC=com
ldap_search_pwd = xxxx
ldap_basedn = OU=Dev-wh.xxx.com,DC=dev-wh,DC=xxx,DC=com
ldap_filter = (objectClass=person)
ldap_uid = 0
ldap_scope = 2
ldap_timeout = 5
self_registration = on
token_expiration = 30
project_creation_restriction = everyone
verify_remote_cert = on
# 數(shù)據(jù)庫相關(guān)配置,默認(rèn)如果不需要使用自建的數(shù)據(jù)庫,這些配置就都不需要
db_host = mysql
db_password = root123
db_port = 3306
db_user = root
redis_url = redis:6379
clair_db_host = postgres
clair_db_password = password
clair_db_port = 5432
clair_db_username = postgres
clair_db = postgres
uaa_endpoint = uaa.mydomain.org
uaa_clientid = id
uaa_clientsecret = secret
uaa_verify_cert = true
uaa_ca_cert = /path/to/ca.pem
registry_storage_provider_name = filesystem
registry_storage_provider_config =
部署harbor
harbor支持docker-compose和kubernetes的部署方式,默認(rèn)采用docker-compose作單機(jī)部署。
先執(zhí)行./prepare,然后執(zhí)行./install.sh進(jìn)行啟動(dòng)。執(zhí)行./install.sh的時(shí)候,即調(diào)用了docker-compose運(yùn)行了當(dāng)前目錄下的docker-compose.yml文件。
在執(zhí)行.prepare的時(shí)候拋出如下異常:
root@ubuntu:~/harbor# ./prepare
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/ui/app.conf
Fail to generate key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
需要修改prepare文件,將第498行:
empty_subj = "/C=/ST=/L=/O=/CN=/"
修改如下:
empty_subj = "/C=US/ST=California/L=Palo Alto/O=VMware, Inc./OU=Harbor/CN=notarysigner"
在實(shí)際啟動(dòng)過程中,出現(xiàn)過registry啟動(dòng)失敗的情況,/var/log/harbor/registry.log輸出如下:
May 30 21:06:00 172.18.0.1 registry[3218]: panic: unable to configure authorization (token): unable to open token auth root certificate bundle file "/etc/registry/root.crt": open /etc/registry/root.crt: permission denied
May 30 21:06:00 172.18.0.1 registry[3218]:
May 30 21:06:00 172.18.0.1 registry[3218]: goroutine 1 [running]:
May 30 21:06:00 172.18.0.1 registry[3218]: panic(0xb4cd40, 0xc4203ae160)
May 30 21:06:00 172.18.0.1 registry[3218]: #011/usr/local/go/src/runtime/panic.go:500 +0x1a1
May 30 21:06:00 172.18.0.1 registry[3218]: github.com/docker/distribution/registry/handlers.NewApp(0x1067820, 0xc4203a8630, 0xc4202df180, 0x1067820)
May 30 21:06:00 172.18.0.1 registry[3218]: #011/go/src/github.com/docker/distribution/registry/handlers/app.go:302 +0x1b6a
May 30 21:06:00 172.18.0.1 registry[3218]: github.com/docker/distribution/registry.NewRegistry(0x7fcfa30dd198, 0xc4203a8630, 0xc4202df180, 0xe, 0x0, 0x0)
May 30 21:06:00 172.18.0.1 registry[3218]: #011/go/src/github.com/docker/distribution/registry/registry.go:86 +0x213
May 30 21:06:00 172.18.0.1 registry[3218]: github.com/docker/distribution/registry.glob..func1(0x108f1a0, 0xc42036d240, 0x1, 0x1)
May 30 21:06:00 172.18.0.1 registry[3218]: #011/go/src/github.com/docker/distribution/registry/registry.go:55 +0x106
May 30 21:06:00 172.18.0.1 registry[3218]: github.com/docker/distribution/vendor/github.com/spf13/cobra.(*Command).execute(0x108f1a0, 0xc42036d1f0, 0x1, 0x1, 0x108f1a0, 0xc42036d1f0)
May 30 21:06:00 172.18.0.1 registry[3218]: #011/go/src/github.com/docker/distribution/vendor/github.com/spf13/cobra/command.go:495 +0x190
May 30 21:06:00 172.18.0.1 registry[3218]: github.com/docker/distribution/vendor/github.com/spf13/cobra.(*Command).Execute(0x108f340, 0xc4201d7f40, 0xc4200001a0)
May 30 21:06:00 172.18.0.1 registry[3218]: #011/go/src/github.com/docker/distribution/vendor/github.com/spf13/cobra/command.go:560 +0x3c3
May 30 21:06:00 172.18.0.1 registry[3218]: main.main()
May 30 21:06:00 172.18.0.1 registry[3218]: #011/go/src/github.com/docker/distribution/cmd/registry/main.go:24 +0x2d
這是因?yàn)閞egistry容器沒有/etc/registry/root.crt的訪問權(quán)限導(dǎo)致。這個(gè)文件默認(rèn)是掛載的./common/config/registry/root.crt這個(gè)文件,所以我們需要對這個(gè)文件作授權(quán)。
通過觀察可知,harbor的容器啟動(dòng)用戶非root身份,而是以一個(gè)uid和gid都為10000的用戶。所以只需要為該用戶授權(quán)即可:
chown 10000.10000 ./common/config/registry/root.crt
正常啟動(dòng)之后,配置完成。
可以通過如下方式訪問: https://hub.dz11.com
注意事項(xiàng)
需要說明的是,harbor支持http和https,但如果使用http的話,在拉取鏡像的時(shí)候,會(huì)拋出倉庫不受信任的異常。需要在所有的docker客戶端的docker配置文件/etc/docker/daemon.json中添加如下配置:
{
"insecure-registries": ["https://hub.dz11.com"],
}
如果使用自簽名的https證書,仍然會(huì)提示證書不受信任的問題。需要將自簽名的ca證書發(fā)送到所有的docker客戶端的指定目錄。
關(guān)于使用自簽名證書配置harbor的具體過程可以參考:https://github.com/WingkaiHo/docker-calico/blob/master/harbor/README.md
文章名稱:Harbor的安裝和使用
分享網(wǎng)址:http://fisionsoft.com.cn/article/dhodsii.html


咨詢
建站咨詢
