Harbor 安装小记

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介: 安装 Harbor 并推送镜像小记

场景

在搭建私有云环境时,我们需要将我们打包的镜像存储在局域网内,而不是把镜像推送到hub.docker.com;一方面是因为安全问题,另一方面在局域网内存储,网速炒鸡快。当然对于私有云搭建,在本地搭建镜像仓库那是必须的。接下来,对我安装Harbor 做一个记录。

分析

因为 Harbor 是用 docker 跑起来的,所以我们的机器上必须有 docker 环境,还有比较中要的一点,Harbor 需要使用docker-compose, 所以需要 docker-compose。

安装

docker 安装

略...(相信你肯定不会怪我)

docker-compose 安装

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
docker-compose version 1.24.0, build 1110ad01

安装Harbor

离线安装版

获取并解压

$ wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.0.tgz
$ tar xvf harbor-offline-installer-v1.8.0.tgz

解压会生成 Harbor 文件夹

修改配置文件

$ cd Harbor
$ vim /Harbor.yaml

需要配置的地方有几处,但最重要的是hostname, hostname 必须指定为域名,不能使localhost,127.0.0.1 这样的地址,别的密码、端口可可定义。如下是我的配置

# Configuration file of Harbor

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: hub.k8s.com

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

# https related config
# https:
#   # https port for harbor, default is 443
#   port: 443
#   # The path of cert and key files for nginx
#   certificate: /your/certificate/path
#   private_key: /your/private/key/path

# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345

# Harbor DB configuration
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: root123

# The default data volume
data_volume: /data

# Harbor Storage settings by default is using /data dir on local filesystem
# Uncomment storage_service setting If you want to using external storage
# storage_service:
#   # ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
#   # of registry's and chart repository's containers.  This is usually needed when the user hosts a internal storage with self signed certificate.
#   ca_bundle:

#   # storage backend, default is filesystem, options include filesystem, azure, gcs, s3, swift and oss
#   # for more info about this configuration please refer https://docs.docker.com/registry/configuration/
#   filesystem:
#     maxthreads: 100
#   # set disable to true when you want to disable registry redirect
#   redirect:
#     disabled: false

# Clair configuration
clair:
  # The interval of clair updaters, the unit is hour, set to 0 to disable the updaters.
  updaters_interval: 12

  # Config http proxy for Clair, e.g. http://my.proxy.com:3128
  # Clair doesn't need to connect to harbor internal components via http proxy.
  http_proxy:
  https_proxy:
  no_proxy: 127.0.0.1,localhost,core,registry

jobservice:
  # Maximum number of job workers in job service
  max_job_workers: 10

chart:
  # Change the value of absolute_url to enabled can enable absolute url in chart
  absolute_url: disabled

# Log configurations
log:
  # options are debug, info, warning, error, fatal
  level: info
  # Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
  rotate_count: 50
  # 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.
  # 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
  # are all valid.
  rotate_size: 200M
  # The directory on your host that store log
  location: /var/log/harbor

#This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
_version: 1.8.0

# Uncomment external_database if using external database. Currently only support POSTGRES.
# Four databases are needed to be create first by users for Harbor core, Clair, Notary server
# and Notary signer. And the tables will be generated automatically when Harbor starting up.
# NOTE: external_database is unable to custom attributes individually, you must do them in block.
# 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
#   clair:
#     host: clair_db_host
#     port: clair_db_port
#     db_name: clair_db_name
#     username: clair_db_username
#     password: clair_db_password
#     ssl_mode: disable
#   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: disable

# Uncomment external_redis if using external Redis server
# external_redis:
#   host: redis
#   port: 6379
#   password:
#   # db_index 0 is for core, it's unchangeable
#   registry_db_index: 1
#   jobservice_db_index: 2
#   chartmuseum_db_index: 3

# Uncomment uaa for trusting the certificate of uaa instance that is hosted via self-signed cert.
# uaa:
#   ca_file: /path/to/ca

执行安装

