總結—Harbor倉庫部署和使用問題集錦

前言

離線手動部署docker鏡像倉庫——harbor倉庫(一) 離線手動部署docker鏡像倉庫——harbor倉庫(二)的實驗中,遇到一些harbor倉庫部署的問題,在此做個小結。
實驗環境:
harbor服務器系統:CentOS Linux release 7.4.1708 (Core)
harbor服務器IP:10.0.0.101(test101)
harbor版本:v1.5.0
docker版本:1.13.1
使用了另一臺機器做pull和push鏡像測試:10.0.0.102(test102)

問題集錦

1、docker配置文件沒生效,引起的push鏡像失敗,報錯10.0.0.101:443: getsockopt: connection refused

問題描述:

在test101機器剛剛部署好harbor的時候,push鏡像失敗了,報“Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused”

[root@test101 nginx]# docker push 10.0.0.101/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101/test/bigdatacenter]
Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused
[root@test101 nginx]# 

原因分析:

是因爲配置文件裏面配置的--insecure-registry=10.0.0.101這一行配置沒有生效(修改了配置之後,有重啓docker,但是這行內容也沒有加載成功):
總結—Harbor倉庫部署和使用問題集錦

解決方法:

再次重新啓動了docker服務,使之重新加載配置文件

[root@test101 harbor]# systemctl daemon-reload     #重啓docker之前,先執行了這個步驟,很重要
[root@test101harbor]# systemctl restart docker

然後測試登錄harbor倉庫,就OK了:

[root@test101 harbor]# docker login 10.0.0.101
Username: admin
Password: 
Login Succeeded

再push鏡像就成功了:

[root@test101 harbor]# docker push 10.0.0.101/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101/test/bigdatacenter]
df9d7f53cb5b: Pushed 
ab0926f7eb13: Pushed 
24a30430d761: Pushed 
20dd87a4c2ab: Layer already exists 
78075328e0da: Layer already exists 
9f8566ee5135: Layer already exists 
latest: digest: sha256:07c467b4f8c6cfa306484bd060721fb621ddb1fd43f528ef5a0df1157d8bd853 size: 1573
[root@test101 harbor]#

2、端口問題引起的pull鏡像報錯Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused

問題描述:

把harbor端口默認的80端口修改爲1180,然後打了個測試鏡像上去,但是在test102機器pull鏡像的時候失敗了,報錯如下:

[root@test102 ~]# docker pull 10.0.0.101/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101/test/bigdatacenter ... 
Get https://10.0.0.101/v1/_ping: dial tcp 10.0.0.101:443: getsockopt: connection refused

解決辦法:

1)想起來test102機器上的docker的配置文件沒有修改,於是在 /etc/sysconfig/docker 加上了“--insecure-registry=10.0.0.101:1180”:
總結—Harbor倉庫部署和使用問題集錦
然後重啓了docker服務:

[root@test102 ~]# systemctl restart docker
[root@test102 ~]# 

再重新pull鏡像,發現報錯不一樣了:

[root@test102 ~]# docker pull 10.0.0.101/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101/test/bigdatacenter ... 
Pulling repository 10.0.0.101/test/bigdatacenter
Error while pulling image: Get http://10.0.0.101/v1/repositories/test/bigdatacenter/images: dial tcp 10.0.0.101:80: getsockopt: connection refused

2)報錯dial tcp 10.0.0.101:80: getsockopt: connection refused,是因爲鏡像名稱裏面沒有加上1180端口,就默認去80端口找鏡像了,於是在命令裏面加上了1180端口:

[root@test102 ~]# docker pull 10.0.0.101:1180/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101:1180/test/bigdatacenter ... 
Get https://10.0.0.101:1180/v1/_ping: http: server gave HTTP response to HTTPS client   #關於這個報錯,網上有很多文章說是關於docker和harbor之間的交互存在一個http和https之間的問題,建議改/etc/docker/daemon.json 。但是按照網上的方法試了,改了/etc/docker/daemon.json 之後,docker服務起不來,沒法解決。最後還是嘗試使用systemctl daemon-reload+systemctl restart docker兩條命令解決了問題
[root@test102 ~]# 

3)加上1180端口之後,報錯不一樣了,於是試着像上一個問題一樣,嘗試執行systemctl daemon-reload命令。重新載入 systemd,掃描新的或有變動的單元,然後再重啓docker:

[root@test102 ~]# systemctl daemon-reload
[root@test102 ~]# systemctl restart docker

再pull鏡像,發現就成功了!

