您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關Harbor 2.0.0安裝及使用,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
背景:隨著工作的不斷推進,鏡像越來越多,部署的機器越來越多,每次部署都需要build一次鏡像非常耗時,尤其是在樹莓派上build帶有pip3 install pandas的鏡像,往往耗時一個小時(雖然apt install python3-pandas快,但目前版本僅支持到0.25.3,1.0.0+的新接口并不支持,如pandas.json_normalize),因而就萌生了將鏡像上傳至鏡像倉庫中,而鏡像倉庫分為公共倉庫和私有倉庫,受限于隱私性,只能考慮私有倉庫,目前的倉庫部署方式:
部署:
服務器主機:
>>> docker pull registry:2
>>> docker run -d -p 5000:5000 --restart always --name registry registry:2
客戶主機:
# 為了使http可用,需添加信任ip
>>> sudo vim /etc/docker/daemon.json
{ "insecure-registries":["服務器主機ip:5000"] }
>>> service docker restart
上傳
>>> docker tag ubuntu:latest 服務器主機ip/test/ubuntu:20.04
>>> docker push 服務器主機ip/test/ubuntu:20.04
可以看到,非常簡單,但是也非常簡陋,存在問題:
缺乏權限控制,理論上只要知道ip、端口、項目名稱、倉庫名稱就能獲取;
無圖形化界面,管理繁瑣
為了解決上述問題,引入Harbor,一個由VMware公司開源的容器鏡像管理工具,貌似是中國團隊開發的,因而原生支持中文,廢話不多說,安裝部署使用方式如下:
安裝環境:
CentOS 7.8.2003
Docker 19.03.11
Docker compose 1.26.0
安裝過程參考:https://juejin.im/post/5d9c2f25f265da5bbb1e3de5
有部分修改
準備:
# 安裝最新版docker
參考:https://docs.docker.com/engine/install/centos/
# 修改docker配置
>>> sed -i '/ExecStart=\/usr\/bin\/dockerd/i\ExecStartPost=\/sbin/iptables -I FORWARD -s 0.0.0.0\/0 -d 0.0.0.0\/0 -j ACCEPT' /usr/lib/systemd/system/docker.service
>>> sed -i '/dockerd/s/$/ \-\-storage\-driver\=overlay2 --insecure-registry 服務器ip/g' /usr/lib/systemd/system/docker.service
# 時間同步
>>> yum -y install ntp
>>> systemctl enable ntpd
>>> systemctl start ntpd
>>> ntpdate -u cn.pool.ntp.org
>>> hwclock --systohc
>>> timedatectl set-timezone Asia/Shanghai
# 關閉swap分區
>>> vim /etc/fstab
#注釋掉SWAP分區項
#/dev/mapper/centos00-swap swap swap defaults 0 0
# 關閉防火墻
>>> systemctl stop firewalld
>>> systemctl disable firewalld
>>> setenforce 0
>>> sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
# 升級內核
>>> rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
>>> rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
>>> yum --enablerepo=elrepo-kernel install kernel-ml -y&&
>>> sed -i s/saved/0/g /etc/default/grub&&
>>> grub2-mkconfig -o /boot/grub2/grub.cfg && reboot
# 安裝docker-compose
>>> curl -L https://github.com/docker/compose/releases/download/1.26.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
>>> chmod +x /usr/local/bin/docker-compose
>>> docker-compose --version
docker-compose version 1.26.0, build d4451659
# 安裝
# 下載在線安裝包
>>> wget https://storage.googleapis.com/harbor-releases/harbor-online-installer-v2.0.0.tgz
>>> tar xf harbor-online-installer-v2.0.0.tgz
>>> cd harbor
安裝:
# 編輯配置文件
>>> vim harbor.yml.tmpl
# 修改hostname
hostname: 服務器ip
# 將https注釋掉,以關閉https支持
# https related config
#https:
# # https port for harbor, default is 443
# port: 443
# # The path of cert and key files for nginx
# certificate: /your/certificate/path
# private_key: /your/private/key/path
# 默認的管理員賬號密碼也可以修改
# 安裝
>>> mv harbor.yml.tmpl harbor.yml
>>> ./install.sh
......
Creating harbor-log ... done
Creating harbor-db ... done
Creating registryctl ... done
Creating harbor-portal ... done
Creating registry ... done
Creating redis ... done
Creating harbor-core ... done
Creating nginx ... done
Creating harbor-jobservice ... done
? ----Harbor has been installed and started successfully.----
>>> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d894c16c987f goharbor/harbor-jobservice:v2.0.0 "/harbor/entrypoint.…" 2 hours ago Up 2 hours (healthy) harbor-jobservice
a3378467ff00 goharbor/nginx-photon:v2.0.0 "nginx -g 'daemon of…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:80->8080/tcp nginx
318b4ad0d0bb goharbor/harbor-core:v2.0.0 "/harbor/entrypoint.…" 2 hours ago Up 2 hours (healthy) harbor-core
9348e1566bd0 goharbor/redis-photon:v2.0.0 "redis-server /etc/r…" 2 hours ago Up 2 hours (healthy) 6379/tcp redis
cc69fe7876b9 goharbor/registry-photon:v2.0.0 "/home/harbor/entryp…" 2 hours ago Up 2 hours (healthy) 5000/tcp registry
dc213cb7c5e8 goharbor/harbor-portal:v2.0.0 "nginx -g 'daemon of…" 2 hours ago Up 2 hours (healthy) 8080/tcp harbor-portal
e69e2ee6d791 goharbor/harbor-registryctl:v2.0.0 "/home/harbor/start.…" 2 hours ago Up 2 hours (healthy) registryctl
8bfcbe9f3d1c goharbor/harbor-db:v2.0.0 "/docker-entrypoint.…" 2 hours ago Up 2 hours (healthy) 5432/tcp harbor-db
59e32a7ecb2a goharbor/harbor-log:v2.0.0 "/bin/sh -c /usr/loc…" 2 hours ago Up 2 hours (healthy) 127.0.0.1:1514->10514/tcp harbor-log
使用:
進入管理界面:http://服務器ip
上傳鏡像:
創建項目:
如果不創建項目,則會報錯‘unauthorized: project not found, name: test: project not found, name: test’
登錄:
# 登錄
>>> docker login 服務器ip
Username:
Password:
Authenticating with existing credentials...
Login Succeeded
# 登出
>>> docker logout 服務器ip
# 登出后再push
>>> docker push 10.8.15.49/test/python:1.0
The push refers to repository [10.8.15.49/test/python]
9867e295092a: Preparing
4a2b3a37baa3: Preparing
64f465a5c456: Preparing
912ca77102af: Preparing
5900cd753a41: Preparing
afae6f50abb9: Waiting
136a15f81f25: Waiting
185574602537: Waiting
24efcd549ab5: Waiting
unauthorized: unauthorized to access repository: test/python, action: push: unauthorized to access repository: test/python, action: push
設置標簽:
>>> docker tag 鏡像名:標簽名 服務器ip/項目名/鏡像名:標簽名
上傳:
>>> docker push 服務器ip/項目名/鏡像名:標簽名
2020-06-11更新
Harbor系統運維
在docker-compose.yml目錄下執行
Stopping Harbor:
#docker-compose stop
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-core ... done
Stopping redis ... done
Stopping registry ... done
Stopping harbor-portal ... done
Stopping registryctl ... done
Stopping harbor-db ... done
Stopping harbor-log ... done
Restarting Harbor after stopping:
#docker-compose start
Starting log ... done
Starting registry ... done
Starting registryctl ... done
Starting postgresql ... done
Starting portal ... done
Starting redis ... done
Starting core ... done
Starting jobservice ... done
Starting proxy ... done
To change Harbor’s configuration, first stop existing Harbor instance and update harbor.cfg.
Then run prepare script to populate the configuration. Finally re-create and start Harbor’s instance:
# docker-compose down
# vim harbor.cfg
# ./prepare
# docker-compose up -d
Removing Harbor’s containers while keeping the image data and Harbor’s database files on the file system:
# docker-compose down
Removing Harbor’s database and image data (for a clean re-installation):
# rm -r /data/database
# rm -r /data/registry
修改監聽端口(默認監聽80端口)
Configuring Harbor listening on a customized port.
By default, Harbor listens on port 80(HTTP) and 443(HTTPS, if configured) for both admin portal and docker commands, you can configure it with a customized one.
For HTTP protocol
Modify docker-compose.yml,Replace the first “80” to a customized port, e.g. 8888:80.
# vim docker-compose.yml
proxy:
image: library/nginx:1.11.5
restart: always
volumes:
- ./config/nginx:/etc/nginx
ports:
- 8888:80
- 443:443
depends_on:
- mysql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
Modify harbor.cfg, add the port to the parameter “hostname”.
# vim harbor.cfg
hostname = 10.90.5.105:8888
Re-deploy Harbor refering to previous section.
# docker-compose down
# ./prepare
# docker-compose up -d
以上就是Harbor 2.0.0安裝及使用,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。