centos7搭建harbor私有倉庫
軟件包下載
wget http://harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
下面開始安裝部署,需事先安裝docker、docker-compose
docker和docker-compose的安裝教程可參照我的博客
[root@localhost ~]# mkdir harbor
[root@localhost ~]# cd harbor/
[root@localhost harbor]# ls
harbor-offline-installer-v1.2.2.tgz
[root@localhost harbor]# tar -xf harbor-offline-installer-v1.2.2.tgz
[root@localhost harbor]# mv harbor /usr/local/
修改配置文件
[root@localhost harbor]# vim /usr/local/harbor/harbor.cfg
# 修改hostname,不要使用localhost或者127.0.0.1
hostname = 192.168.218.142
配置文件一些參數解釋:
hostname:
用於訪問用戶界面和 register服務。它應該是目標機器的IP地址或完全限定的域名(FQDN)
例如192.168.195.128或 hub.kgc.cn。不要使用 localhost或127.0.0.1爲主機名。
ui_url_protocol:
(http或https默認爲http)用於訪問UI和令牌/通知服務的協議。如果公證處於啓用狀態,則此參數必須爲https
max_job_workers:鏡像復製作業線程。
db_ password:用於 db_auth的 MySQL數據庫root用戶的密碼。
customize_crt:
該屬性可設置爲打開或關閉,默認打開。打開此屬性時,準備腳本創建私鑰和根證書,用於生成/驗證註冊表令牌。當由外部來源提供密鑰和根證書時,將此屬性設置爲off
ssI_cert:SSL證書的路徑,僅當協議設置爲https時才應用。
ssl_cert_key:SSL密鑰的路徑,僅當協議設置爲https吋才應用。
secretkey_path:用於在複製策略中加密或解密遠程 register密碼的密鑰路徑。
以上的參數爲所需參數,如果安裝之後需要修改這些參數,則需要重新安裝harbor
下面爲可選參數,可在安裝完成後在web 上進行修改;這些參數只會在第一次啓動harbor時生效,如果後來被更新,則配置文件中的值會被忽略
Email:
Harbor需要該參數才能向用戶發送“密碼重置”電子郵件,並且只有在需要該功能時才需要。
請注意,在默認情況下SSL連接時沒有啓用。如果SMTP服務器需要SSL,但不支持 STARTTLS,
那麼應該通過設置啓用 SSL email_ssl=TRUE。
harbor_admin_password:
管理員的初始密碼,只在 Harbour第一次啓動時生效。之後,此設置將被忽略,並且應Ul中設置管理員的密碼。
請注意,默認的用戶名/密碼是 admin/ Harbor12345。
auth_mode:
使用的認證類型,默認情況下,它是 db_auth,即憑據存儲在數據庫中。對於LDAP身份驗證,請將其設置爲ldap_auth
self_registration:
啓用/禁用用戶註冊功能。禁用時,新用戶只能由 Admin用戶創建,只有管理員用戶可以在 Harbour中創建新用戶。
注意:當 auth_mode設置爲 Idap_auth時,自注冊功能將始終處於禁用狀態,並且該標誌被忽略。
Token_expiration:由令牌服務創建的令牌的到期時間(分鐘),默認爲30分鐘。
project_creation_restriction:
用於控制哪些用戶有權創建項目的標誌。默認情況下,每個人都可以創建一個項目。如果將其值設置爲“ adminonly”,那麼只有 admin可以創建項日。
verify_remote_cert:
打開或關閉,默認打開。此標誌決定了當 Harbor與遠程 register實例
通信時是否驗證 SSL/TLS證書。將此屬性設置爲off將繞過SSL/TLS驗證,這在遠程實例具有自簽名或不可信證書時經常使用。
安裝harbor,直接運行install.sh這個腳本
[root@localhost harbor]# sh /usr/local/harbor/install.sh
最後安裝成功,輸出如下:
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.218.142.
For more details, please visit https://github.com/vmware/harbor .
查看harbor容器狀態,docker-compose因爲需要找到相應的配置文件,故需要進入harbor的目錄下,再執行docker-compose命令
[root@localhost harbor]# cd /usr/local/harbor
[root@localhost harbor]# docker-compose ps
Name Command State Ports
------------------------------------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/harbor_adminserver Up
harbor-db docker-entrypoint.sh mysqld Up 3306/tcp
harbor-jobservice /harbor/harbor_jobservice Up
harbor-log /bin/sh -c crond && rm -f ... Up 127.0.0.1:1514->514/tcp
harbor-ui /harbor/harbor_ui Up
nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp, 0.0.0.0:80->80/tcp
registry /entrypoint.sh serve /etc/ ... Up 5000/tcp
使用admin登陸harbor,密碼爲默認的Harbor12345
[root@localhost harbor]# docker login -u admin -p Harbor12345 http://127.0.0.1
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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
在瀏覽器訪問http://192.168.218.142,即可訪問harbor網頁端
如圖:
嘗試上傳鏡像
在瀏覽器端,創建一個新的project,名爲test
修改鏡像名,格式爲:harbor-ip/project-name/image
注意,如果harbor上沒有對應的project,是不能上傳成功 的!
[root@localhost harbor]# docker tag nginx 127.0.0.1/test/nginx:v1
[root@localhost harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1/test/nginx v1 e791337790a6 5 days ago 127MB
......
開始上傳
[root@localhost harbor]# docker push 127.0.0.1/test/nginx:v1
The push refers to repository [127.0.0.1/test/nginx]
be91fceb796e: Pushed
919b6770519b: Pushing [==========================================> ] 48.68MB/57.56MB
b60e5c3bcef2: Pushing [======================> ] 30.91MB/69.21MB
待最後上傳完畢,到瀏覽器查看我們剛剛上傳的鏡像
可以看到,鏡像已成功上傳
下面將本地的127.0.0.1/test/nginx:v1鏡像刪除,再嘗試從倉庫中拉取鏡像
[root@localhost harbor]# docker rmi 127.0.0.1/test/nginx:v1
Untagged: 127.0.0.1/test/nginx:v1
Untagged: 127.0.0.1/test/nginx@sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
拉取
[root@localhost harbor]# docker pull 127.0.0.1/test/nginx:v1
v1: Pulling from test/nginx
Digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
Status: Downloaded newer image for 127.0.0.1/test/nginx:v1
127.0.0.1/test/nginx:v1
[root@localhost harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest e791337790a6 5 days ago 127MB
127.0.0.1/test/nginx v1 e791337790a6 5 days ago 127MB
倉庫的鏡像已成功拉取到本地