harbor高可用部署

article/2025/10/12 17:00:33

harbor高可用简介

harbor目前有两种主流的高可用方案:

  • 双主复制,harbor自带的镜像复制功能
  • 多harbor实例共享后端存储

在这里插入图片描述
双主复制架构在遇到大镜像时有同步延迟,并且一个实例故障后需要手动重新开启复制策略才能再次同步,下面以阿里云环境为例,使用两台ECS实例+NFS后端共享存储方式部署高可用harbor,整体架构图如下:
在这里插入图片描述
该方案需要注意以下几点:

  1. 共享存储的选取,Harbor的后端存储目前支持本地文件系统、NFS、CephFS、azure、gcs、AWS s3,、swift 以及阿里云oss。
  2. Session在不同的实例上共享,在最新的harbor中,默认session会存放在redis中,只需要将redis独立出来即可,可以通过redis sentinel或者redis cluster等方式来保证redis的可用性。
  3. 由于PostgreSQL多个实例无法共享一份数据文件,需要将harbor中的数据库拆出来独立部署,让多实例共用一个外部数据库,并将Harbor中默认创建在PostgreSQL的所有表的结构、初始数据等导入进单独部署的PostgreSQL服务中,PostgreSQL数据的冗余可以使用PostgreSQL的同步策略来实现。

harbor高可用部署

在阿里云申请以下资源:

资源类型数量地域
ECS实例2华南1(深圳)-可用区D
NAS实例1华南1(深圳)-可用区D
RDS实例1华南1(深圳)-可用区D
Redis实例1华南1(深圳)-可用区D
SLB实例1华南1(深圳)-可用区D

两台ECS实例信息:

ECS主机名私网IP公网IPOS地域
harbor001172.18.8.242120.79.96.163CentOS8.4华南1(深圳)-可用区D
harbor002172.18.8.243120.79.96.169CentOS8.4华南1(深圳)-可用区D

备注:如果在私有云环境部署,可自建PostgreSQL集群、Redis集群、NFS server,并使用nginx/haproxy/lvs+keepalived代替公网SLB负载均衡,如果使用对象存储作为后端,可选用minio代替s3。

配置SLB实例

创建1个SLB实例(代替上图nginx)及两组监听,用于四层转发,访问443端口转发到后端两台harbor ECS实例的443端口,访问80端口harbor默认会重定向到443端口,未启动后端harbor时当前监听应该处于异常状态:
在这里插入图片描述
自行准备域名,解析到SLB实例的公网IP:

registry.cloudcele.com --->  120.25.165.246

以阿里云域名为例:
在这里插入图片描述

配置RDS实例

创建PostgreSQL类型RDS实例,创建一个数据库用户,以超级管理员postgres为例:
在这里插入图片描述
然后手动创建三个空数据库,绑定到postgres用户下:

参考:https://goharbor.io/docs/master/install-config/harbor-ha-helm

notaryserver
notarysigner
registry

阿里云示例:
在这里插入图片描述

配置NAS实例

创建NAS实例后,在两台ECS实例上都执行挂载,安装NFS客户端:

sudo yum install nfs-utils

执行以下命令,提高同时发起的NFS请求数量:

sudo echo "options sunrpc tcp_slot_table_entries=128" >> /etc/modprobe.d/sunrpc.conf
sudo echo "options sunrpc tcp_max_slot_table_entries=128" >> /etc/modprobe.d/sunrpc.conf

挂载NFS文件系统,这里挂载到/data目录下

cat >> /etc/fstab <<EOF
217d3488b8-mtr10.cn-shenzhen.nas.aliyuncs.com:/ /data nfs vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0
EOFmkdir /data
mount -a

验证挂载是否成功

[root@harbor001 ~]# df -h | grep aliyun
217d3488b8-mtr10.cn-shenzhen.nas.aliyuncs.com:/   10P     0   10P   0% /data

生成域名证书

参考:

https://github.com/acmesh-official/acme.sh
https://goharbor.io/docs/2.3.0/install-config/configure-https/

域名证书可以手动自签证书,但自签发的证书不会被 Chrome 等浏览器信任,这里采用 Let’s Encrypt 生成免费的、可被浏览器信任的证书,常用的 Let’s Encrypt 生成工具主要有 acme.sh 及 certbot 两种,本次使用 acme.sh 自动从 letsencrypt 生成证书。

使用acme.sh时有httpdns两种验证方式,dns验证又分为手动和自动,这里使用阿里云域名解析,支持使用dns方式自动连接到阿里云API申请证书:

