高可用harbor集群搭建

一、安装部署

1.节点角色

角色 数量 名称 备注
harbor主节点 2 harbor-1 harbor-2 双主模式
haproxy 2 HA-1 HA-2 需要通过keepalived绑定vip
Redis 高可用集群 redis harbor组件,本地启动或远程配置
postgresql 高可用集群 postgres harbor组件,本地启动或远程配置
ceph 高可用集群 ceph harbor组件

2.离线安装

1、下载离线源码包解压至harbor-1 harbor-2 节点 /data/harbor目录下,修改启动脚本harbor.cfg各项配置参数如下


  1. ## Configuration file of Harbor
  2. #This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
  3. _version = 1.7.0
  4. #The IP address or hostname to access admin UI and registry service.
  5. #DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
  6. #DO NOT comment out this line, modify the value of "hostname" directly, or the installation will fail.
  7. hostname = harbor.xxx.xxx.com //配置域名信息
  8. #The protocol for accessing the UI and token/notification service, by default it is http.
  9. #It can be set to https if ssl is enabled on nginx.
  10. ui_url_protocol = https //指定为https协议
  11. #Maximum number of job workers in job service
  12. max_job_workers = 10
  13. #Determine whether or not to generate certificate for the registry's token.
  14. #If the value is on, the prepare script creates new root cert and private key
  15. #for generating token to access the registry. If the value is off the default key/cert will be used.
  16. #This flag also controls the creation of the notary signer's cert.
  17. customize_crt = on
  18. #The path of cert and key files for nginx, they are applied only the protocol is set to https
  19. ssl_cert = /data/harbor/cert/uat.cmft.com.pem
  20. ssl_cert_key = /data/harbor/cert/uat.cmft.com.pem
  21. #The path of secretkey storage
  22. secretkey_path = /data
  23. #Admiral's url, comment this attribute, or set its value to NA when Harbor is standalone
  24. admiral_url = NA
  25. #Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
  26. log_rotate_count = 50
  27. #Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes.
  28. #If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G
  29. #are all valid.
  30. log_rotate_size = 200M
  31. #Config http proxy for Clair, e.g. http://my.proxy.com:3128
  32. #Clair doesn't need to connect to harbor internal components via http proxy.
  33. http_proxy =
  34. https_proxy =
  35. no_proxy = 127.0.0.1,localhost,core,registry
  36. #NOTES: The properties between BEGIN INITIAL PROPERTIES and END INITIAL PROPERTIES
  37. #only take effect in the first boot, the subsequent changes of these properties
  38. #should be performed on web ui
  39. #************************BEGIN INITIAL PROPERTIES************************
  40. #Email account settings for sending out password resetting emails.
  41. #Email server uses the given username and password to authenticate on TLS connections to host and act as identity.
  42. #Identity left blank to act as username.
  43. email_identity =
  44. email_server = smtp.mydomain.com
  45. email_server_port = 25
  46. email_username = sample_admin@mydomain.com
  47. email_password = abc
  48. email_from = admin <sample_admin@mydomain.com>
  49. email_ssl = false
  50. email_insecure = false
  51. ##The initial password of Harbor admin, only works for the first time when Harbor starts.
  52. #It has no effect after the first launch of Harbor.
  53. #Change the admin password from UI after launching Harbor.
  54. harbor_admin_password = yourpassword //配置harboradmin账户密码,建议修改
  55. ##By default the auth mode is db_auth, i.e. the credentials are stored in a local database.
  56. #Set it to ldap_auth if you want to verify a user's credentials against an LDAP server.
  57. auth_mode = db_auth
  58. #The url for an ldap endpoint.
  59. ldap_url = ldaps://ldap.mydomain.com
  60. #A user's DN who has the permission to search the LDAP/AD server.
  61. #If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.
  62. #ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com
  63. #the password of the ldap_searchdn
  64. #ldap_search_pwd = password
  65. #The base DN from which to look up a user in LDAP/AD
  66. ldap_basedn = ou=people,dc=mydomain,dc=com
  67. #Search filter for LDAP/AD, make sure the syntax of the filter is correct.
  68. #ldap_filter = (objectClass=person)
  69. # The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes depending on your LDAP/AD
  70. ldap_uid = uid
  71. #the scope to search for users, 0-LDAP_SCOPE_BASE, 1-LDAP_SCOPE_ONELEVEL, 2-LDAP_SCOPE_SUBTREE
  72. ldap_scope = 2
  73. #Timeout (in seconds) when connecting to an LDAP Server. The default value (and most reasonable) is 5 seconds.
  74. ldap_timeout = 5
  75. #Verify certificate from LDAP server
  76. ldap_verify_cert = true
  77. #The base dn from which to lookup a group in LDAP/AD
  78. ldap_group_basedn = ou=group,dc=mydomain,dc=com
  79. #filter to search LDAP/AD group
  80. ldap_group_filter = objectclass=group
  81. #The attribute used to name a LDAP/AD group, it could be cn, name
  82. ldap_group_gid = cn
  83. #The scope to search for ldap groups. 0-LDAP_SCOPE_BASE, 1-LDAP_SCOPE_ONELEVEL, 2-LDAP_SCOPE_SUBTREE
  84. ldap_group_scope = 2
  85. #Turn on or off the self-registration feature
  86. self_registration = on
  87. #The expiration time (in minute) of token created by token service, default is 30 minutes
  88. token_expiration = 30
  89. #The flag to control what users have permission to create projects
  90. #The default value "everyone" allows everyone to creates a project.
  91. #Set to "adminonly" so that only admin user can create project.
  92. project_creation_restriction = everyone
  93. #************************END INITIAL PROPERTIES************************
  94. #######Harbor DB configuration section#######
  95. #The address of the Harbor database. Only need to change when using external db.
  96. db_host = 100.12.13.10
  97. #The password for the root user of Harbor DB. Change this before any production use.
  98. db_password = yourdbpassword
  99. #The port of Harbor database host
  100. db_port = 7810
  101. #The user name of Harbor database
  102. db_user = harbordata
  103. #若采用本地配置,则采用如下配置形式,指定db为本地启动。
  104. #db_host = postgresql
  105. #db_password = yourpassword
  106. #db_port = 5432
  107. #db_user = postgres
  108. ##### End of Harbor DB configuration#######
  109. ##########Redis server configuration.############
  110. #Redis connection address
  111. redis_host = 100.101.21.3
  112. #Redis connection port
  113. redis_port = 4410
  114. #Redis connection password
  115. redis_password = 123456
  116. #Redis connection db index
  117. #db_index 1,2,3 is for registry, jobservice and chartmuseum.
  118. #db_index 0 is for UI, it's unchangeable
  119. redis_db_index = 1,2,3
  120. ########## End of Redis server configuration ############
  121. ##########Clair DB configuration############
  122. #Clair DB host address. Only change it when using an exteral DB.
  123. clair_db_host = 100.101.12.3 //clair 使用与db相同的数据库,注意使用新的database,防止数据冲突。
  124. #The password of the Clair's postgres database. Only effective when Harbor is deployed with Clair.
  125. #Please update it before deployment. Subsequent update will cause Clair's API server and Harbor unable to access Clair's database.
  126. clair_db_password = 123456
  127. #Clair DB connect port
  128. clair_db_port = 7810
  129. #Clair DB username
  130. clair_db_username = harbordata
  131. #Clair default database
  132. clair_db = template1 //由于与主数据库公用 不可与db指定相同的database
  133. #clair_db_host = postgresql
  134. #clair_db_password = root123
  135. #clair_db_port = 5432
  136. #clair_db_username = postgres
  137. #clair_db = postgres
  138. #The interval of clair updaters, the unit is hour, set to 0 to disable the updaters.
  139. clair_updaters_interval = 12
  140. ##########End of Clair DB configuration############
  141. #The following attributes only need to be set when auth mode is uaa_auth
  142. uaa_endpoint = uaa.mydomain.org
  143. uaa_clientid = id
  144. uaa_clientsecret = secret
  145. uaa_verify_cert = true
  146. uaa_ca_cert = /path/to/ca.pem
  147. ### Harbor Storage settings ###
  148. #若采用本地ceph 指定 registry_storage_provider_name = filesystem 且忽略registry_storage_provider_config
  149. #默认申请ceph具有如下形式
  150. #bucket region accesskey secretkey regionendpoint参数
  151. #Please be aware that the following storage settings will be applied to both docker registry and helm chart repository.
  152. #registry_storage_provider can be: filesystem, s3, gcs, azure, etc.
  153. registry_storage_provider_name = s3//使用s3协议连接ceph
  154. #registry_storage_provider_config is a comma separated "key: value" pairs, e.g. "key1: value, key2: value2".
  155. #To avoid duplicated configurations, both docker registry and chart repository follow the same storage configuration specifications of docker registry.
  156. #Refer to https://docs.docker.com/registry/configuration/#storage for all available configuration.
  157. registry_storage_provider_config = bucket: registry, region: default, accesskey: 123456, secretkey: 123456, regionendpoint: http://100.xx.xxx.xxx:7480, rootdirectory: /harbor-registry/st
  158. #ceph建议使用域名配置 若使用ip有可能出现 401 signatureMisMatch的错误。
  159. #registry_custom_ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
  160. #of registry's and chart repository's containers. This is usually needed when the user hosts a internal storage with self signeed certificate.
  161. registry_custom_ca_bundle =
  162. #If reload_config=true, all settings which present in harbor.cfg take effect after prepare and restart harbor, it overwrites exsiting settings.
  163. #reload_config=false
  164. #Regular expression to match skipped environment variables
  165. #skip_reload_env_pattern=(^EMAIL.*)|(^LDAP.*)

