1 环境

ubuntu20 virtualbox 的虚拟机

2 docker 与 docker-compose

  1. bruce@bruce-VirtualBox:~/harbor$ docker -v & docker-compose -v
  2. [1] 36159
  3. Docker version 20.10.7, build 20.10.7-0ubuntu5~20.04.2
  4. docker-compose version 1.25.0, build unknown
  5. [1]+ 已完成 docker -v
  6. bruce@bruce-VirtualBox:~/harbor$
  1. 题外话,开始没有 docker-compose,直接执行 sudo apt install docker-compose

3 安装

3.1 离线下载

下载地址:https://github.com/goharbor/harbor/releases 选择自己的版本,本次使用的是 2.4.2

3.2 解压

解压: tar -zxvf harbor-offline-installer-v2.4.2.tgz

3.3 配置

配置:cp harbor.yml.tmp harbor.yml,并修改 harbor.yml
主要是hostname,密码,https,docker volume 等

下面是全部的 harbor.yml 内容:

  1. # Configuration file of Harbor
  2. # The IP address or hostname to access admin UI and registry service.
  3. # DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
  4. hostname: 10.0.2.4
  5. # http related config
  6. http:
  7. # port for http, default is 80. If https enabled, this port will redirect to https port
  8. port: 80
  9. # https related config
  10. #https:
  11. # https port for harbor, default is 443
  12. #port: 443
  13. # The path of cert and key files for nginx
  14. #certificate: /your/certificate/path
  15. #private_key: /your/private/key/path
  16. # # Uncomment following will enable tls communication between all harbor components
  17. # internal_tls:
  18. # # set enabled to true means internal tls is enabled
  19. # enabled: true
  20. # # put your cert and key files on dir
  21. # dir: /etc/harbor/tls/internal
  22. # Uncomment external_url if you want to enable external proxy
  23. # And when it enabled the hostname will no longer used
  24. # external_url: https://reg.mydomain.com:8433
  25. # The initial password of Harbor admin
  26. # It only works in first time to install harbor
  27. # Remember Change the admin password from UI after launching Harbor.
  28. harbor_admin_password: Harbor12345
  29. # Harbor DB configuration
  30. database:
  31. # The password for the root user of Harbor DB. Change this before any production use.
  32. password: root123
  33. # The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
  34. max_idle_conns: 100
  35. # The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
  36. # Note: the default number of connections is 1024 for postgres of harbor.
  37. max_open_conns: 900
  38. # The default data volume
  39. data_volume: /data
  40. # Harbor Storage settings by default is using /data dir on local filesystem
  41. # Uncomment storage_service setting If you want to using external storage
  42. # storage_service:
  43. # # ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
  44. # # of registry's and chart repository's containers. This is usually needed when the user hosts a internal storage with self signed certificate.
  45. # ca_bundle:
  46. # # storage backend, default is filesystem, options include filesystem, azure, gcs, s3, swift and oss
  47. # # for more info about this configuration please refer https://docs.docker.com/registry/configuration/
  48. # filesystem:
  49. # maxthreads: 100
  50. # # set disable to true when you want to disable registry redirect
  51. # redirect:
  52. # disabled: false
  53. # Trivy configuration
  54. #
  55. # Trivy DB contains vulnerability information from NVD, Red Hat, and many other upstream vulnerability databases.
  56. # It is downloaded by Trivy from the GitHub release page https://github.com/aquasecurity/trivy-db/releases and cached
  57. # in the local file system. In addition, the database contains the update timestamp so Trivy can detect whether it
  58. # should download a newer version from the Internet or use the cached one. Currently, the database is updated every
  59. # 12 hours and published as a new release to GitHub.
  60. trivy:
  61. # ignoreUnfixed The flag to display only fixed vulnerabilities
  62. ignore_unfixed: false
  63. # skipUpdate The flag to enable or disable Trivy DB downloads from GitHub
  64. #
  65. # You might want to enable this flag in test or CI/CD environments to avoid GitHub rate limiting issues.
  66. # If the flag is enabled you have to download the `trivy-offline.tar.gz` archive manually, extract `trivy.db` and
  67. # `metadata.json` files and mount them in the `/home/scanner/.cache/trivy/db` path.
  68. skip_update: false
  69. #
  70. # The offline_scan option prevents Trivy from sending API requests to identify dependencies.
  71. # Scanning JAR files and pom.xml may require Internet access for better detection, but this option tries to avoid it.
  72. # For example, the offline mode will not try to resolve transitive dependencies in pom.xml when the dependency doesn't
  73. # exist in the local repositories. It means a number of detected vulnerabilities might be fewer in offline mode.
  74. # It would work if all the dependencies are in local.
  75. # This option doesn’t affect DB download. You need to specify "skip-update" as well as "offline-scan" in an air-gapped environment.
  76. offline_scan: false
  77. #
  78. # insecure The flag to skip verifying registry certificate
  79. insecure: false
  80. # github_token The GitHub access token to download Trivy DB
  81. #
  82. # Anonymous downloads from GitHub are subject to the limit of 60 requests per hour. Normally such rate limit is enough
  83. # for production operations. If, for any reason, it's not enough, you could increase the rate limit to 5000
  84. # requests per hour by specifying the GitHub access token. For more details on GitHub rate limiting please consult
  85. # https://developer.github.com/v3/#rate-limiting
  86. #
  87. # You can create a GitHub token by following the instructions in
  88. # https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
  89. #
  90. # github_token: xxx
  91. jobservice:
  92. # Maximum number of job workers in job service
  93. max_job_workers: 10
  94. notification:
  95. # Maximum retry count for webhook job
  96. webhook_job_max_retry: 10
  97. chart:
  98. # Change the value of absolute_url to enabled can enable absolute url in chart
  99. absolute_url: disabled
  100. # Log configurations
  101. log:
  102. # options are debug, info, warning, error, fatal
  103. level: info
  104. # configs for logs in local storage
  105. local:
  106. # Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
  107. rotate_count: 50
  108. # 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.
  109. # 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
  110. # are all valid.
  111. rotate_size: 200M
  112. # The directory on your host that store log
  113. location: /var/log/harbor
  114. # Uncomment following lines to enable external syslog endpoint.
  115. # external_endpoint:
  116. # # protocol used to transmit log to external endpoint, options is tcp or udp
  117. # protocol: tcp
  118. # # The host of external endpoint
  119. # host: localhost
  120. # # Port of external endpoint
  121. # port: 5140
  122. #This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
  123. _version: 2.4.0
  124. # Uncomment external_database if using external database.
  125. # external_database:
  126. # harbor:
  127. # host: harbor_db_host
  128. # port: harbor_db_port
  129. # db_name: harbor_db_name
  130. # username: harbor_db_username
  131. # password: harbor_db_password
  132. # ssl_mode: disable
  133. # max_idle_conns: 2
  134. # max_open_conns: 0
  135. # notary_signer:
  136. # host: notary_signer_db_host
  137. # port: notary_signer_db_port
  138. # db_name: notary_signer_db_name
  139. # username: notary_signer_db_username
  140. # password: notary_signer_db_password
  141. # ssl_mode: disable
  142. # notary_server:
  143. # host: notary_server_db_host
  144. # port: notary_server_db_port
  145. # db_name: notary_server_db_name
  146. # username: notary_server_db_username
  147. # password: notary_server_db_password
  148. # ssl_mode: disable
  149. # Uncomment external_redis if using external Redis server
  150. # external_redis:
  151. # # support redis, redis+sentinel
  152. # # host for redis: <host_redis>:<port_redis>
  153. # # host for redis+sentinel:
  154. # # <host_sentinel1>:<port_sentinel1>,<host_sentinel2>:<port_sentinel2>,<host_sentinel3>:<port_sentinel3>
  155. # host: redis:6379
  156. # password:
  157. # # sentinel_master_set must be set to support redis+sentinel
  158. # #sentinel_master_set:
  159. # # db_index 0 is for core, it's unchangeable
  160. # registry_db_index: 1
  161. # jobservice_db_index: 2
  162. # chartmuseum_db_index: 3
  163. # trivy_db_index: 5
  164. # idle_timeout_seconds: 30
  165. # Uncomment uaa for trusting the certificate of uaa instance that is hosted via self-signed cert.
  166. # uaa:
  167. # ca_file: /path/to/ca
  168. # Global proxy
  169. # Config http proxy for components, e.g. http://my.proxy.com:3128
  170. # Components doesn't need to connect to each others via http proxy.
  171. # Remove component from `components` array if want disable proxy
  172. # for it. If you want use proxy for replication, MUST enable proxy
  173. # for core and jobservice, and set `http_proxy` and `https_proxy`.
  174. # Add domain to the `no_proxy` field, when you want disable proxy
  175. # for some special registry.
  176. proxy:
  177. http_proxy:
  178. https_proxy:
  179. no_proxy:
  180. components:
  181. - core
  182. - jobservice
  183. - trivy
  184. # metric:
  185. # enabled: false
  186. # port: 9090
  187. # path: /metrics
  188. # Trace related config
  189. # only can enable one trace provider(jaeger or otel) at the same time,
  190. # and when using jaeger as provider, can only enable it with agent mode or collector mode.
  191. # if using jaeger collector mode, uncomment endpoint and uncomment username, password if needed
  192. # if using jaeger agetn mode uncomment agent_host and agent_port
  193. # trace:
  194. # enabled: true
  195. # # set sample_rate to 1 if you wanna sampling 100% of trace data; set 0.5 if you wanna sampling 50% of trace data, and so forth
  196. # sample_rate: 1
  197. # # # namespace used to differenciate different harbor services
  198. # # namespace:
  199. # # # attributes is a key value dict contains user defined attributes used to initialize trace provider
  200. # # attributes:
  201. # # application: harbor
  202. # # # jaeger should be 1.26 or newer.
  203. # # jaeger:
  204. # # endpoint: http://hostname:14268/api/traces
  205. # # username:
  206. # # password:
  207. # # agent_host: hostname
  208. # # # export trace data by jaeger.thrift in compact mode
  209. # # agent_port: 6831
  210. # # otel:
  211. # # endpoint: hostname:4318
  212. # # url_path: /v1/traces
  213. # # compression: false
  214. # # insecure: true
  215. # # timeout: 10s

