Harbor部署(HTTP與HTTPS)

一、簡介

Harbor是一個用於存儲和分發Docker鏡像的企業級Registry服務器,通過添加一些企業必需的功能特性,例如安全、標識和管理等,擴展了開源Docker Distribution。作爲一個企業級私有Registry服務器,Harbor提供了更好的性能和安全。提升用戶使用Registry構建和運行環境傳輸鏡像的效率。Harbor支持安裝在多個Registry節點的鏡像資源複製,鏡像全部保存在私有Registry中, 確保數據和知識產權在公司內部網絡中管控。另外,Harbor也提供了高級的安全特性,諸如用戶管理,訪問控制和活動審計等。

二、Harbor特徵

  • 基於角色的訪問控制 :用戶與Docker鏡像倉庫通過“項目”進行組織管理,一個用戶可以對多個鏡像倉庫在同一命名空間(project)裏有不同的權限。
  • 鏡像複製 : 鏡像可以在多個Registry實例中複製(同步)。尤其適合於負載均衡,高可用,混合雲和多雲的場景。
  • 圖形化用戶界面 : 用戶可以通過瀏覽器來瀏覽,檢索當前Docker鏡像倉庫,管理項目和命名空間。
  • AD/LDAP 支持 : Harbor可以集成企業內部已有的AD/LDAP,用於鑑權認證管理。
  • 審計管理 : 所有針對鏡像倉庫的操作都可以被記錄追溯,用於審計管理。
  • 國際化 : 已擁有英文、中文、德文、日文和俄文的本地化版本。更多的語言將會添加進來。
  • RESTful API : RESTful API 提供給管理員對於Harbor更多的操控, 使得與其它管理軟件集成變得更容易。
  • 部署簡單 : 提供在線和離線兩種安裝工具, 也可以安裝到vSphere平臺(OVA方式)虛擬設備。

三、離線安裝Harbor

下載離線安裝包,500多M,有點兒大,在xshell下載半天都不動,複製鏈接到瀏覽器一會er就下載完了

wget  https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-offline-installer-v1.7.4.tgz

安裝epel源

docker-compose在epel倉庫中

[root@n1 ~]# yum install epel-release -y

需要用到Docker Compose

[root@n1 harbor]# yum install docker-compose -y

解壓

[root@n1 ~]# tar xf harbor-offline-installer-v1.7.4.tgz -C /usr/local/

修改配置文件

[root@n1 harbor]# pwd

/usr/local/harbor

[root@n1 harbor]# vim harbor.cfg

hostname = n1.realxw.com  #設置主機名
harbor_admin_password = Harbor12345  #設置harbor管理員登錄密碼
db_password = root123  #設置數據庫登錄密碼

開始安裝

[root@n1 harbor]# ./prepare

[root@n1 harbor]# ./install.sh

✔ ----Harbor has been installed and started successfully.----

查看相關端口是否開啓

圖片.png

安裝成功!

四、測試

默認用戶登錄

用戶名:admin,密碼:Harbor

創建普通用戶及項目

瀏覽器輸入IP地址

http://192.168.231.60

圖片.png

創建普通用戶

圖片.png

用realxw用戶登錄

圖片.png

創建一個devel項目,項目下邊可以有多個倉庫

圖片.png

向鏡像倉庫中推送鏡像,需要安裝提示打標籤

配置

想要推鏡像,需要設置非安全倉庫(這裏使用http協議,沒有使用https)

[root@n1 ~]# vim /etc/docker/daemon.json

{

"registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com","https://registry.docker-cn.com"],
"insecure-registries": ["n1.realxw.com"]   #添加
}

添加解析記錄

[root@n1 ~]# vim /etc/hosts

192.168.231.60 n1.realxw.com

修改i配置文件後重啓docker

[root@n1 ~]# systemctl restart docker

再次登錄時會出現用戶登錄用戶名或密碼錯誤,是因爲harbor的相關容器關閉,需要用docker-compose啓動harbor

[root@n1 harbor]# pwd

/usr/local/harbor#切換到harbor目錄,使docker-compose能找到docker-compose.yml

[root@n1 harbor]# docker-compose start   #停止服務,使用stop

登錄Harbor

圖片.png

推送鏡像

拉取busybox鏡像

[root@n1 ~]# docker pull busybox:latest

爲busybox鏡像打標籤

[root@n1 ~]# docker tag busybox:latest n1.realxw.com/devel/busybox:v1

 [root@n1 ~]# docker push  n1.realxw.com/devel/busybox:v1

The push refers to repository [n1.realxw.com/devel/busybox]

adab5d09ba79: Pushed

v1: digest: sha256:4415a904b1aca178c2450fd54928ab362825e863c0ad5452fd020e92f7a6a47e size: 527

推送成功

五、配置HTTPS

這裏是後續補充,不是在上邊主機部署

生成自簽證書

[root@zhangshibin ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3650

創建數據庫文件

[root@zhangshibin ~]# touch  /etc/pki/CA/index.txt

序列號文件並給明第一個證書的序列號碼

[root@zhangshibin ~]# echo 01 > /etc/pki/CA/serial

生成祕鑰

[root@zhangshibin test]# (umask 077; openssl genrsa -out docker.key 1024)

生成證書請求文件

[root@zhangshibin test]# openssl req -new -key docker.key -out docker.csr

CA簽署證書

[root@zhangshibin test]# openssl ca -in docker.csr -out docker.crt -days 365

[root@zhangshibin ~]# mkdir -p /etc/docker/certs.d/192.168.231.30

[root@zhangshibin test]# cp docker.key /etc/docker/certs.d/192.168.231.30/

[root@zhangshibin test]# cp docker.crt /etc/docker/certs.d/192.168.231.30/

修改配置文件

[root@zhangshibin ~]# vim harbor/harbor.cfg

ui_url_protocol = https

ssl_cert = /etc/docker/certs.d/192.168.231.30/docker.crt

ssl_cert_key = /etc/docker/certs.d/192.168.231.30/docker.key

更新配置文件

[root@zhangshibin harbor]# ./prepare

[root@zhangshibin harbor]# docker-compose restart

編輯/etc/docker/daemon.json

刪除"insecure-registries": ["192.168.231.30"]

重啓docker

[root@zhangshibin ~]# systemctl restart docker.servic

瀏覽器訪問

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章