$ ./install.sh
......
Creating harbor-portal     ... done
Creating nginx             ... done

 ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://hub.k8s.com.
For more details, please visit https://github.com/goharbor/harbor .

最后出现如上提示就安装成功了。将hub.k8s.com解析到本地即可访问。

harbor

配置/etc/docker/daemon.json

配置此项的目的是让 docker push 可以将镜像推送到私有仓库中

$ vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://gmjjwogo.mirror.aliyuncs.com"],
  "insecure-registries": ["hub.k8s.com"] # 追加内容,必须符合json规范
}

重启 docker

$ systemctl restart docker

将本地golang 镜像推送到私有仓库

$ docker login hub.k8s.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-store

Login Succeeded

为golang 打标签并推送镜像

$ docker tag golang:alpine hub.k8s.com/cms/golang:alpine
$  docker push hub.k8s.com/cms/golang:alpine
The push refers to repository [hub.k8s.com/cms/golang]
23419e186866: Pushed
1f6ba46a9c52: Pushed
968d46c1d20e: Pushed
b87598efb2f0: Pushed
f1b5933fe4b5: Pushed
alpine: digest: sha256:5ec3232b32e6876c0941d66d8392f667c77ca1ef14cafb85991deea4339b92da size: 1365

小结

Harbor 是一个 docker 镜像私有仓库的解决方案,是基于 docker-compose 运行起来的,使用相对简单。

相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
相关文章
|
存储 运维 Kubernetes
在k8s上安装Harbor
在k8s上安装Harbor
685 0
|
2月前
|
存储 应用服务中间件 开发工具
docker镜像上传至Harbor及从Harbor下载
docker镜像上传至Harbor及从Harbor下载
|
3月前
|
应用服务中间件 nginx 数据安全/隐私保护
使用Harbor搭建Docker私有仓库
Harbor是一款开源的企业级Docker仓库管理工具,分为私有与公有仓库两种类型,其中私有仓库被广泛应用于运维场景。Harbor提供图形化界面,便于直观操作,并且其核心组件均由容器构建而成,因此安装时需预先配置Docker及docker-compose。Harbor支持基于项目的用户与仓库管理,实现细粒度的权限控制;具备镜像复制、日志收集等功能,并可通过UI直接管理镜像,支持审计追踪。部署Harbor涉及配置文件调整、登录认证等步骤,并可通过客户端进行镜像的上传、拉取等操作。系统内置多种角色,包括受限访客、访客、开发者、维护人员及管理员,以满足不同场景下的使用需求。
152 0
|
6月前
|
Ubuntu 关系型数据库 PostgreSQL
部署harbor
在Ubuntu 22.04 LTS环境下,部署Harbor私有仓库的步骤包括:确保已安装Docker(版本24.0.6),参考官方v2.5.3安装指南,注意避免在NFS4挂载磁盘上部署以防止PostgreSQL相关问题。首先,生成SSL证书,然后更新Docker配置并重启服务。解压并配置Harbor离线安装包,修改`harbor.yml`,执行`prepare`和`install.sh`脚本,最后将Harbor设置为系统服务。
197 0
|
应用服务中间件 数据安全/隐私保护 nginx
搭建harbor
通过harbor在线包搭建harbor服务
101 1
|
应用服务中间件 nginx Docker
Harbor部署 2
Harbor部署
159 0
|
Docker 容器
Harbor部署 1
Harbor部署
|
网络协议 关系型数据库 Linux
CentOS7 下搭建 Harbor 仓库以及登录
手把手教会你在 CentOS7 环境下搭建 Harbor 仓库,以及使用 Docker 以 HTTP 方式登录 Harbor 仓库。
1069 0
CentOS7 下搭建 Harbor 仓库以及登录
|
Docker 容器
Docker之私有仓库harbor (二)
Docker之私有仓库harbor (二)
117 0
|
JSON Kubernetes 算法
Harbor再次安装与使用
Harbor再次安装与使用
195 0