3.4 prepare 预处理

预处理一下:sudo ./prepare 会生成相关的配置等

  1. bruce@bruce-VirtualBox:~/harbor$ sudo ./prepare
  2. [sudo] bruce 的密码:
  3. prepare base dir is set to /home/bruce/harbor
  4. Unable to find image 'goharbor/prepare:v2.4.2' locally
  5. v2.4.2: Pulling from goharbor/prepare
  6. 6c964f3b879f: Pull complete
  7. 3042f4284e2c: Pull complete
  8. 7a91ea24644b: Pull complete
  9. b3c79e094a18: Pull complete
  10. 110443f7949d: Pull complete
  11. 1fbee02500d7: Pull complete
  12. 8675c3a61fe1: Pull complete
  13. d48514bf9c2b: Pull complete
  14. Digest: sha256:b14da6252672c596291f02a5e76fbb065f558aaf0a647f90e1c77aefaa29db74
  15. Status: Downloaded newer image for goharbor/prepare:v2.4.2
  16. WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
  17. Generated configuration file: /config/portal/nginx.conf
  18. Generated configuration file: /config/log/logrotate.conf
  19. Generated configuration file: /config/log/rsyslog_docker.conf
  20. Generated configuration file: /config/nginx/nginx.conf
  21. Generated configuration file: /config/core/env
  22. Generated configuration file: /config/core/app.conf
  23. Generated configuration file: /config/registry/config.yml
  24. Generated configuration file: /config/registryctl/env
  25. Generated configuration file: /config/registryctl/config.yml
  26. Generated configuration file: /config/db/env
  27. Generated configuration file: /config/jobservice/env
  28. Generated configuration file: /config/jobservice/config.yml
  29. Generated and saved secret to file: /data/secret/keys/secretkey
  30. Successfully called func: create_root_cert
  31. Generated configuration file: /compose_location/docker-compose.yml
  32. Clean up the input dir
  33. bruce@bruce-VirtualBox:~/harbor$

