harbor-私有镜像仓库的离线安装部署

发布时间 2023-09-14 22:42:01作者: the1729cranes

harbor-私有镜像仓库的离线安装部署

最低安装条件:

资源 最低限度 推荐
CPU 2核 4核
内存 4 GB 8 GB

最低软件要求:

软件 版本 描述
Docker engine 版本 17.06.0-ce+ 或更高版本 有关安装说明,请参阅 Docker 引擎文档
Docker Compose 版本 1.18.0 或更高版本 有关安装说明,请参阅 Docker Compose 文档
OpenSSL 最新的优先 用于为 Harbor 生成证书和密钥

Harbor 要求在目标主机上打开以下端口:

端口号 协议 描述
443 HTTPS Harbor 门户和核心 API 接受此端口上的 HTTPS 请求。您可以在配置文件中更改此端口。
4443 HTTPS 与 Harbor 的 Docker 内容信任服务的连接。仅在启用 Notary 时才需要。您可以在配置文件中更改此端口。
80 HTTP Harbor 门户和核心 API 接受此端口上的 HTTP 请求。您可以在配置文件中更改此端口。

离线安装步骤

安装docker
# 配置阿里云的repo源
yum install -y yum-utils
 
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 
# 安装docker服务
yum install docker-ce-20.10.6 -y
 
# 启动docker,设置开机自启
systemctl start docker && systemctl enable docker.service
 
# 查看docker版本,docker compose版本
[root@localhost harbor]# docker version
Client: Docker Engine - Community
 Version:           24.0.6
 API version:       1.41 (downgraded from 1.43)
 Go version:        go1.20.7
 Git commit:        ed223bc
 Built:             Mon Sep  4 12:35:25 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          20.10.6
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8728dd2
  Built:            Fri Apr  9 22:43:57 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@localhost harbor]# docker compose version
Docker Compose version v2.21.0
[root@localhost harbor]# 

安装harbor

官方发布 页面下载离线安装包

image

解压后进入harbor文件夹,记得复制harbor.yml.tmpl配置文件为harbor.yml

[root@localhost ~]# tar -zxf harbor-offline-installer-v2.7.3.tgz 
[root@localhost ~]# cd harbor
# harbor.yml.tmpl为配置文件,install.sh为安装执行文件
[root@localhost harbor]# ls
common  common.sh  docker-compose.yml  harbor.v2.7.3.tar.gz  harbor.yml  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@localhost harbor]# 

打开harbor.yml文件修改三处位置

# 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.
# 设置harbor的域名,注意不要使用localhost或者127.0.0.1
hostname: 192.168.142.138

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  # 设置http开放端口
  port: 8088

# https related config
# 这里我们不用https,注释掉
#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

执行./install.sh命令安装harbor

根据harbor.yml文件中配置的IP地址和端口访问

image
image

现在可以使用harbor创建项目,即存放镜像的仓库,harbor初始帮我们创建了library仓库

由于我部署的时候没有使用HTTPS,所以使用docker登录的时候会出现一下异常信息:

image

原因:Docker自从1.3.X之后docker registry交互默认使用的是HTTPS,但是搭建私有镜像默认使用的是HTTP服务,所以与私有镜像交时出现以上错误。

解决办法:找到docker 的 daemon.json 配置文件,CentOS 7 的路径:/etc/docker/daemon.json(系统版本不同所处位置不同,其他版本的请自行百度),如果路径下没有这个文件自己创建即可。然后再配置文件里加上:

{
  "registry-mirrors": ["https://mirror.ccs.tencentyun.com"],
  "insecure-registries": ["192.168.142.138:8088"]
}

操作完成重新加载:

# 修改完成后reload配置文件
sudo systemctl daemon-reload
 
# 重启docker服务
sudo systemctl restart docker

关闭和启动harbor

# 关闭
docker compose down
# 启动
docker compose up

harbor基本操作

登录harbor

[root@localhost harbor]# docker login -u admin -p Harbor12345 192.168.142.138:8088
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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

对nginx镜像进行上传仓库

# 在项目中标记镜像:
docker tag SOURCE_IMAGE[:TAG] 192.168.142.138:8088/library/REPOSITORY[:TAG]
# 推送镜像到当前项目:
docker push 192.168.142.138:8088/library/REPOSITORY[:TAG]