溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

企業(yè)級鏡像倉庫harbor搭建(http/https)及使用

發(fā)布時間:2020-07-24 07:02:11 來源:網(wǎng)絡 閱讀:4536 作者:slitobo 欄目:云計算

1.Harbor簡介
Harbor是由VMWare公司開源的容器鏡像倉庫。事實上,Harbor是在Docker Registry上進行了相應的企業(yè)級擴展,從而獲得了更加廣泛的應用,這些新的企業(yè)級特性包括:管理用戶界面,基于角色的訪問控制,AD/LDAP集成以及審計日志等,足以滿足基本企業(yè)需求。
2.安裝docker-ce
1)安裝依賴包
[root@harbor opt]# yum install -y yum-utils device-mapper-persistent-data lvm2
2)下載docker-ce 倉庫
[root@harbor opt]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
官方比較慢的話,可以使用阿里云的docker-ce.repo
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3)更新倉庫
yum repolist 或者 yum makecache fast
4)安裝docker-ce
[root@harbor opt]# yum install docker-ce -y
5)配置加速并啟動
[root@harbor opt]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
[root@harbor opt]# systemctl start docker
6) 確認安裝完成
[root@harbor opt]# docker version
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
3.安裝docker-compose
第一種方式:yum 安裝
[root@harbor opt]# yum install docker-compose -y
第二種方式:下載可執(zhí)行文件:
[root@harbor opt]# curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
[root@harbor opt]# chmod +x /usr/local/bin/docker-compose
確認安裝完成:
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
4.安裝harbor
[root@harbor opt]# cd /opt
[root@harbor opt]# wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.6.1.tgz
[root@harbor opt]# tar -xf harbor-offline-installer-v1.6.1.tgz
[root@harbor opt]# cd harbor/
[root@harbor opt]# vim harbor.cfg
hostname = reg.slito.com \harbor的服務地址(ip或者域名)
ui_url_protocol = http \選擇http方式
harbor_admin_password = 123456 \harbor web訪問的密碼
[root@harbor harbor]# ./prepare \加載配置
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
[root@harbor harbor]# ./install.sh \安裝harbor
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
安裝完成后,提示通過“ http://reg.slito.com” 訪問harbor,用戶名是admin,密碼是之前設置的123456
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
5.上傳鏡像到harbor倉庫
在本機配置harbor倉庫http可信
/etc/docker/daemon.json中添加“"insecure-registries":["reg.slito.com"]”,重啟docker
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
不然會報錯,默認是走https的
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
在node1上登錄harbor倉庫,上傳/下載鏡像
[root@node1 ~]# docker login reg.slito.com
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@node1 ~]# docker tag busybox reg.slito.com/library/busybox:v1
[root@node1 ~]# docker push reg.slito.com/library/busybox:v1
The push refers to repository [reg.slito.com/library/busybox]
8a788232037e: Pushed
v1: digest: sha256:915f390a8912e16d4beb8689720a17348f3f6d1a7b659697df850ab625ea29d5 size: 527
[root@node1 ~]#
在harbor中查看
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
6.下載harbor中的鏡像
先刪掉原來的鏡像
[root@node1 ~]# docker rmi reg.slito.com/library/busybox:v1
重新從harbor pull
[root@node1 ~]# docker pull reg.slito.com/library/busybox:v1
確認
[root@node1 ~]# docker images | grep busybox
reg.slito.com/library/busybox v1 59788edf1f3e 8 weeks ago 1.15MB

7.配置https訪問
1) 安裝openssl
#yum install openssl -y
2) 創(chuàng)建證書的database文件index.txt和序列文件serial
[root@harbor opt]# touch /etc/pki/CA/index.txt
[root@harbor opt]# echo "01" > /etc/pki/CA/serial
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用

3) 創(chuàng)建私鑰,生成自簽證書(用于發(fā)放給個人用戶)
#(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem)
#openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
4) 客戶端生成證書請求(.csr)
#cd /opt/harbor
#mkdir ssl
#cd ssl
#(umask 077;openssl genrsa -out reg.slito.com.key) \生成私鑰
#openssl req -new -key reg.slito.com.key -out reg.slito.com.csr \ 生成證書請求
和上面cacert.pem生成時寫的結果保持一致
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
5) 簽發(fā)證書(本機是CA同時又是申請證書的客戶端)
#cd /opt/harbor/ssl
#openssl ca -in reg.slito.com.csr -out reg.slito.com.crt -days 365
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
6) 修改配置文件,重新啟動harbor
#cd /opt/harbor
#docker-compose down -v
#vim harbor.cfg
ui_url_protocol = https
ssl_cert = ./ssl/reg.slito.com.crt
ssl_cert_key = ./ssl/cert/reg.slito.com.key
secretkey_path = ./ssl/
#./prepare
#./install.sh
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
訪問“https://reg.slito.com”
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用
7) 其他主機訪問harbor,pull/push鏡像設置
拷貝reg.slito.com.crt到需要訪問harbor倉庫的主機上(/etc/docker/certs.d/reg.slito.com/),目標主機不用配置信任就可以直接訪問。
#cp /opt/harbor/ssl/reg.slito.com.crt /etc/docker/certs.d/reg.slito.com/
企業(yè)級鏡像倉庫harbor搭建(http/https)及使用

其他:關于https訪問,可以看另一篇博客https://blog.51cto.com/slitobo/1931603

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI