harbor安裝(1.6.0)
阿新 • • 發佈:2021-12-25
pw參考文件
安裝文件:https://goharbor.io/docs/2.2.0/install-config/download-installer/
github:https://github.com/goharbor/harbor
環境準備
系統型別 | IP地址 | 節點角色 | CPU | Memory | Hostname |
---|---|---|---|---|---|
centos-7.9 | 192.168.10.182 | master,worker,etcd | >=2 | >=2G | harbor1 |
centos-7.9 | 192.168.10.183 | worker,etcd | >=2 | >=2G | harbor2 |
-
採用雙主複製的,前端負載nginx的方式進行部署
-
harbor版本:1.6.0
-
修改hostname
# hostnamectl set-hostname harbor1 # hostnamectl set-hostname harbor2
-
關閉防火牆、selinux、swap,重置iptables
# 關閉selinux # setenforce 0 # sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config # 關閉防火牆 # systemctl stop firewalld && systemctl disable firewalld # 關閉swap # swapoff -a && free –h #或者在這裡刪除swap掛載 # vim /etc/fstab # 關閉dnsmasq(否則可能導致容器無法解析域名) # service dnsmasq stop && systemctl disable dnsmasq
-
安裝docker
安裝
-
上傳harbor-offline-installer-v1.6.0軟體包 並解壓 兩臺節點同時執行
# mkdir /opt/harbor # cd /opt/harbor/ # ls harbor-offline-installer-v1.6.0.tgz #解壓 # tar vxf harbor-offline-installer-v1.6.0.tgz # cd harbor
-
上傳docker compose 並且mv為可執行檔案(兩臺機器執行)
# pwd /opt/harbor # ll total 690056 -rw-r--r-- 1 root root 11750136 May 10 16:14 docker-compose-Linux-x86_64-1.22.0 drwxr-xr-x 4 root root 294 May 10 16:13 harbor -rw-r--r-- 1 root root 694863055 May 10 16:04 harbor-offline-installer-v1.6.0.tgz # mv docker-compose-Linux-x86_64-1.22.0 /usr/local/bin/docker-compose # chmod +x /usr/local/bin/docker-compose # docker-compose --version
-
編輯配置檔案(兩臺機器執行)
# cd harbor #修改hostname為當前ip和登入密碼 因為要做ha 不能使用域名 其他的不動 # vim harbor.cfg …… hostname=192.168.10.160 harbor_admin_password = Harbor12345 ……
-
修改docker-compose.yml檔案(兩臺機器執行)
# 將所有volumes檔案放到大磁碟下 如果不需要更改 則預設 # vim docker-compose.yml
-
安裝(兩臺機器執行)
# ./install.sh
-
安裝完畢後登入harbor
# curl http://192.168.10.160 # curl http://192.168.10.161 #使用者名稱 admin 密碼為Harbor12345
-
部署nginx 用docker部署 編寫配置檔案
[root@harbor1 harbor]# docker pull nginx:1.7.9 [root@harbor1 harbor]# mkdir /opt/harbor/nginx [root@harbor1 harbor]# cd /opt/harbor/nginx #編輯配置檔案 [root@harbor1 nginx]# vim nginx.conf user nginx; worker_processes 2; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { upstream harbor { server 192.168.10.160:80; } server { listen 8080; location / { proxy_pass http://harbor; } } }
-
編寫啟動指令碼
[root@harbor1 nginx]# vim restart.sh #!/bin/bash docker stop harbornginx docker rm harbornginx #掛載本地檔案 docker run -idt --net=host --name harbornginx -v /opt/harbor/nginx/nginx.conf:/etc/nginx/nginx.conf nginx:1.7.9 [root@harbor1 nginx]# sh restart.sh harbornginx harbornginx f701f495327f318ce8d100b1bf41e9466204db61d3bc19c158ca93576ed2d7ef #檢視日誌 [root@harbor1 nginx]# docker logs f7 #測試訪問 # curl http://192.168.10.160:8080/harbor/sign-in
-
編輯docker配置檔案 允許指定ip來訪問
[root@harbor1 nginx]# vim /etc/docker/daemon.json { "insecure-registries": ["192.168.10.160","192.168.10.161"] } [root@harbor1 nginx]# systemctl restart docker
-
在harbor新建一個專案
-
建立一個harbor使用者:testpush/Ttestpush123.
-
將新使用者新增到專案裡
建立一個harbor使用者:testpush/Ttestpush123.
-
在harbor新建一個公開專案test, 然後推送一個映象
# 先打一個tag [root@harbor1 nginx]# docker tag nginx:1.7.9 192.168.10.160/test/nginx:1.7.9 #登入 [root@harbor1 nginx]# docker login 192.168.10.160 Username: testpush Password: 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 #push 成功 [root@harbor1 nginx]# docker push 192.168.10.160/test/nginx:1.7.9
-
檢視倉庫是否有了
-
測試 161節點pull一下
[root@harbor2 harbor]# docker login 192.168.10.160 Username: testpush Password: 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 #pull成功 [root@harbor2 harbor]# docker pull 192.168.10.160/test/nginx:1.7.9 1.7.9: Pulling from test/nginx 4f4fb700ef54: Pull complete 8c71e11b018e: Pull complete 32a497444d35: Pull complete 8f6a37a5f8b6: Pull complete b0568fa3217a: Pull complete 2188268d060d: Pull complete 5af4b0ff64b0: Pull complete Digest: sha256:b1f5935eb2e9e2ae89c0b3e2e148c19068d91ca502e857052f14db230443e4c2 Status: Downloaded newer image for 192.168.10.160/test/nginx:1.7.9 192.168.10.160/test/nginx:1.7.9
-
雙主複製配置 登入http://192.168.10.160/
-
倉庫管理->新建目標 填寫需要複製的倉庫目標
-
複製管理->新建規則,關聯上面建立的161目標倉庫
-
160檢視複製結果
-
同理,161建立複製規則到160 達到雙向複製
-
161複製管理新建規則到160
-
161檢視複製結果
-
結論
雙主複製的時候兩邊映象是通過對比映象簽名來完成是否是同一個映象的,如果是同一個映象則不盡興復制