[root@test102 ~]# docker pull 10.0.0.101:1180/test/bigdatacenter:latest
Trying to pull repository 10.0.0.101:1180/test/bigdatacenter ... 
latest: Pulling from 10.0.0.101:1180/test/bigdatacenter
53478ce18e19: Pull complete 
d1c225ed7c34: Pull complete 
c6724ba0c09a: Pull complete 
de3b8705ee9f: Pull complete 
c091a284f068: Pull complete 
010503dbdd2d: Pull complete 
Digest: sha256:ce823873379c519a583756783923dd160473a60fcf78dfd869e8b33f5198f237
Status: Downloaded newer image for 10.0.0.101:1180/test/bigdatacenter:latest
[root@test102 ~]# 

注意,問題1和2說明,修改了docker的配置文件 /etc/sysconfig/docker之後,重啓docker服務,文件不一定生效了,如果發現沒生效,別忘了“systemctl daemon-reload”這條命令!

3、push鏡像失敗,報denied: requested access to the resource is denied

問題描述:

部署好harbor倉庫的時候,push鏡像失敗了,報denied: requested access to the resource is denied

[root@test101 harbor]# docker push 10.0.0.101:1180/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101:1180/test/bigdatacenter]
d7393e4babfa: Preparing 
d8db36d925b6: Preparing 
93fc2863a9fb: Preparing 
20dd87a4c2ab: Preparing 
78075328e0da: Preparing 
9f8566ee5135: Waiting 
denied: requested access to the resource is denied

解決辦法:

遇到這種情況,登錄一下harbor倉庫,登錄成功,就OK了。
關於原因和解決方法,在網上查了,說法不一,也有很多其他的方法,但是沒有試過,就試着登錄了一下,然後問題就解決了,部署過程中遇到好幾次這個問題,都是這樣解決的。當換了用戶名/密碼/端口/域名什麼的,在push鏡像的時候就可能會出現這個問題。

[root@test101 harbor]# docker login 10.0.0.101:1180      #登錄一下就好了
Username: admin
Password: 
Login Succeeded

然後再重新push鏡像,就成功了

[root@test101 harbor]# docker push 10.0.0.101:1180/test/bigdatacenter:latest
The push refers to a repository [10.0.0.101:1180/test/bigdatacenter]
d7393e4babfa: Pushed 
d8db36d925b6: Pushed 
93fc2863a9fb: Pushed 
20dd87a4c2ab: Pushed 
78075328e0da: Pushed 
9f8566ee5135: Pushed 
latest: digest: sha256:63a86f231cf0415fe02ac11e31b00a959563ff3e264955c7c0236bd398b1c775 size: 1573
[root@test101 harbor]# 

4、360瀏覽器設置問題引起的harbor倉庫訪問異常

問題描述:

部署好harbor倉庫之後,發現瀏覽器訪問界面出不來,一直處於這樣的狀態:
總結—Harbor倉庫部署和使用問題集錦

原因分析:

後來發現因爲這臺機器上只有360瀏覽器,存在模式的區別,現在用的是默認的兼容模式,所以界面出不來,並非服務的問題。

解決辦法:

把瀏覽器換成極速模式就好了:
總結—Harbor倉庫部署和使用問題集錦
爲了避免這種不必要的問題,最好不要用360這樣的瀏覽器,最好使用谷歌瀏覽器

5、harbor項目訪問級別引起pull鏡像失敗

問題描述:

測試在rancher2.0上部署一個harbor倉庫的服務到服務器上,發現拉取鏡像失敗,報錯repository does not exist or may require ‘docker login’:
總結—Harbor倉庫部署和使用問題集錦

原因分析:

因爲harbor倉庫的項目訪問級別設置成了私有,所以rancher-server和agent服務器都訪問不到,因此報錯無法拉取鏡像。
因爲在服務器上測試手動pull鏡像,是測試的公開項目裏面的鏡像,所以沒有發現該問題:
總結—Harbor倉庫部署和使用問題集錦

解決方法:

將harbor上面項目的訪問級別設置爲公開,就好了

6、錯誤配置harbor地址,導致pull鏡像失敗

問題描述:

在另一次使用rancher2.0測試部署服務的時候,服務器上拉取了harbor倉庫的web鏡像,但是拉取鏡像一直失敗,報錯如下:
總結—Harbor倉庫部署和使用問題集錦

原因分析:

看到這個熟悉的錯誤信息,馬上查看docker配置文件,發現harbor的地址多寫了個http://
總結—Harbor倉庫部署和使用問題集錦

解決方法:

去掉配置文件的http:// 然後重啓docker服務即可:
總結—Harbor倉庫部署和使用問題集錦

然後重啓docker服務,重新部署,恢復正常:
總結—Harbor倉庫部署和使用問題集錦

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