curl https://get.acme.sh | sh
yum install -y socatexport Ali_Key=xxxxxxxxxxxxxxx
export Ali_Secret=xxxxxxxxxxxxxxx
acme.sh --issue --dns dns_ali -d registry.cloudcele.com

查看生成的证书

# ls -1 /root/.acme.sh/registry.cloudcele.com/
ca.cer
fullchain.cer
registry.cloudcele.com.cer
registry.cloudcele.com.conf
registry.cloudcele.com.csr
registry.cloudcele.com.csr.conf
registry.cloudcele.com.key

安装证书到harbor目录下

mkdir -p /data/harbor/certacme.sh --installcert -d registry.cloudcele.com \--key-file /data/harbor/cert/registry.cloudcele.com.key \--fullchain-file /data/harbor/cert/registry.cloudcele.com.crt

查看安装到harbor路径下的证书

[root@harbor001 ~]# ls -1 /data/harbor/cert/
registry.cloudcele.com.crt
registry.cloudcele.com.key

acme.sh申请的证书有效期90天,acme.sh安装的时候已经自动添加了一个计划任务每天自动更新证书,更新后重启使用证书的服务。 acme.sh自动添加的计划任务

[root@harbor001 ~]# crontab  -l | grep acme
55 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null

该计划任务也会自动执行证书上一次的安装命令,为确保nginx使用最新的证书,重新执行一次安装证书命令让acme.ch将证书文件安装到正确的位置及重启nginx服务。

acme.sh --installcert -d registry.cloudcele.com \--key-file /data/harbor/cert/registry.cloudcele.com.key \--fullchain-file /data/harbor/cert/registry.cloudcele.com.crt \--reloadcmd "docker restart nginx"

开始安装harbor

前提:两台ECS实例已完成docker及docker-compose安装,以下所有操作在第一个harbor节点执行:

下载harbor

wget https://mirrors.tuna.tsinghua.edu.cn/github-release/goharbor/harbor/v2.3.1/harbor-offline-installer-v2.3.1.tgz
tar -zxvf harbor-offline-installer-v2.3.1.tgz -C /opt

切换到harbor安装目录

cd /opt/harbor
cp harbor.yml.tmpl harbor.yml

修改harbor配置文件,注意获取VPC实例内网连接地址、端口及密码信息,有变动的内容如下:

[root@harbor001 harbor]# vim harbor.yml
hostname: registry.cloudcele.comhttp:port: 80https:port: 443certificate: /data/harbor/cert/registry.cloudcele.com.crtprivate_key: /data/harbor/cert/registry.cloudcele.com.keydata_volume: /data/harborexternal_database:harbor:host: pgm-wz9541r7evq0auo6168200.pg.rds.aliyuncs.comport: 1921db_name: registryusername: postgrespassword: Postgres@2021ssl_mode: disablemax_idle_conns: 2max_open_conns: 0notary_signer:host: pgm-wz9541r7evq0auo6168200.pg.rds.aliyuncs.comport: 1921db_name: notarysignerusername: postgrespassword: Postgres@2021ssl_mode: disablenotary_server:host: pgm-wz9541r7evq0auo6168200.pg.rds.aliyuncs.comport: 1921db_name: notaryserverusername: postgrespassword: Postgres@2021ssl_mode: disableexternal_redis:host: r-wz9fpfgjon0p4kci80.redis.rds.aliyuncs.com:6379password: Redis123registry_db_index: 1jobservice_db_index: 2chartmuseum_db_index: 3trivy_db_index: 5idle_timeout_seconds: 30

执行harbor安装

./install.sh

复制harbor安装目录到harbor002节点:

[root@harbor001 ~]# scp -r /opt/harbor/ 172.18.8.243:/opt

同样,连接到harbor002节点直接安装即可,无需其他操作:

[root@harbor002 ~]# cd /opt/harbor/
[root@harbor002 ~]# ./install.sh

访问harbor验证

浏览器访问harbor域名:https://registry.cloudcele.com
在这里插入图片描述
停掉第一个节点harbor实例,验证依然能够正常访问:

[root@harbor001 ~]# cd /opt/harbor/
[root@harbor001 harbor]# docker-compose down

harbor上传镜像

首先为docker客户端准备证书,从acme.sh目录下获取证书

[root@harbor001 ~]# cd /root/.acme.sh/registry.cloudcele.com/

复制以下三个文件到docker客户端目录/etc/docker/certs.d/registry.cloudcele.com/

ca.cer
registry.cloudcele.com.cer
registry.cloudcele.com.key

客户端创建目录,查看复制过来的证书文件:

# mkdir -p /etc/docker/certs.d/registry.cloudcele.com/# ls -1 /etc/docker/certs.d/registry.cloudcele.com/
ca.crt
registry.cloudcele.com.cert
registry.cloudcele.com.key

重启docker进程

systemctl restart docker

登录harbor仓库

# docker login registry.cloudcele.com
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-storeLogin Succeeded

上传docker镜像

[root@master ~]# docker push registry.cloudcele.com/library/nginx
Using default tag: latest
The push refers to repository [registry.cloudcele.com/library/nginx]
d9eb91d66e2a: Pushed 
ae1f545e4c08: Pushed 
c20672db3628: Pushed 
4cbb728cd302: Pushing [=>                                                 ]  1.609MB/63.74MB
4cbb728cd302: Pushed 
9eb82f04c782: Pushed 
latest: digest: sha256:1a53eb723d17523512bd25c27299046cfa034cce309f4ed330c943a304513f59 size: 1362

拉取docker镜像

[root@master ~]# docker pull registry.cloudcele.com/library/nginx
Using default tag: latest
latest: Pulling from library/nginx
Digest: sha256:1a53eb723d17523512bd25c27299046cfa034cce309f4ed330c943a304513f59
Status: Image is up to date for registry.cloudcele.com/library/nginx:latest
registry.cloudcele.com/library/nginx:latest

参考:https://cloud.tencent.com/developer/article/1838838


http://chatgpt.dhexx.cn/article/wq0QdwRG.shtml

相关文章

HADOOP 高可用搭建

首先先说一下大概的步骤&#xff0c;就用四台为例&#xff0c;简单适合新手操作。 流程是&#xff1a;创建虚拟机&#xff0c;配置好&#xff1b;搭建linux系统&#xff1b;安装jdk&#xff08;因为后面好多都依赖jkd&#xff09;&#xff1b;免密登录ssh&#xff1b;安装zook…

高可用详细概念及三种决策方式分析

文章目录 1.基本概念1.计算高可用2.存储高可用高可用状态决策1.独裁式2.协商式3.民主式 1.基本概念 这个定义的关键在于“无中断”&#xff0c;但恰好难点也在“无中断”上面&#xff0c;因为无论是单个硬件还是单 个软件&#xff0c;都不可能做到无中断&#xff0c;硬件会出故…

Nacos实现高可用

由于Nacos暂不支持Arm架构芯片的Mac集群搭建&#xff0c;本小节用Linxu云主机&#xff08;Nacos比较吃内存&#xff0c;2个Nacos服务器集群&#xff0c;至少2G内存&#xff09;环境演示。 通过前面的学习&#xff0c;我们已经了解了如何使用Nacos以及Nacos的功能等&#xff0c;…

浅谈高可用测试

前言 现今的互联网产品越来越注重可靠性&#xff0c;尤其是在生产环境中使用的系统&#xff0c;对高可用性都有一定的要求。而作为产品的提供方&#xff0c;在交付产品之前&#xff0c;也会对高可用进行验收测试。近期跟进过两个产品曾有高可用测试的需求&#xff0c;在此简单…

nginx高可用

Nginx高可用 为什么要使用nginx的高可用&#xff1a;因为nginx作为反向代理服务器时&#xff0c;有可能出现宕机的情况&#xff0c;而由于其反向代理的特性&#xff0c;就会导致其他服务器&#xff08;tomcat等&#xff09;无法被访问&#xff0c;这样项目就停止工作了。但是使…

RabbitMQ高可用

RabbitMQ高可用 各种消息队列对比使用推荐 RabbitMQ 高可用普通集群模式镜像集群模式保证消息队列的幂等性(消息不被重复消费)消息队列的可靠性传输生产者丢失数据RabbitMQ丢失数据消费者丢失数据 保证消息的顺序性消息积压问题 各种消息队列对比 特性ActiveMQRabbitMQRocketM…

系统高可用

系统高可用 1. 什么是高可用&#xff1f;可用性的判断标准是啥&#xff1f;1.1 可用性的判断标准是啥&#xff1f; 2. 哪些情况会导致系统不可用&#xff1f;3. 有哪些提高系统可用性的方法&#xff1f;3.1 注重代码质量&#xff0c;定时Review代码3.2 使用集群&#xff0c;减少…

HBase高可用

一、HBase高可用简介 HBase集群如果只有一个master&#xff0c;一旦master出现故障&#xff0c;将导致整个集群无法使用&#xff0c;所以在实际的生产环境中&#xff0c;需要搭建HBase的高可用&#xff0c;也就是让HMaster高可用&#xff0c;也就是需要再选择一个或多个节点也…