3.初始化与证书生成

1.harbor-1节点/data/harbor目录下执行命令: ./install.sh --with-notary --with-clair --with-chartmuseum #初始化运行harbor watch 'docker ps -a' #监测各组件运行情况 2.拷贝证书 : /data/harbor/common/config/core/private_key.pem /data/harbor/common/config/registry/root.crt 到/tmp/certfile目录下 同时拷贝到harbor-2节点的相同目录下

4、指定生成证书


  1. #关闭harbor-1节点与相关组件:
  2. docker-compose down -v --remove-orphans
  1. 1.修改启动脚本install.sh
  1. if [ -f harbor*.tar.gz ]
  2. then
  3. h2 "[Step $item]: loading Harbor images ..."; let item+=1
  4. #docker load -i ./harbor*.tar.gz
  5. fi
  6. echo "" #关闭重复加载image
  1. 2.(下列修改操作同时针对 harbor-1 harbor-2
  1. if customize_crt == 'on' and openssl_installed():
  2. print("creating cert-----------------------------")
  3. shell_stat = subprocess.check_call(["which", "openssl"], stdout=FNULL, stderr=subprocess.STDOUT)
  4. empty_subj = "/"
  5. private_key_pem = os.path.join(config_dir, "core", "private_key.pem")
  6. root_crt = os.path.join(config_dir, "registry", "root.crt")
  7. create_root_cert(empty_subj, key_path=private_key_pem, cert_path=root_crt)
  8. mark_file(private_key_pem)
  9. mark_file(root_crt)
  10. else:
  11. print("Copied configuration file: %s" % os.path.join("/tmp", "certfile", "private_key.pem"))
  12. shutil.copyfile(os.path.join("/tmp", "certfile", "private_key.pem"), os.path.join(core_config_dir, "private_key.pem"))
  13. print("Copied configuration file: %s" % os.path.join("/tmp", "certfile", "root.crt"))
  14. shutil.copyfile(os.path.join("/tmp", "certfile", "root.crt"), os.path.join(registry_config_dir, "root.crt"))
  15. #此处将harbor自动生成证书关闭,将证书拷贝到外部路径并直接指定,否则将导致出现两个节点鉴权失败的问题。
  16. 修改install.sh 添加参数 customize_crt == off #关闭自生成证书

5、启动harbor

分别进入harbor-1 harbor-2 执行启动命令

  1. ./install.sh --with-notary --with-clair --with-chartmuseum
  2. watch 'docker ps -a' #监测各组件运行情况

6、配置haproxy/keep-alived

在HA-1 HA-2节点 安装ha/keepalived 修改配置文件如下

harproxy(haproxy.cfg):

  1. #---------------------------------------------------------------------
  2. # Global settings
  3. #---------------------------------------------------------------------
  4. global
  5. # to have these messages end up in /var/log/haproxy.log you will
  6. # need to:
  7. #
  8. # 1) configure syslog to accept network log events. This is done
  9. # by adding the '-r' option to the SYSLOGD_OPTIONS in
  10. # /etc/sysconfig/syslog
  11. #
  12. # 2) configure local2 events to go to the /var/log/haproxy.log
  13. # file. A line like the following can be added to
  14. # /etc/sysconfig/syslog
  15. #
  16. # local2.* /var/log/haproxy.log
  17. #
  18. log 127.0.0.1 local2
  19. chroot /var/lib/haproxy
  20. pidfile /var/run/haproxy.pid
  21. maxconn 20000
  22. user haproxy
  23. group haproxy
  24. daemon
  25. tune.bufsize 131072
  26. tune.ssl.default-dh-param 2048
  27. # turn on stats unix socket
  28. stats socket /var/lib/haproxy/stats
  29. #---------------------------------------------------------------------
  30. # common defaults that all the 'listen' and 'backend' sections will
  31. # use if not designated in their block
  32. #---------------------------------------------------------------------
  33. defaults
  34. mode http
  35. log global
  36. option httplog
  37. option dontlog-normal
  38. option http-server-close
  39. option forwardfor except 127.0.0.0/8
  40. option redispatch
  41. retries 3
  42. timeout http-request 10s
  43. timeout queue 1m
  44. timeout connect 10s
  45. timeout client 1m
  46. timeout server 30m
  47. timeout http-keep-alive 10s
  48. timeout check 10s
  49. maxconn 10000
  50. #---------------------------------------------------------------------
  51. # static backend for serving up images, stylesheets and such
  52. #---------------------------------------------------------------------
  53. #---------------------------------------------------------------------
  54. # round robin balancing between the various backends
  55. #---------------------------------------------------------------------
  56. frontend app
  57. bind *:443
  58. balance roundrobin
  59. mode tcp
  60. server s1 100.65.22.2:443 weight 1 #绑定harbor-1 harbor-2 的443端口
  61. #server s2 100.65.22.3:443 weight 1
  62. #---------------------------------------------------------------------
  63. # round robin balancing between the various backends
  64. #---------------------------------------------------------------------
  65. frontend ceph
  66. bind *:80
  67. balance roundrobin
  68. server app1 100.xx.xx.xx:7480 check #ceph 可选配置
  1. keepalived (keepalived.conf):

  1. vrrp_script chk_http_haproxy {
  2. script "/app/haproxy/bin/check_haproxy.sh"
  3. interval 10
  4. weight 2
  5. }
  6. global_defs {
  7. notification_email {
  8. admin@admin.com
  9. }
  10. notification_email_from admin@admin.com
  11. smtp_server mail.admin.com
  12. smtp_connect_timeout 30
  13. router_id CMRH_WEB
  14. }
  15. vrrp_instance VI_1 {
  16. state MASTER
  17. interface eth0
  18. virtual_router_id 6
  19. priority 101
  20. advert_int 1
  21. track_script {
  22. #run the script
  23. chk_http_haproxy
  24. }
  25. virtual_ipaddress {
  26. 100.70.42.6
  27. }
  28. }
  29. /app/haproxy/bin/check_haproxy.sh
  30. #! /bin/bash
  31. num=`ps -C haproxy --no-header |wc -l`
  32. if [ $num -eq 0 ]; then
  33. /app/haproxy/sbin/haproxy -f /app/haproxy/conf/haproxy.cfg
  34. sleep 3
  35. if [ `ps -C haproxy --no-header |wc -l` -eq 0 ]; then
  36. killall keepalived
  37. fi
  38. fi
  1. #! /bin/bash
  2. num=`ps -C haproxy --no-header |wc -l`
  3. if [ $num -eq 0 ]; then
  4. /app/haproxy/sbin/haproxy -f /app/haproxy/conf/haproxy.cfg
  5. sleep 3
  6. if [ `ps -C haproxy --no-header |wc -l` -eq 0 ]; then
  7. killall keepalived
  8. fi
  9. fi

配置完成后启动在HA-1 HA-2 上启动haproxy

  1. systemcl start keepalived
  2. systemctl start haproxy

7、访问测试

1、访问ha-vip页面 443端口 测试前端访问

2、pull/push测试

3、关闭harbor-1 harbor-2节点:高可用测试

8、常见问题:

1、页面可正常访问,但经常性显示错误,账号登出

haproxy/keepalive配置错误,确认配置

2、harbor启动日志查看/问题排查:/var/log/harbor/下存在的log文件

3、401 SignatureMisMatch :

ceph地址配置错误,建议使用域名进行配置

4、harbor仓库内部数据访问异常:

此处可能是harbor迁移时,使用的新数据库内部有脏数据导致,可清除template1数据库内所有表数据重置。

5、notary数据库为本地:待解决

6、日志刷新时有概率出现无数据问题:交替访问harbor节点导致,待解决

7、unkown blob问题

  1. When setting up Harbor behind an nginx proxy or elastic load balancing, look for the line below, in common/templates/nginx/nginx.http.conf and remove it from the sections if the proxy already has similar settings: location /, location /v2/ and location /service/.
  2. proxy_set_header X-Forwarded-Proto $scheme;

harbor高可用集群搭建的更多相关文章

  1. .Net Core2.1 秒杀项目一步步实现CI/CD(Centos7.2)系列一:k8s高可用集群搭建总结以及部署API到k8s

    前言:本系列博客又更新了,是博主研究很长时间,亲自动手实践过后的心得,k8s集群是购买了5台阿里云服务器部署的,这个集群差不多搞了一周时间,关于k8s的知识点,我也是刚入门,这方面的知识建议参考博客园 ...

  2. 实现CI/CDk8s高可用集群搭建总结以及部署API到k8s

    实现CI/CD(Centos7.2)系列二:k8s高可用集群搭建总结以及部署API到k8s 前言:本系列博客又更新了,是博主研究很长时间,亲自动手实践过后的心得,k8s集群是购买了5台阿里云服务器部署 ...

  3. hadoop高可用集群搭建小结

    hadoop高可用集群搭建小结1.Zookeeper集群搭建2.格式化Zookeeper集群 (注:在Zookeeper集群建立hadoop-ha,amenode的元数据)3.开启Journalmno ...

  4. Spark高可用集群搭建

    Spark高可用集群搭建 node1    node2    node3   1.node1修改spark-env.sh,注释掉hadoop(就不用开启Hadoop集群了),添加如下语句 export ...

  5. Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)

    声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 一.服务器环境 主机名 IP 用户名 密码 安装目录 master188 192.168.29.188 hadoop hadoop /home/ha ...

  6. Hadoop 3.1.2(HA)+Zookeeper3.4.13+Hbase1.4.9(HA)+Hive2.3.4+Spark2.4.0(HA)高可用集群搭建

    目录 目录 1.前言 1.1.什么是 Hadoop? 1.1.1.什么是 YARN? 1.2.什么是 Zookeeper? 1.3.什么是 Hbase? 1.4.什么是 Hive 1.5.什么是 Sp ...

  7. MongoDB高可用集群搭建(主从、分片、路由、安全验证)

    目录 一.环境准备 1.部署图 2.模块介绍 3.服务器准备 二.环境变量 1.准备三台集群 2.安装解压 3.配置环境变量 三.集群搭建 1.新建配置目录 2.修改配置文件 3.分发其他节点 4.批 ...

  8. RabbitMQ高级指南:从配置、使用到高可用集群搭建

    本文大纲: 1. RabbitMQ简介 2. RabbitMQ安装与配置 3. C# 如何使用RabbitMQ 4. 几种Exchange模式 5. RPC 远程过程调用 6. RabbitMQ高可用 ...

  9. spring cloud 服务注册中心eureka高可用集群搭建

    spring cloud 服务注册中心eureka高可用集群搭建 一,准备工作 eureka可以类比zookeeper,本文用三台机器搭建集群,也就是说要启动三个eureka注册中心 1 本文三台eu ...

