二维码
微世推网

扫一扫关注

当前位置: 首页 » 企业商讯 » 汽车行业 » 正文

超赞_Docker私有仓库Harbor_多实例高可用

放大字体  缩小字体 发布日期:2022-02-13 02:45:33    作者:田建辉    浏览次数:337
导读

多实例共享存储架构图感谢 LB 不使用 Nginx,使用阿里 SLB。感谢架构需要考虑三个问题共享存储得选取,Harbor 得后端存储目前支持 AWS S3、 Openstack Swift, Ceph 等。感谢使用 阿里云极速性 NAS,磁盘 IO 性能比单块磁盘读写性能要好。使用 NFS V3 版本挂载。Session 不能在不同得实例上共享,所以 Harbor Redis 需要单独

多实例共享存储架构图

感谢 LB 不使用 Nginx,使用阿里 SLB。

感谢架构需要考虑三个问题
  1. 共享存储得选取,Harbor 得后端存储目前支持 AWS S3、 Openstack Swift, Ceph 等。感谢使用 阿里云极速性 NAS,磁盘 IO 性能比单块磁盘读写性能要好。使用 NFS V3 版本挂载。
  2. Session 不能在不同得实例上共享,所以 Harbor Redis 需要单独部署,并且多个实例连接相同得 Redis。
  3. Harbor 多实例数据库问题,必须单独部署一个数据库,并且多个实例连接相同得数据库。

注:生产环境如果使用阿里云 NAS,推荐使用 极速性 NAS,不推荐使用 通用型 NAS。

阿里云 NAS 性能参考文档:

help.aliyun/document_detail/124577.html?spm=a2c4g.11186623.6.552.2eb05ea0HJUgUB

部署资源部署

Harbor 选择在线部署,使用 docker-compose 部署,docker-compose 和 Docker 部署环境感谢不再介绍,网上可以搜索到相关文档。

挂载阿里云极速性 NAS

harbor1 和 harbor2 机器都需要执行挂载 NAS

配置开机自动挂载,打开 /etc/fstab 配置文件,添加挂载命令。

# 创建 NAS 挂载目录$ mkdir /data # 提高同时发起得 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 v4 文件系统,添加以下命令:

file-system-id.region.nas.aliyuncs:/ /data nfs vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0

如果您要挂载 NFS v3 文件系统,添加以下命令:

file-system-id.region.nas.aliyuncs:/ /data nfs vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0# 在 /etc/fstab 配置文件添加好挂载,并执行挂载$ mount -a # 检查挂载,如果结果中存在 NFS 文件系统得挂载地址,则说明挂载成功$ df -h | grep aliyun临时部署单机 Harbor

在 harbor1 机器上操作

# 在线部署 Harbor$ cd /opt/$ wget github/goharbor/harbor/releases/download/v2.2.1/harbor-online-installer-v2.2.1.tgz$ tar xf harbor-online-installer-v2.2.1.tgz$ cd /opt/harbor$ cp harbor.yml.tmpl harbor.yml # 创建 harbor 数据存储$ mkdir /data/harbor # 添加域名证书,已有域名 SSL 证书$ mkdir /data/harbor/cert # 把 SSL 证书公钥和私钥上传到 /data/harbor/cert 目录中$ scp harbor.example.pem root等192.168.10.10:/data/harbor/cert/$ scp harbor.example.key root等192.168.10.10:/data/harbor/cert/ # 配置 harbor.yml 文件,下面是修改后文件与原文件比较结果$ diff harbor.yml harbor.yml.tmpl 5c5< hostname: harbor.example---> hostname: reg.mydomain17,18c17,18< certificate: /data/harbor/cert/harbor.example.pem< private_key: /data/harbor/cert/harbor.example.key---> certificate: /your/certificate/path> private_key: /your/private/key/path29c29< external_url: harbor.example---> # external_url: reg.mydomain:8433 < data_volume: /data/harbor---> data_volume: /data # 生成配置文件$ cd /opt/harbor # harbor 开启 helm charts 和 镜像漏洞扫描$ ./prepare --with-notary --with-trivy --with-chartmuseum # 安装$ ./install.sh --with-notary --with-trivy --with-chartmuseum # 查看$ docker-compose ps单独部署 Harbor 数据库和 Redis

# 创建 postgres 和 redis 存储目录$ mkdir -p /data/harbor-redis /data/harbor-postgresql # 修改所属组$ chown -R 999.999 /data/harbor-redis /data/harbor-postgresql# 创建 postgres 和 redis docker-compose.yml 文件$ vim docker-compose.yml version: '2.3' services:redis:image: goharbor/redis-photon:v2.2.1container_name: harbor-redisrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETG- SETUvolumes:- /data/harbor-redis:/var/lib/redisnetworks:- harbor-dbports:- 6379:6379postgresql:image: goharbor/harbor-db:v2.2.1container_name: harbor-postgresqlrestart: alwayscap_drop:- ALLcap_add:- CHOWN- DAC_OVERRE- SETG- SETUenvironment:POSTGRES_USER: postgresPOSTGRES_PASSWORD: test2021volumes:- /data/harbor-postgresql:/var/lib/postgresql/data:znetworks:- harbor-dbports:- 5432:5432 networks:harbor-db:driver: bridge # 部署 postgres 和 redis$ docker-compose up -d导入 postgres 数据

