Ubuntu22.04 LTS 部署harbor-v2.7.2高可用
Ubuntu22.04 LTS 部署harbor高可用环境预备
均需要docker环境
IP主机名10.0.0.20harbor0110.0.0.21harbor02一、harbor 环境部署
1. 下载harbor包
# wget https://github.com/goharbor/harbor/releases/download/v2.7.2/harbor-offline-installer-v2.7.2.tgz2. 解压软件包
# tar xf harbor-offline-installer-v2.7.2.tgz -C /caixiangjia/softwares/
# cd /caixiangjia/softwares/harbor/3. 预备配置文件
# cp harbor.yml.tmpl harbor.yml
# ll harbor.yml*
-rw-r--r-- 1 root root 11567 Dec 14 21:13 harbor.yml
-rw-r--r-- 1 root root 11567 Apr 242023 harbor.yml.tmpl4. 编辑harbor配置文件
...
hostname: 10.0.0.20
...
12 # https related config
13 #https:
14 ## https port for harbor, default is 443
15 #port: 443
16 ## The path of cert and key files for nginx
17 #certificate: /your/certificate/path
18 #private_key: /your/private/key/path
...
34 harbor_admin_password: 1
...
53 data_volume: /caixiangjia/data/harbor
...
# 此处方便后期prometheus监控
220 metric:
221 enabled: true
222 port: 9099
223 path: /metrics5. 安装 harbor
# ./install.sh --with-chartmuseum
...
[+] Building 0.0s (0/0) docker:default
[+] Running 13/13
✔ Network harbor_harbor-chartmuseumCreated 0.1s
✔ Network harbor_harbor Created 0.1s
✔ Container harbor-log Started 0.0s
✔ Container chartmuseum Started 0.0s
✔ Container registry Started 0.0s
✔ Container registryctl Started 0.0s
✔ Container harbor-portal Started 0.0s
✔ Container harbor-db Started 0.0s
✔ Container redis Started 0.0s
✔ Container harbor-core Started 0.0s
✔ Container nginx Started 0.0s
✔ Container harbor-jobservice Started 0.0s
✔ Container harbor-exporter Started 0.0s
✔ ----Harbor has been installed and started successfully.----6. 访问 harbor 的 WebUI
http://10.0.0.20/
用户名:admin
密码:1https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214225543367-2038443162.png
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214225701484-2071530512.png
二、harbor 的基本使用
1. 客户端配置
# cat /etc/docker/daemon.json
{
"insecure-registries": ["10.0.0.20"]
}
# systemctl restart docker.service 2. harbor 创建仓库
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214225805745-1890237321.png
3. 给镜像打 tag
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d2c94e258dcb 19 months ago 13.3kB
# docker tag hello-world:latest 10.0.0.20/test/hello-world-latesthttps://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214225829681-1462556.png
4. 推送镜像到harbor仓库
# 未登录之前
# docker push 10.0.0.20/test/hello-world
Using default tag: latest
The push refers to repository
ac28800ec8bb: Preparing
unauthorized: unauthorized to access repository: test/hello-world, action: push: unauthorized to access repository: test/hello-world, action: push
# docker login 10.0.0.20
Username: admin # 输入用户名
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
# 登录成功后会保存登录信息
# more /root/.docker/config.json
{
"auths": {
"10.0.0.20": {
"auth": "YWRtaW46MQ=="
}
}
}
# 通过 base64 -d 查看你的密码
# echo YWRtaW46MQ== | base64 -d | more
admin:1
#登录之后
# docker push 10.0.0.20/test/hello-world
Using default tag: latest
The push refers to repository
ac28800ec8bb: Pushed
latest: digest: sha256:d37ada95d47ad12224c205a938129df7a3e52345828b4fa27b03a98825d1e2e7 size: 5245.web页面查看
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214225851744-353242025.png
6. 推送镜像完成后立刻退出(制止密码走漏)
# docker logout 10.0.0.20
Removing login credentials for 10.0.0.20
# more /root/.docker/config.json
{
"auths": {}
}
7. 其他客户端拉取镜像,【需要配置信任仓库】
# cat /etc/docker/daemon.json
{
"insecure-registries": ["10.0.0.20"]
}
# systemctl restart docker.service
# docker pull 10.0.0.20/test/hello-world:latest
latest: Pulling from test/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d37ada95d47ad12224c205a938129df7a3e52345828b4fa27b03a98825d1e2e7
Status: Downloaded newer image for 10.0.0.20/test/hello-world:latest
10.0.0.20/test/hello-world:latest三、harbor 高可用环境搭建
1. 将harbor发送到10.0.0.21节点
# scp harbor-offline-installer-v2.7.2.tgz 10.0.0.21:/root2. 解压软件包
# tar xf harbor-offline-installer-v2.7.2.tgz -C /caixiangjia/softwares/3. 将harbor配置文件发送到10.0.0.21节点
# scp harbor.yml 10.0.0.21:/caixiangjia/softwares/harbor/4. 安装harbor
# 修改harbor配置文件
# vim harbor.yml
...
hostname: 10.0.0.21
...
# ./install.sh --with-chartmuseum5. 访问harbor 的WebUi
http://10.0.0.21/
账号:admin
密码:1https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214225915223-517129576.png
6. 10.0.0.20节点新建仓库
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230029908-77142861.png
7. 10.0.0.20节点新建复制规则
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230054683-1917244540.png
8. 10.0.0.21节点新建仓库
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230110962-495228163.png
9. 10.0.0.21节点新建复制规则
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230131695-348580752.png
10. 测试验证结果
推送镜像到 20 节点,观察 21 是否有同步数据
# docker push 10.0.0.20/wordpress/wordpress:latest https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230151114-1402391211.png
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230201598-13568886.png
推送镜像到 21 节点,观察 20 是否有同步数据
# docker push 10.0.0.21/mysql/mysql:8.0.36-oraclehttps://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230223290-1860469683.png
https://img2024.cnblogs.com/blog/3546069/202412/3546069-20241214230231882-119121119.png
11. 配置keepalived
1. 分别安装keepalived
# apt -y install keepalived
# apt -y install keepalived2. 修改 keepliaved 的配置文件
# cat > /etc/keepalived/keepalived.conf
页:
[1]