目錄
一、Harbor 介紹
二、Harbor 的優(yōu)勢
三、Harbor 部署安裝
3.1 部署環(huán)境
3.2?為 Harbor 自簽發(fā)證書
3.3 安裝 Harbor
3.4 設置開機自啟
四、Harbor 圖像化界面使用說明
4.1 修改本地 hosts 文件
4.2 訪問 harbor
4.3 創(chuàng)建項目
五、測試使用 harbor 私有鏡像倉庫
5.1 修改 docker 配置
5.2 登錄 harbor
5.3 上傳鏡像到 harbor
5.4?從 harbor 倉庫下載鏡像
一、Harbor 介紹
????????Docker容器應用的開發(fā)和運行離不開可靠的鏡像管理,雖然Docker官方也提供了公共的鏡像倉庫,但是從安全和效率等方面考慮,部署我們私有環(huán)境內(nèi)的Registry也是非常必要的。Harbor是由VMware公司開源的企業(yè)級的Docker Registry管理項目,它包括權限管理(RBAC)、LDAP、日志審核、管理界面、自我注冊、鏡像復制和中文支持等功能。
Harbor 官網(wǎng):Harbor
二、Harbor 的優(yōu)勢
- 基于角色的訪問控制:用戶與 Docker 鏡像倉庫通過“項目”進行項目管理,可以對不同的賬戶設置不同的權限,以實現(xiàn)權限的精細管控。
- 鏡像復制:鏡像可以在多個 Registry 實例中復制(同步),可以實現(xiàn)高性能、高可用的鏡像服務。
- 圖形化用戶界面:用戶可以通過瀏覽器來瀏覽,管理當前 Docker 鏡像倉庫,管理項目和鏡像等。
- AD/LDAP 支:Harbor 可以集成企業(yè)內(nèi)部已有的 AD/LDAP,用于鑒權認證管理。
- 審計管理:所有針對鏡像倉庫的操作都可以被記錄追溯,用于審計管理。
- 國際化:已擁有英文、中文、德文、日文和俄文等多語言支持版本。
- RESTful API:提供給管理員對于 Harbor 更多的操控, 使得與其它管理軟件集成變得更容易。
- 部署簡單:提供在線和離線兩種安裝工具, 也可以安裝到 vSphere 平臺(OVA 方式)虛擬設備。
三、Harbor 部署安裝
Harbor 官方安裝文檔:Harbor docs | Harbor Installation and Configuration
3.1 部署環(huán)境
????????Harbor 安裝之前需要先安裝 Docker engine,Docker Compose,Openssl;Harbor 啟動默認是占用80
端口(如果是 HTTP Schema,在生產(chǎn)環(huán)境還是最好使用 HTTPS),當然這個可以在后面的配置文件中更改。
Docker Compose 安裝步驟查看這篇文章:【云原生 | Docker 高級篇】07、Docker compose 容器編排_Stars.Sky的博客-CSDN博客
系統(tǒng)環(huán)境初始化:CentOS 7 初始化系統(tǒng)_centos7初始化_Stars.Sky的博客-CSDN博客
3.2?為 Harbor 自簽發(fā)證書
[root@harbor ~]# mkdir /harbor/ssl -p
[root@harbor ~]# cd /harbor/ssl/
# 生成 ca 證書
# 生成一個 3072 位的 key,也就是私鑰
[root@harbor ssl]# openssl genrsa -out ca.key 3072
[root@harbor ssl]# openssl req -new -x509 -days 3650 -key ca.key -out ca.pem
????????生成一個數(shù)字證書 ca.pem,3650 表示證書的有效時間是 3 年,按箭頭提示填寫即可,沒有箭頭標注的為空:
# 生成域名的證書
[root@harbor ssl]# openssl genrsa -out harbor.key 3072
[root@harbor ssl]# openssl req -new -key harbor.key -out harbor.csr
生成一個證書請求,一會簽發(fā)證書時需要的,標箭頭的按提示填寫,沒有箭頭標注的為空:
# 簽發(fā)證書
[root@harbor ssl]# openssl x509 -req -in harbor.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out harbor.pem -days 3650
[root@harbor ssl]# ls
ca.key ca.pem ca.srl harbor.csr harbor.key harbor.pem
3.3 安裝 Harbor
Harbor 安裝包下載地址:Releases · goharbor/harbor · GitHub
# 把下載好的包放在此目錄
[root@harbor ssl]# cd /usr/local/
[root@harbor local]# ls
bin etc games go harbor-offline-installer-v2.5.5.tgz include lib lib64 libexec sbin share src
[root@harbor local]# tar -zxvf harbor-offline-installer-v2.5.5.tgz
[root@harbor local]# cd harbor/
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
# 修改配置文件
[root@harbor harbor]# vim harbor.yml
······
hostname: harbor # 修改 hostname,跟上面簽發(fā)的證書域名保持一致
······
https: # 協(xié)議用 https
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /harbor/ssl/harbor.pem # 修改為前面創(chuàng)建證書的路徑
private_key: /harbor/ssl/harbor.key
······
# 郵件和 ldap 不需要配置,在 harbor 的 web 界面可以配置,其他配置采用默認即可,修改之后保存退出。
# 注:harbor 默認的賬號密碼:admin/Harbor12345
# 運行安裝腳本
[root@harbor harbor]# ./install.sh
看到下面內(nèi)容,說明安裝成功:
3.4 設置開機自啟
[root@harbor harbor]# vim uprestart.sh
#!/bin/bash
cd /usr/local/harbor
docker-compose stop; sleep 1m; docker-compose up -d >> /dev/null 2>&1 &
[root@harbor harbor]# chmod +x uprestart.sh
# 最后一行添加下面內(nèi)容
[root@harbor harbor]# vim /etc/rc.d/rc.local
/usr/bin/bash /usr/loacl/harbor/uprestart.sh
[root@harbor harbor]# chmod +x /etc/rc.d/rc.local
擴展:
# 停止 harbor
# 進入 Harbor 文件夾
[root@harbor harbor]# pwd
/usr/local/harbor
[root@harbor harbor]# docker-compose stop
# 重啟 harbor
# 進入 Harbor 文件夾
[root@harbor harbor]# pwd
/usr/local/harbor
[root@harbor harbor]# docker-compose start
或
[root@harbor harbor]# docker-compose up -d
四、Harbor 圖像化界面使用說明
4.1 修改本地 hosts 文件
在 hosts 文件下面添加如下一行,然后保存即可(注意:填寫自己的 harbor 主機 ip)
192.168.78.138? harbor
# harbor 服務器也要修改
[root@harbor harbor]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.78.138 harbor
4.2 訪問 harbor
在瀏覽器輸入 https://harbor
賬號:admin
密碼:Harbor12345
輸入賬號密碼出現(xiàn)如下:
所有基礎鏡像都會放在 library 里面,這是一個公開的鏡像倉庫。
4.3 創(chuàng)建項目
點擊新建項目 -> 自定義項目名字為 test(把訪問級別公開那個選中,讓項目才可以被公開使用)
五、測試使用 harbor 私有鏡像倉庫
5.1 修改 docker 配置
# 增加一行內(nèi)容 "insecure-registries": ["192.168.78.138","harbor"],表示走 http 協(xié)議,即內(nèi)網(wǎng)訪問
[root@harbor harbor]# vim /etc/docker/daemon.json
{ "registry-mirrors": ["https://hlfcd01t.mirror.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com"],
"insecure-registries": ["192.168.78.138","harbor"]
}
# 使配置生效
[root@harbor harbor]# systemctl daemon-reload
[root@harbor harbor]# systemctl restart docker.service
5.2 登錄 harbor
[root@harbor harbor]# docker login 192.168.78.138
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
5.3 上傳鏡像到 harbor
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
······
centos latest 5d0da3dc9764 16 months ago 231MB
# 給 centos 鏡像打標簽,指定 test 項目
[root@harbor harbor]# docker tag centos:latest 192.168.78.138/test/centos:v1
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
······
centos latest 5d0da3dc9764 16 months ago 231MB
192.168.78.138/test/centos v1 5d0da3dc9764 16 months ago 231MB
# 上傳鏡像到 harbor 里的 test 項目下
[root@harbor harbor]# docker push 192.168.78.138/test/centos:v1
文章來源:http://www.zghlxwxcb.cn/news/detail-796432.html
5.4?從 harbor 倉庫下載鏡像
# 先本地刪除鏡像
[root@harbor harbor]# docker rmi -f 192.168.78.138/test/centos:v1
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
······
centos latest 5d0da3dc9764 16 months ago 231MB
# 下載鏡像
[root@harbor harbor]# docker pull 192.168.78.138/test/centos:v1
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
·····
192.168.78.138/test/centos v1 5d0da3dc9764 16 months ago 231MB
centos latest 5d0da3dc9764 16 months ago 231MB
上一篇文章:【云原生 | Docker 高級篇】10、Docker 資源配額_Stars.Sky的博客-CSDN博客_docker容器默認分配多少內(nèi)存文章來源地址http://www.zghlxwxcb.cn/news/detail-796432.html
到了這里,關于【云原生 | Docker 高級篇】11、Docker 私有鏡像倉庫 Harbor 安裝及使用教程的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!