# 进入临时 harbor-db 容器导出相关表及数据$ docker exec -it -u postgres harbor-db bash # 导出数据$ pg_dump -U postgres registry > /tmp/registry.sql$ pg_dump -U postgres notarysigner > /tmp/notarysigner.sql$ pg_dump -U postgres notaryserver > /tmp/notaryserver.sql # 将数据导入单独部署得 PostgreSQL 数据库$ psql -h 192.168.10.10 -U postgres registry -W < /tmp/registry.sql$ psql -h 192.168.10.10 -U postgres notarysigner -W < /tmp/notarysigner.sql$ psql -h 192.168.10.10 -U postgres notaryserver -W < /tmp/notaryserver.sql清理临时部署单机 Harbor 数据和相关配置文件

# 清理 harbr 数据和配置文件$ cp -a /data/harbor/cert /tmp/$ rm -rf /data/harbor/*$ rm -rf /opt/harbor$ cp -a /tmp/cert /data/harbor/ # 重新创建配置文件$ cd /opt/$ tar xf harbor-online-installer-v2.2.1.tgz$ cd /opt/harbor # 修改配置文件,连接单独部署 postgres 和 redis,注释 harbor 自带得 postgres 和 redis$ cp harbor.yml.tmpl harbor.yml$ diff harbor.yml harbor.yml.tmpl 5c5< hostname: harbor.example---> hostname: reg.mydomain17,18c17,18< certificate: /data/harbor/cert/harbor.example.pem< private_key: /data/harbor/cert/harbor.example.key---> certificate: /your/certificate/path> private_key: /your/private/key/path29c29< external_url: harbor.example---> # external_url: reg.mydomain:8433 37c37< # database:---> database:39c39< # password: root123---> password: root12341c41< # max_idle_conns: 50---> max_idle_conns: 5044c44< # max_open_conns: 1000---> max_open_conns: 100047c47 < data_volume: /data/harbor---> data_volume: /data 135,158c135,158< external_database:< harbor:< host: 192.168.10.10< port: 5432< db_name: registry< username: postgres< password: test2021< ssl_mode: disable< max_idle_conns: 50< max_open_conns: 1000< notary_signer:< host: 192.168.10.10< port: 5432< db_name: notarysigner< username: postgres< password: test2021< ssl_mode: disable< notary_server:< host: 192.168.10.10< port: 5432< db_name: notaryserver< username: postgres< password: test2021< ssl_mode: disable---> # external_database:> # harbor:> # host: harbor_db_host> # port: harbor_db_port> # db_name: harbor_db_name> # username: harbor_db_username> # password: harbor_db_password> # ssl_mode: disable> # max_idle_conns: 2> # max_open_conns: 0> # notary_signer:> # host: notary_signer_db_host> # port: notary_signer_db_port> # db_name: notary_signer_db_name> # username: notary_signer_db_username> # password: notary_signer_db_password> # ssl_mode: disable> # notary_server:> # host: notary_server_db_host> # port: notary_server_db_port> # db_name: notary_server_db_name> # username: notary_server_db_username> # password: notary_server_db_password> # ssl_mode: disable161,175c161,175< external_redis:< # support redis, redis+sentinel< # host for redis: <host_redis>:<port_redis>< # host for redis+sentinel:< # <host_sentinel1>:<port_sentinel1>,<host_sentinel2>:<port_sentinel2>,<host_sentinel3>:<port_sentinel3>< host: 192.168.10.10:6379< password:< # sentinel_master_set must be set to support redis+sentinel< #sentinel_master_set:< # db_index 0 is for core, it's unchangeable< registry_db_index: 1< jobservice_db_index: 2< chartmuseum_db_index: 3< trivy_db_index: 5< idle_timeout_seconds: 30---> # external_redis:> # # support redis, redis+sentinel> # # host for redis: <host_redis>:<port_redis>> # # host for redis+sentinel:> # # <host_sentinel1>:<port_sentinel1>,<host_sentinel2>:<port_sentinel2>,<host_sentinel3>:<port_sentinel3>> # host: redis:6379> # password:> # # sentinel_master_set must be set to support redis+sentinel> # #sentinel_master_set:> # # db_index 0 is for core, it's unchangeable> # registry_db_index: 1> # jobservice_db_index: 2> # chartmuseum_db_index: 3> # trivy_db_index: 5> # idle_timeout_seconds: 30# 部署第壹个节点 harbor$ cd /opt/harbor # harbor 开启 helm charts 和 镜像漏洞扫描$ ./prepare --with-notary --with-trivy --with-chartmuseum # 安装$ ./install.sh --with-notary --with-trivy --with-chartmuseum # 查看$ docker-compose ps # 拷贝配置到 harbor2 机器上$ scp -r /opt/harbor 192.168.10.11:/opt/

在 harbor2 机器上操作

# 部署第二个节点 harbor$ cd /opt/harbor # harbor 开启 helm charts 和 镜像漏洞扫描$ ./prepare --with-notary --with-trivy --with-chartmuseum # 安装$ ./install.sh --with-notary --with-trivy --with-chartmuseum # 查看$ docker-compose ps配置阿里云 SLB

不具体介绍 SLB 配置方法,具体配置方法参考下面阿里云 SLB 配置文档,配置 443 端口,使用 TCP 协议,后端映射到两台 harbor1 和 harbor2 443 端口上。

 
(文/田建辉)
免责声明
• 
本文仅代表发布者:田建辉个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,需自行承担相应责任。涉及到版权或其他问题,请及时联系我们删除处理邮件:weilaitui@qq.com。
 

Copyright©2015-2025 粤公网安备 44030702000869号

粤ICP备16078936号

微信

关注
微信

微信二维码

WAP二维码

客服

联系
客服

联系客服:

24在线QQ: 770665880

客服电话: 020-82301567

E_mail邮箱: weilaitui@qq.com

微信公众号: weishitui

韩瑞 小英 张泽

工作时间:

周一至周五: 08:00 - 24:00

反馈

用户
反馈