你管这破玩意儿叫高可用

大家好&#xff0c;我是坤哥 今天我们来聊一下互联网三高&#xff08;高并发、高性能、高可用&#xff09;中的高可用&#xff0c;看完本文相信能解开你关于高可用设计的大部分困惑 前言 高可用&#xff08;High availability&#xff0c;即 HA&#xff09;的主要目的是为了保障…

什么是高可用?高可用介绍:

前言&#xff1a; 高可用&#xff08;High availability&#xff0c;即 HA&#xff09;的主要目的是为了保障「业务的连续性」&#xff0c;即在用户眼里&#xff0c;业务永远是正常&#xff08;或者说基本正常&#xff09;对外提供服务的。高可用主要是针对架构而言&#xff0c…

HTML Responsive Web Page

注&#xff1a;参考网站 https://www.w3schools.com HTML Responsive Web Page index.html <!DOCTYPE html> <html><head><link rel"stylesheet" href"style.css"><title>Responsive web page</title><meta lan…

响应式布局【Responsive】 与 自适应布局 【adaptive】、单页面【SPA】 和多页面【MPA】

1、响应式布局 是一个网址能兼容多个terminate【终端】&#xff0c;而不是为每个终端做一个特定的版本 优点&#xff1a; 用户体验好节约开发时间、节省设计seo友好可以适用所有设备屏幕 缺点 设计与风格有局限性《自由度太低&#xff0c;局部性较大》灵活性有所欠缺 基于不…

Bootstrap:Responsive Design with Bootstrap(一)

1.Use Responsive Design with Bootstrap Fluid Containers 现在让我们回到我们的Cat Photo应用。这次&#xff0c;我们将用流行的响应式框架Bootstrap来美化它。 Bootstrap将会根据你的屏幕的大小来调整HTML元素的大小 —— 强调 响应式设计的概念。 通过响应式设计&#x…

responsive tables

以上内容原本是整理为ppt格式的&#xff0c;贴过来格式有点乱&#xff0c;请见谅。 其他responsive tables参考&#xff1a; http://gergeo.se/RWD-Table-Patterns/ 3种类型的代码参考 unseen column&#xff1a; http://runjs.cn/code/zrhodpx5 flip scroll&#xff1a; ht…

CSS之responsive image gallery

responsive image gallery 这次实例主要是练习如何讲不同的图片设置为一个栏目&#xff0c;并且能够根据屏幕的大小进行自适应的变换。需要注意的是&#xff0c;本次实例中运用到的重要的关键的内容是&#xff1a;float-left&#xff1b;box-sizing; media screen and (max-wi…

html5 响应式表格插件,响应式表格jQuery插件 – Responsive tables

响应式表格jQuery插件 – Responsive tables 4月 24, 2014 评论 (1) Sponsor 这个Responsive tables jQuery插件依赖于Bootstrap 3使用&#xff0c;比BS自带的自适应多了一些好用的功能&#xff0c;比如筛选显示&#xff0c;Focus选定、Table头滑动固定等&#xff0c;下来看看介…

SAP Fiori 设计准则里的 Responsive 表格概述

Responsive Table 是 SAP Fiori 中的默认表控件。 它包含一组 Line item 并且完全响应(fully responsive)。 根据具体情况&#xff0c;用户还可以从行项目导航到更多详细信息页面。 一个行项目包含多个数据点(data point)&#xff0c;这些数据点被分类到列中。 数据点是指一个…

Responsive Web测试

什么是Responsive Web设计 Ethan Marcotte曾于2010年5月25日在A List Apart发表了文章《Responsive Web Design》&#xff0c;首次提出了RWD(Responsive Web Design)的概念。其理念是&#xff0c;Web页面的设计能够自适应多种设备、平台和浏览器&#xff0c;同时减少缩放、平移…

CSS之Responsive设计的关键三步

下面我们就通过这篇教程&#xff0c;帮助大家从三个步骤来了解和学习“Responsive”设计 第一步&#xff1a;Meta标签 大家都知道&#xff0c;现在智能手机上浏览web页面会让页面适应屏幕的大小&#xff0c;显示在屏幕上。不过我们可以通过“meta”标签对他进行重置&#xff…

CSS之Responsive网页设计的三个特性

Responsive网页设计无疑是网页设计中的一个热门话题。某种程度上&#xff0c;他将是一个最受欢迎的网页设计概念&#xff0c;因为随着网站用户日渐多样化的访问方法&#xff0c;比如说“iPad”、“iPhone”、“Android移动设备”、“平板电脑”、“台式机”以及“ 笔记本”等不…