随机推荐

  1. Linux扩展分区和文件系统

    磁盘分区 linux也与windows一样,为了使用全部的磁盘空间,需要先对磁盘分区:如果所有分区的总容量小于磁盘容量,说明磁盘还有未分配空间,这个时候会对磁盘造成浪费.需要增加一个新的分区来将全部空 ...

  2. SQL根据两个日期生成年、月、日

    1 DECLARE @beginTime DATETIME, @endTime DATETIME 2 SET @beginTime ='2019-03-01' 3 SET @endTime ='201 ...

  3. shell的编程规范和变量

    目录 一.Shell脚本概述 1.shell脚本的概念 2.shell脚本应用场景 3.shell的作用--命令翻译器,"翻译官" 二.用户的登录shell 三.shell脚本的构 ...

  4. Hybrid接口

    目录 一.Hybrid接口 1.1 VLan的基本概念 1.2 Hybrid接口特点 1.3 Hybrid接口工作原理 1.4 Hybrid配置 一.Hybrid接口 1.1 VLan的基本概念 特点 ...

  5. JavaEE精英进阶课学习笔记《博学谷》

    JavaEE精英进阶课学习笔记<博学谷> 第1章 亿可控系统分析与设计 学习目标 了解物联网应用领域及发展现状 能够说出亿可控的核心功能 能够画出亿可控的系统架构图 能够完成亿可控环境的准 ...

  6. C++ 继承方式 与 普通方式 对比

    1 //C++ 继承 2 //继承是面向对象三大特性之一 3 4 #include <iostream> 5 #include <string> 6 using namespa ...

  7. 4.10 Python3 进阶 - 迭代器 & 生成器

    >>返回主目录 源码 from typing import Iterable, Iterator # 可迭代对象:字符串.列表.元组.字典.集合.range().enumerate()等 ...

  8. RationalRose使用

    UML 概述 什么是 UML? Unified Modeling Language (UML)又称统一建模语言或标准建 模语言,是始于 1997 年一个 OMG 标准,它是一个支持模型化 和软件系统开 ...

  9. Ubuntu本地提权适配不同小版本内核(CVE-2017-16995)

    朋友在执行的时候说有的会出现提权不成功,内核crash掉的现象.因为cred结构体的偏移量可能因为内核版本不同.内核编译选项不同而出现差异,作者给的exp偏移量是写死的,所以exp里面对应的偏移地址也 ...

  10. 【vue3】封装自定义全局插件

    [vue3]封装自定义全局插件 原vue2方法 main.js import Vue from 'vue' import App from './App.vue' import router from ...