私有鏡像倉庫Harbor設置https、http訪問

Harbor自簽名證書以https方式訪問UI界面

說明

前文Centos7搭建Harbor私有倉庫(一)中成功搭建了Harbor,但,是以http方式搭建的,這裏咱們修改成https方式及配置Docker以http方式訪問私有倉庫html

生成自簽名證書

這裏咱們使用https://github.com/Fishdrowned/ssl提供的shell腳本生成ssl證書,在命令行中輸入如下命名:linux

git clone https://github.com/Fishdrowned/ssl.git #將項目下載到本地

項目的目錄結構以下:git

.
├── LICENSE
├── README.md
├── ca.cnf
├── docs
│   ├── chrome-certs-details.png
│   ├── chrome-certs-ok.png
│   ├── chrome-settings-certs-imported.png
│   ├── chrome-settings-certs.png
│   ├── chrome-trust.md
│   └── output.png
├── flush.sh
├── gen.cert.sh
└── gen.root.sh

若是須要修改CA、證書相關信息,能夠編輯ca.cnfgen.cert.sh替換對應的內容。接下來,輸入如下命令生成ssl證書,github

./gen.cert.sh registry.anxminise.cc #生成registry.anxminise.cc域名的證書

 

目錄中,會生成一個out目錄,裏面的registry.anxminise.cc目錄存放了生成的證書,內容以下:chrome

 

.
├── 20181011-0710
│   ├── registry.anxminise.cc.bundle.crt
│   ├── registry.anxminise.cc.crt
│   └── registry.anxminise.cc.csr.pem
├── registry.anxminise.cc.bundle.crt -> ./20181011-0710/registry.anxminise.cc.bundle.crt
├── registry.anxminise.cc.crt -> ./20181011-0710/registry.anxminise.cc.crt
├── registry.anxminise.cc.key.pem -> ../cert.key.pem
└── root.crt -> ../root.crt

其中,registry.anxminise.cc.crt是咱們須要的證書,registry.anxminise.cc.key.pem是祕鑰存儲文件,將這兩個文件上傳到Harbor服務器,這裏是192.168.1.112服務器docker

配置Harbor的https證書

Harbor服務器上執行如下命令shell

mkdir -p /data/cert建立證書存放目錄
mv registry.anxminise.cc.crt /data/cert/server.crt #將證書放到Harbor配置目錄下
mv registry.anxminise.cc.key.pem /data/cert/server.key #將祕鑰放到Harbor配置目錄下
ll /data/cert #查看目錄內容

配置Harbor以https啓動

cd /opt/harbor #進入到harbor目錄
vim harbor.cfg #編輯harbor的配置文件

編輯如下內容:json

hostname = registry.anxminise.cc #配置harbor服務器的域名
ui_url_protocol = https #配置https方式啓動

從新配置啓動Harbor

./prepare #從新配置Harbor
./install.sh #從新執行Harbor安裝,注:此處可能有更好的方式重啓

編輯hosts文件以域名方式訪問

cat /etc/hosts
192.168.1.112 registry.anxminise.cc

 

 

Docker以http訪問Harbor私有倉庫

說明

前文Centos7搭建Harbor私有倉庫(一)咱們成功搭建Harbor,本篇咱們主要配置Docker以http方式訪問私有倉庫vim

Docker配置

Mac系統

配置Docker

Mac系統中配置Docker的Preferences -> DaemonInsecure registies中添加192.168.1.112,即:Harbor私服的ip地址,以下:
windows

登陸私有倉庫進行驗證

docker login 192.168.1.112

 

Linux系統

3.1.1 配置Docker

/etc/docker新建daemon.json文件:

mkdir -p /etc/docker #新建docker目錄
vim /etc/docker/daemon.json #新建daemon.json文件

編輯內容以下:

{ "insecure-registries":["192.168.1.112"] }

 

重啓docker

systemctl restart docker

 

3.1.2 登陸私有倉庫進行驗證

docker login 192.168.1.112

 

 

Docker以https訪問Harbor私有倉庫

 

說明

  1. 前文Centos7搭建Harbor私有倉庫(二)中,咱們以https方式搭建了Harbor,本篇咱們主要配置Docker以https方式訪問Harbor私有倉庫

2 Docker配置

2.1 Mac系統

2.1.1 配置Docker

Mac系統中只需配置Proferences -> Proxies使用System Proxy便可,以下:

2.1.2 登陸私服驗證

docker login registry.anxminise.cc #登陸私服

2.2 Windows系統

待補充

2.3 Linux系統

2.3.1 配置registry.anxminise.cc域名

編輯/etc/hosts:

vim /etc/hosts

 

文件最後部分,加入以下:

192.168.1.112 registry.anxminise.cc

 

2.3.2 配置Docker

/etc/docker/certs.d目錄下新建registry.anxminise.cc目錄,

mkdir -p /etc/docker/certs.d/registry.anxminise.cc

https://github.com/Fishdrowned/ssl自簽名生成的根證書,即out目錄下的root.crt證書放到registry.anxminise.cc目錄中,以下:

重啓docker:

systemctl restart docker

 

登陸registry.anxminise.cc私服倉庫:

docker login registry.anxminise.cc

 

 

 

本文出處:https://www.cnblogs.com/anxminise/ 

相關文章
相關標籤/搜索