harbor部署及高可用
作者:互联网
一、harbor简介
Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,可以用来构建企业内部的Docker镜像仓库。
它在Docker的开源项目 Distribution的基础上,添加了一些企业需要的功能特性,如镜像同步复制、漏洞扫描和权限管理等。
二、harbor安装
1.搭建harbor依赖于docker环境,所以要先安装docker和docker-compose
docker 官网有对应系统的安装步骤:https://docs.docker.com/engine/install/ubuntu/
卸载旧版本
# apt-get remove docker docker-engine docker.io containerd runc
设置存储库,更新apt包
# apt-get update
# apt-get install ca-certificates curl gnupg lsb-release
添加Docker官方的GPG密钥
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
安装docker(下载最新版本)
# apt-get install docker-ce docker-ce-cli containerd.io docker-compose
安装docker (下载指定版本)
查找版本
# apt-cache madison docker-ce
docker-ce | 5:20.10.12~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.11~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.10~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.9~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.8~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.7~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.6~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
下载指定版本
# apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io docker-compose=<VERSION_STRING>
2.部署harbor
安装包下载地址 https://github.com/goharbor/harbor/releases
下载harbor安装包 \
# wget https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
解压安装包
# tar -xf harbor-offline-installer-v2.4.1.tgz (解压后生产harbor目录)
进入harbor目录配置harbor.yml
# cd harbor
# cp harbor.yml.tmpl harbor.yml
# vim harbor.yml
hostname: 10.10.0.2
harbor_admin_password: admin12345
data_volume: /data/harbor
安装harbor
# ./install.sh --with-trivy
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4883c7e2def0 goharbor/harbor-jobservice:v2.3.5 "/harbor/entrypoint.…" 2 hours ago Up 2 hours (healthy) harbor-jobservice
0529dffb3ce5 goharbor/nginx-photon:v2.3.5 "nginx -g 'daemon of…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx
3b0b12a1ea7b goharbor/harbor-core:v2.3.5 "/harbor/entrypoint.…" 2 hours ago Up 2 hours (healthy) harbor-core
5d857909864b goharbor/trivy-adapter-photon:v2.3.5 "/home/scanner/entry…" 2 hours ago Up 2 hours (healthy) trivy-adapter
cecf68b70d0f goharbor/redis-photon:v2.3.5 "redis-server /etc/r…" 2 hours ago Up 2 hours (healthy) redis
55fb3f70af3b goharbor/harbor-registryctl:v2.3.5 "/home/harbor/start.…" 2 hours ago Up 2 hours (healthy) registryctl
86d7fb349579 goharbor/harbor-db:v2.3.5 "/docker-entrypoint.…" 2 hours ago Up 2 hours (healthy) harbor-db
6d7d83ca7708 goharbor/registry-photon:v2.3.5 "/home/harbor/entryp…" 2 hours ago Up 2 hours (healthy) registry
fd52cec69e75 goharbor/harbor-portal:v2.3.5 "nginx -g 'daemon of…" 2 hours ago Up 2 hours (healthy) harbor-portal
9291a14def9b goharbor/harbor-log:v2.3.5 "/bin/sh -c /usr/loc…" 2 hours ago Up 2 hours (healthy) 127.0.0.1:1514->10514/tcp harbor-log
harbor启动后服务器配置登录
# docker login 10.10.0.16
执行完后docker会拉起harbor,可以用配置的ip和端口去浏览器访问
### 三、高可用部署
- 两个节点安装docker和harbor参考上面安装步骤,harbor1和harbor2互相同步数据
harbor1
harbor2
可在harbor页面做配置,harbor1和harbor2互相配置,保证互相都能同步镜像
-
haproxy高可用
docker上传镜像,通过harproxy上传至harbor1或者harbor2,可用轮询的方式上传镜像,或者指定一个仓库上传,harbor1和harbor2做复制同步
安装haproxy(可直接apt-get安装也可二进制包安装)
# apt-get install haproxy -y
修改haproxy配置
# vim /etc/haproxy/haproxy.cfg
#最末尾添加
listen harbor
bind 10.10.0.14:80 #只能写内网ip或者127.0.0.1
mode tcp
balance source #默认轮询方式,改配置指定第一个仓库地址
server harbor1 10.10.0.16:80 check inter 3s fall 3 rise 5
server harbor2 10.10.0.2:80 check inter 3s fall 3 rise 5
修改完重启haproxy
# systemctl restart haproxy.service
配置服务端使用haproxy登录harbor,保证可以正常拉取上传镜像
# docker login 10.10.0.14
标签:goharbor,可用,harbor,hours,部署,ubuntu,docker,focal 来源: https://blog.csdn.net/xiechenyang16/article/details/122046972