3.5 安装

安装:sudo ./install.sh

  1. bruce@bruce-VirtualBox:~/harbor$ sudo ./install.sh
  2. [Step 0]: checking if docker is installed ...
  3. Note: docker version: 20.10.7
  4. [Step 1]: checking docker-compose is installed ...
  5. Note: docker-compose version: 1.25.0
  6. [Step 2]: loading Harbor images ...
  7. 7abced50bfd2: Loading layer [==================================================>] 5.296MB/5.296MB
  8. 43ad630c07b8: Loading layer [==================================================>] 5.928MB/5.928MB
  9. 3457e72d7725: Loading layer [==================================================>] 14.47MB/14.47MB
  10. 4a079b4b377a: Loading layer [==================================================>] 29.29MB/29.29MB
  11. 7b180b7bf3b4: Loading layer [==================================================>] 22.02kB/22.02kB
  12. 7b678649a1be: Loading layer [==================================================>] 14.47MB/14.47MB
  13. Loaded image: goharbor/notary-signer-photon:v2.4.2
  14. 4f650960b0dc: Loading layer [==================================================>] 5.832MB/5.832MB
  15. 967788659fd5: Loading layer [==================================================>] 4.096kB/4.096kB
  16. 30cc19bdf2d6: Loading layer [==================================================>] 3.072kB/3.072kB
  17. 9ccede1a4324: Loading layer [==================================================>] 47.85MB/47.85MB
  18. 86f4685faff0: Loading layer [==================================================>] 12.38MB/12.38MB
  19. 25af1cf9c44e: Loading layer [==================================================>] 61.02MB/61.02MB
  20. Loaded image: goharbor/trivy-adapter-photon:v2.4.2
  21. Loaded image: goharbor/prepare:v2.4.2
  22. 323ed00cae7e: Loading layer [==================================================>] 8.447MB/8.447MB
  23. c3f8c4668352: Loading layer [==================================================>] 3.584kB/3.584kB
  24. 94b71cd07106: Loading layer [==================================================>] 2.56kB/2.56kB
  25. 5d5638decfe4: Loading layer [==================================================>] 75.6MB/75.6MB
  26. 48426521f41c: Loading layer [==================================================>] 5.632kB/5.632kB
  27. bb977315930e: Loading layer [==================================================>] 97.28kB/97.28kB
  28. 2a80a5f64ee7: Loading layer [==================================================>] 11.78kB/11.78kB
  29. 0a5146355ed0: Loading layer [==================================================>] 76.5MB/76.5MB
  30. 7d5eac57d5fa: Loading layer [==================================================>] 2.56kB/2.56kB
  31. Loaded image: goharbor/harbor-core:v2.4.2
  32. f7cedf07c50c: Loading layer [==================================================>] 8.447MB/8.447MB
  33. b2a916599ac7: Loading layer [==================================================>] 3.584kB/3.584kB
  34. 3bc2556f46f8: Loading layer [==================================================>] 2.56kB/2.56kB
  35. a9cc192089ec: Loading layer [==================================================>] 86.96MB/86.96MB
  36. 9e9c53c1bd85: Loading layer [==================================================>] 87.75MB/87.75MB
  37. Loaded image: goharbor/harbor-jobservice:v2.4.2
  38. 6111e09009c2: Loading layer [==================================================>] 7.222MB/7.222MB
  39. Loaded image: goharbor/nginx-photon:v2.4.2
  40. f4658d2c3aa3: Loading layer [==================================================>] 8.447MB/8.447MB
  41. 4b7bdcad271f: Loading layer [==================================================>] 18.13MB/18.13MB
  42. cbb8c130a490: Loading layer [==================================================>] 4.608kB/4.608kB
  43. f1367013643c: Loading layer [==================================================>] 18.93MB/18.93MB
  44. Loaded image: goharbor/harbor-exporter:v2.4.2
  45. a1b12e0ab8ea: Loading layer [==================================================>] 5.296MB/5.296MB
  46. df6629a5ee28: Loading layer [==================================================>] 5.928MB/5.928MB
  47. 944fcde3a84b: Loading layer [==================================================>] 15.88MB/15.88MB
  48. 300e181c27cf: Loading layer [==================================================>] 29.29MB/29.29MB
  49. 87f01e78dde1: Loading layer [==================================================>] 22.02kB/22.02kB
  50. 8306283aa89d: Loading layer [==================================================>] 15.88MB/15.88MB
  51. Loaded image: goharbor/notary-server-photon:v2.4.2
  52. c635aace513a: Loading layer [==================================================>] 5.3MB/5.3MB
  53. 8deb84525956: Loading layer [==================================================>] 64.5MB/64.5MB
  54. 5d1431f9963f: Loading layer [==================================================>] 3.072kB/3.072kB
  55. faeb0aac7135: Loading layer [==================================================>] 4.096kB/4.096kB
  56. 7ade25e3acdb: Loading layer [==================================================>] 65.29MB/65.29MB
  57. Loaded image: goharbor/chartmuseum-photon:v2.4.2
  58. 27495e3181af: Loading layer [==================================================>] 7.222MB/7.222MB
  59. 88649dba6134: Loading layer [==================================================>] 7.356MB/7.356MB
  60. 875f964b6f85: Loading layer [==================================================>] 1.754MB/1.754MB
  61. Loaded image: goharbor/harbor-portal:v2.4.2
  62. c724cc796747: Loading layer [==================================================>] 124.3MB/124.3MB
  63. b6c853c6dc0d: Loading layer [==================================================>] 3.584kB/3.584kB
  64. 0c5772798040: Loading layer [==================================================>] 3.072kB/3.072kB
  65. c5f3bfcfa62d: Loading layer [==================================================>] 2.56kB/2.56kB
  66. 2602a8530e9d: Loading layer [==================================================>] 3.072kB/3.072kB
  67. ba9b43b5ffb1: Loading layer [==================================================>] 3.584kB/3.584kB
  68. cf92b578ba00: Loading layer [==================================================>] 20.48kB/20.48kB
  69. Loaded image: goharbor/harbor-log:v2.4.2
  70. fc1f8cdaf1ce: Loading layer [==================================================>] 1.096MB/1.096MB
  71. eb68e72cbb03: Loading layer [==================================================>] 5.888MB/5.888MB
  72. 53a31c9e9836: Loading layer [==================================================>] 166.2MB/166.2MB
  73. bed7172f8681: Loading layer [==================================================>] 17.75MB/17.75MB
  74. c8fcd33ae148: Loading layer [==================================================>] 4.096kB/4.096kB
  75. 0c8d734a07ee: Loading layer [==================================================>] 6.144kB/6.144kB
  76. c01db4825573: Loading layer [==================================================>] 3.072kB/3.072kB
  77. 4802d0abc8ba: Loading layer [==================================================>] 2.048kB/2.048kB
  78. 70bafeb87c65: Loading layer [==================================================>] 2.56kB/2.56kB
  79. 376ced88e40e: Loading layer [==================================================>] 2.56kB/2.56kB
  80. 0ba55f221469: Loading layer [==================================================>] 2.56kB/2.56kB
  81. 55cac263100c: Loading layer [==================================================>] 8.704kB/8.704kB
  82. Loaded image: goharbor/harbor-db:v2.4.2
  83. 30ed654bbb0e: Loading layer [==================================================>] 5.301MB/5.301MB
  84. 51a81f0bf9ea: Loading layer [==================================================>] 4.096kB/4.096kB
  85. 12992ea6b45e: Loading layer [==================================================>] 3.072kB/3.072kB
  86. 91b97bcaa9d7: Loading layer [==================================================>] 17.32MB/17.32MB
  87. 1a992360f6fa: Loading layer [==================================================>] 18.12MB/18.12MB
  88. Loaded image: goharbor/registry-photon:v2.4.2
  89. d7224235291f: Loading layer [==================================================>] 5.301MB/5.301MB
  90. dd26d9070a7b: Loading layer [==================================================>] 4.096kB/4.096kB
  91. 4022ecee5f13: Loading layer [==================================================>] 17.32MB/17.32MB
  92. 93d727d0accc: Loading layer [==================================================>] 3.072kB/3.072kB
  93. 8a56be8f0b84: Loading layer [==================================================>] 28.69MB/28.69MB
  94. 629472303402: Loading layer [==================================================>] 46.81MB/46.81MB
  95. Loaded image: goharbor/harbor-registryctl:v2.4.2
  96. bf4dfb7b7a70: Loading layer [==================================================>] 120.1MB/120.1MB
  97. a0b0ce804b6b: Loading layer [==================================================>] 3.072kB/3.072kB
  98. f088aae660dd: Loading layer [==================================================>] 59.9kB/59.9kB
  99. 2c15508db9bd: Loading layer [==================================================>] 61.95kB/61.95kB
  100. Loaded image: goharbor/redis-photon:v2.4.2
  101. [Step 3]: preparing environment ...
  102. [Step 4]: preparing harbor configs ...
  103. prepare base dir is set to /home/bruce/harbor
  104. WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
  105. Clearing the configuration file: /config/jobservice/env
  106. Clearing the configuration file: /config/jobservice/config.yml
  107. Clearing the configuration file: /config/nginx/nginx.conf
  108. Clearing the configuration file: /config/log/logrotate.conf
  109. Clearing the configuration file: /config/log/rsyslog_docker.conf
  110. Clearing the configuration file: /config/core/app.conf
  111. Clearing the configuration file: /config/core/env
  112. Clearing the configuration file: /config/registry/passwd
  113. Clearing the configuration file: /config/registry/config.yml
  114. Clearing the configuration file: /config/portal/nginx.conf
  115. Clearing the configuration file: /config/db/env
  116. Clearing the configuration file: /config/registryctl/config.yml
  117. Clearing the configuration file: /config/registryctl/env
  118. Generated configuration file: /config/portal/nginx.conf
  119. Generated configuration file: /config/log/logrotate.conf
  120. Generated configuration file: /config/log/rsyslog_docker.conf
  121. Generated configuration file: /config/nginx/nginx.conf
  122. Generated configuration file: /config/core/env
  123. Generated configuration file: /config/core/app.conf
  124. Generated configuration file: /config/registry/config.yml
  125. Generated configuration file: /config/registryctl/env
  126. Generated configuration file: /config/registryctl/config.yml
  127. Generated configuration file: /config/db/env
  128. Generated configuration file: /config/jobservice/env
  129. Generated configuration file: /config/jobservice/config.yml
  130. loaded secret from file: /data/secret/keys/secretkey
  131. Generated configuration file: /compose_location/docker-compose.yml
  132. Clean up the input dir
  133. [Step 5]: starting Harbor ...
  134. Creating network "harbor_harbor" with the default driver
  135. Creating harbor-log ... done
  136. Creating harbor-portal ... done
  137. Creating registry ... done
  138. Creating registryctl ... done
  139. Creating redis ... done
  140. Creating harbor-db ... done
  141. Creating harbor-core ... done
  142. Creating nginx ... done
  143. Creating harbor-jobservice ... done
  144. ----Harbor has been installed and started successfully.----
  145. bruce@bruce-VirtualBox:~/harbor$

3.6 访问

本次是 http://localhost 或者 http://10.0.2.4,账号是 admin,密码是 Harbor12345
image.png