前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Harbor .v1.10.2 私有镜像仓库的自签CA证书、安装使用【超详细官方文档翻译说明】

Harbor .v1.10.2 私有镜像仓库的自签CA证书、安装使用【超详细官方文档翻译说明】

作者头像
Devops海洋的渔夫
发布2020-04-22 11:18:16
3.6K0
发布2020-04-22 11:18:16
举报
文章被收录于专栏:Devops专栏Devops专栏Devops专栏

需求

在以前搭建docker镜像私有仓库的时候,我都是使用registery搭建。本篇章来尝试另一个新的镜像仓库Harbor。

Harbor介绍

Harbor是由VMware公司开源的企业级的Docker Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能。

它是Docker Registry的更高级封装,它除了提供友好的Web UI界面,角色和用户权限管理,用户操作审计等功能外,它还整合了K8s的插件(Add-ons)仓库,即Helm通过chart方式下载,管理,安装K8s插件,而chartmuseum可以提供存储chart数据的仓库【注:helm就相当于k8s的yum】。

另外它还整合了两个开源的安全组件,一个是Notary,另一个是Clair,Notary类似于私有CA中心,而Clair则是容器安全扫描工具,它通过各大厂商提供的CVE漏洞库来获取最新漏洞信息,并扫描用户上传的容器是否存在已知的漏洞信息,这两个安全功能对于企业级私有仓库来说是非常具有意义的。

各组件功能如下: harbor-adminserver:配置管理中心 harbor-dbMysql:数据库 harbor-jobservice:负责镜像复制 harbor-log:记录操作日志 harbor-ui:Web管理页面和API nginx:前端代理,负责前端页面和镜像上传/下载转发 redis:会话 registry:镜像存储

Harbor相关地址

官网:https://goharbor.io/

Github地址:https://github.com/goharbor/harbor

操作文档:https://goharbor.io/docs/

安装Harbor

Harbor安装有多种方式:

  • 在线安装:从Docker Hub下载Harbor相关镜像,因此安装软件包非常小
  • 离线安装:安装包包含部署的相关镜像,因此安装包比较大

本次篇章我的环境是Centos7.4,使用离线的安装方式来进行安装。大概是因为我总是习惯性考虑离线操作的情况吧。

环境要求

回到Harbor的Github地址,可以看到环境的要求:

System requirements:

On a Linux host: docker 17.06.0-ce+ and docker-compose 1.18.0+ .

下面来根据要求,逐步实现一下。

安装 docker-ce

注意:安装这个docker的版本不要偷懒,直接用yum install docker,不然安装的时候就会报错如下:

卸载旧版本

Docker 的旧版本被称为 docker 或 docker-engine。如果这些已安装,请卸载它们以及关联 的依赖关系。

yum remove docker docker-common docker-selinux docker-engine -y
使用 docker hub 仓库安装:
1.安装依赖包:
yum install -y yum-utils device-mapper-persistent-data lvm2
2.设置yum源

官方源

yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

国内源

yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

在这里配置使用国内阿里云的yum源就好。如下:

3.安装 docker-ce
  • 安装最新版本:
yum install docker-ce -y
# 这个命令会安装最新版本,安装完后,并不会启动 docker,会创建 docker 组,但是组中没有任何用户。
  • 可以使用以下命令列出可用版本,选择安装不同版本。
yum list docker-ce --showduplicates | sort -r
  • 启动 docker
systemctl start docker
  • 测试。检查 docker 是否正确安装并运行 hello-world 镜像
docker run hello-world
  • 建立 docker 用户组 默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户 和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。
  • 建立 docker 组:
groupadd docker
  • 将当前用户加入 docker 组:
sudo usermod -aG docker $USER

版本如下:

[root@server01 ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:25:42 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[root@server01 ~]# 
4.拷贝docker下载的相关服务证书

升级为最新版本的docker-ce有一个坑,就是会将docker hub等服务下载的证书都清除了,导致docker hub的镜像无法下载。

而且镜像存储格式的升级也导致无法启动服务,必须重新下载镜像。

解决的方法:卸载docker-ce,重新安装docker,然后保存相关证书,如下:

然后再重新安装docker-ce,将证书拷贝进去即可。

安装 docker-compose

yum install docker-compose -y

版本如下:

[root@server01 docker]# docker-compose --version
docker-compose version 1.18.0, build 8dd22a9
[root@server01 docker]# 

下载Harbor安装包

根据Github提示,可以看到下载Harbor的release版本链接以及安装配置的引导文档。

其中下载 Harbor 的 release 版本,如下:

https://github.com/goharbor/harbor/releases

*.asc文件是用来验证该软件包是否正版,所以不用下载了,在这里肯定是正版。

下载地址如下:

https://github.com/goharbor/harbor/releases/download/v1.10.2/harbor-offline-installer-v1.10.2.tgz

不过这个下载速度的确有些堪忧。

没办法,直接切v**,使用迅雷下载了,速度如下:

这个速度还是杠杠的!

下载完毕之后,将安装包上传至服务器上。

另外,查阅安装的引导文档如下:https://goharbor.io/docs/1.10/install-config/download-installer/

解压Harbor安装包

# 解压
[root@server01 harbor]# tar -zxvf harbor-offline-installer-v1.10.2.tgz 
harbor/harbor.v1.10.2.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml
[root@server01 harbor]# 
# 可以看到解压到 harbor 文件夹中
[root@server01 harbor]# ls
harbor  harbor-offline-installer-v1.10.2.tgz
[root@server01 harbor]# 
# 查看解压后的文件
[root@server01 harbor]# cd harbor/
[root@server01 harbor]# ls
common.sh  harbor.v1.10.2.tar.gz  harbor.yml  install.sh  LICENSE  prepare
[root@server01 harbor]# 

其中 harbor.v1.10.2.tar.gz 里就是 Harbor 用到的镜像。

解压完毕之后,根据文档就是要选择是否配置Https安装访问、以及配置安装Harbor的yml文件。

配置对Harbor的HTTPS访问

官网文档说明:https://goharbor.io/docs/1.10/install-config/configure-https/

By default, Harbor does not ship with certificates. It is possible to deploy Harbor without security, so that you can connect to it over HTTP. However, using HTTP is acceptable only in air-gapped test or development environments that do not have a connection to the external internet. Using HTTP in environments that are not air-gapped exposes you to man-in-the-middle attacks. In production environments, always use HTTPS. If you enable Content Trust with Notary to properly sign all images, you must use HTTPS.

默认情况下,Harbor不附带CA证书认证的。也就是说,Harbor 可以在没有安全性的情况下部署,以便可以快速通过HTTP连接到访问。但是,只有在没有外部互联网连接、局域网的测试或开发环境中,才适合使用HTTP。 不过,不考虑安全性,在私人使用的话也可以直接在互联网使用。当然,如果直接在互联网使用HTTP协议,就会有可能遭受中间人攻击。 所以在生产环境中,一般也是一定会去使用HTTPS。

To configure HTTPS, you must create SSL certificates. You can use certificates that are signed by a trusted third-party CA, or you can use self-signed certificates. This section describes how to useOpenSSL to create a CA, and how to use your CA to sign a server certificate and a client certificate. You can use other CA providers, for example Let’s Encrypt.

要配置HTTPS,必须创建SSL证书。您可以使用由受信任的第三方CA签名的证书,也可以使用openssl进行自签名证书。本节介绍如何使用 OpenSSL创建CA,以及如何使用CA签署服务器证书和客户端证书。您可以使用其他CA工具进行自签名,例如 Let's Encrypt

The procedures below assume that your Harbor registry’s hostname is yourdomain.com, and that its DNS record points to the host on which you are running Harbor.

以下操作过程假定您的Harbor注册表的主机名是yourdomain.com(当然,我会改为我使用的服务器 hostname),并且其DNS记录指向您在其上运行Harbor的主机(这个在hosts文件配置好就可以了)。

下面先逐步生成一下证书。

生成证书颁发机构证书 Generate a Certificate Authority Certificate

In a production environment, you should obtain a certificate from a CA. In a test or development environment, you can generate your own CA. To generate a CA certficate, run the following commands.

在生产环境中,一般是应该从CA获得证书,例如:在阿里云购买域名之后就可以下载相关域名的CA证书了。但是在测试或开发环境中,对于这种自己定义的内网域名,就可以自己生成自己的CA证书。 要生成CA证书,则运行以下命令。

1. 生成CA证书私钥 ca.key。Generate a CA certificate private key.
openssl genrsa -out ca.key 4096

生成CA证书私钥,在服务器执行如下:

2. 根据上面生成的CA证书私钥,再来生成CA证书 ca.crt。 Generate the CA certificate.

Adapt the values in the -subj option to reflect your organization. If you use an FQDN to connect your Harbor host, you must specify it as the common name (CN) attribute.

设置 -subj 选项中的值来反映的组织,例如:省份、地市、域名等等信息。如果使用FQDN 【 (Fully Qualified Domain Name)全限定域名:同时带有主机名和域名的名称。】连接Harbor主机,则必须将其指定为通用名称(CN)属性,可以看到示例写的是yourdomain.com

openssl req -x509 -new -nodes -sha512 -days 3650 \
 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com" \
 -key ca.key \
 -out ca.crt

不过看这个单纯的示例,设置-subj这块,还是不是很清晰。这里来一个百度的域名CA证书看看,就大概清楚了,如下:

# 百度CA证书的 -subj 相关参数:
CN = baidu.com
O = Beijing Baidu Netcom Science Technology Co., Ltd
OU = service operation department
L = beijing
S = beijing
C = CN

# 对比一下示例的参数
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com"

# 设置一下我的CA证书 subj 参数
-subj "/C=CN/ST=Shenzhen/L=Shenzhen/O=Harbor/OU=Harbor/CN=server01.harbor.com"

对于这个域名的配置,其实就是DNS可以找到你 Harbor 服务器IP的域名。

例如:最直观的,我本次配置Harbor服务的域名如下:

# 设置harbor服务器一个内网的使用域名,写入 hosts 文件。如果有DNS,也可以在DNS配置
[root@server01 ssl]# echo "172.16.0.4 server01.harbor.com" >> /etc/hosts
[root@server01 ssl]# 
[root@server01 ssl]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.4 instance-0sv5g3ed instance-0sv5g3ed.novalocal
...

# 设置好的harbor服务器域名
172.16.0.4 server01.harbor.com
[root@server01 ssl]# 
# ping 测试域名如下
[root@server01 ssl]# ping server01.harbor.com
PING server01.harbor.com (172.16.0.4) 56(84) bytes of data.
64 bytes from instance-0sv5g3ed (172.16.0.4): icmp_seq=1 ttl=64 time=0.053 ms
64 bytes from instance-0sv5g3ed (172.16.0.4): icmp_seq=2 ttl=64 time=0.065 ms
^C
--- server01.harbor.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.053/0.059/0.065/0.006 ms
[root@server01 ssl]# 

执行生成CA证书:

openssl req -x509 -new -nodes -sha512 -days 3650 \
 -subj "/C=CN/ST=Shenzhen/L=Shenzhen/O=Harbor/OU=Harbor/CN=server01.harbor.com" \
 -key ca.key \
 -out ca.crt

  # 根据ca.key密钥生成 ca.crt证书。

 # 参数说明:
-new 指生成证书请求
-x509 表示直接输出证书
-key 指定私钥文件
-days 指定证书过期时间为3650天
-out 导出结束后证书文件
-subj 输入证书拥有者信息

生成服务器证书 Generate a Server Certificate

上面生成了 ca 的证书,那么下面来继续生成服务器的证书。

The certificate usually contains a .crt file and a .key file, for example, yourdomain.com.crt and yourdomain.com.key.

证书通常包含一个.crt文件和一个.key文件,例如yourdomain.com.crtyourdomain.com.key。 在这里,因为我上面设置的服务器域名为server01.harbor.com,所以将要生成的证书为server01.harbor.com.crtserver01.harbor.com.key

1.生成私钥 yourdomain.com.key。 Generate a private key.
openssl genrsa -out yourdomain.com.key 4096

在Harbor服务器上执行生成私钥命令如下:

openssl genrsa -out server01.harbor.com.key 4096
2.生成证书签名请求(CSR)yourdomain.com.csr。Generate a certificate signing request (CSR).

Adapt the values in the -subj option to reflect your organization. If you use an FQDN to connect your Harbor host, you must specify it as the common name (CN) attribute and use it in the key and CSR filenames.

设置-subj选项中的值来反映组织,基本跟上面ca证书那样设置就可以了。

openssl req -sha512 -new \
    -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com" \
    -key yourdomain.com.key \
    -out yourdomain.com.csr

# 上面证书颁发机构的 subj 设置。
-subj "/C=CN/ST=Shenzhen/L=Shenzhen/O=Harbor/OU=Harbor/CN=server01.harbor.com" \

在服务器上执行如下:

openssl req -sha512 -new \
    -subj "/C=CN/ST=Shenzhen/L=Shenzhen/O=Harbor/OU=Harbor/CN=server01.harbor.com" \
    -key server01.harbor.com.key \
    -out server01.harbor.com.csr
3. 生成一个x509 v3扩展文件。Generate an x509 v3 extension file.

Regardless of whether you’re using either an FQDN or an IP address to connect to your Harbor host, you must create this file so that you can generate a certificate for your Harbor host that complies with the Subject Alternative Name (SAN) and x509 v3 extension requirements. Replace the DNS entries to reflect your domain.

无论是使用FQDN还是IP地址连接到Harbor主机,都必须创建此文件。这样的话,Harbor主机才能够生成符合主题备用名称(SAN)和x509 v3的证书扩展要求。 下面的配置中,DNS的部分需要替换为自己Harbor服务器的域名。

cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=yourdomain.com
DNS.2=yourdomain
DNS.3=hostname
EOF

替换一下DNS的内容即可,如下:

cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=server01.harbor.com
DNS.2=server01
EOF

在服务器执行如下:

4. 使用该v3.ext文件为您的Harbor主机生成证书 yourdomain.com.crt。Use the v3.ext file to generate a certificate for your Harbor host.

Replace the yourdomain.com in the CRS and CRT file names with the Harbor host name.

yourdomain.comCRS和CRT文件名中的替换为自己配置的Harbor主机名。

openssl x509 -req -sha512 -days 3650 \
    -extfile v3.ext \
    -CA ca.crt -CAkey ca.key -CAcreateserial \
    -in yourdomain.com.csr \
    -out yourdomain.com.crt

修改为我配置的Harbor域名,如下:

openssl x509 -req -sha512 -days 3650 \
    -extfile v3.ext \
    -CA ca.crt -CAkey ca.key -CAcreateserial \
    -in server01.harbor.com.csr \
    -out server01.harbor.com.crt

注意:这里要使用前面自定义颁发机构的ca证书,所以拷贝过来,然后在服务器执行如下:

提供证书给Harbor和Docker。Provide the Certificates to Harbor and Docker

After generating the ca.crt, yourdomain.com.crt, and yourdomain.com.key files, you must provide them to Harbor and to Docker, and reconfigure Harbor to use them.

生成后证书颁发机构的ca.crt以及服务器的证书yourdomain.com.crtyourdomain.com.key文件,那么就需要将它们提供到 Harbor 和 docker 进行证书配置 。

1. 将服务器证书yourdomain.com.crt和密钥yourdomain.com.key复制到Harbor主机上的certficates文件夹中。Copy the server certificate and key into the certficates folder on your Harbor host.
cp yourdomain.com.crt /data/cert/
cp yourdomain.com.key /data/cert/

拷贝上面生成的证书至指定的路径/data/cert,这里暂时不改动路径,按照官网的操作:

mkdir -p /data/cert
cp server01.harbor.com.crt /data/cert/
cp server01.harbor.com.key /data/cert/
2. 将服务器证书yourdomain.com.crt的编码格式转换为yourdomain.com.cert,提供Docker使用。 Convert yourdomain.com.crt to yourdomain.com.cert, for use by Docker.

The Docker daemon interprets .crt files as CA certificates and .cert files as client certificates.

Docker守护程序将.crt文件解释为CA证书,并将.cert文件解释为客户端证书。

openssl x509 -inform PEM -in yourdomain.com.crt -out yourdomain.com.cert

执行命令:

openssl x509 -inform PEM -in server01.harbor.com.crt -out server01.harbor.com.cert
3.将服务器证书,密钥和CA文件复制到Harbor主机上的Docker certificate文件夹中。必须首先创建docker对应的文件夹。 Copy the server certificate, key and CA files into the Docker certificates folder on the Harbor host. You must create the appropriate folders first.

其实这个对应文件夹在使用yum install docker的时候就会自动安装上,如下:

其实就是docker访问镜像仓库的客户端证书。

cp yourdomain.com.cert /etc/docker/certs.d/yourdomain.com/
cp yourdomain.com.key /etc/docker/certs.d/yourdomain.com/
cp ca.crt /etc/docker/certs.d/yourdomain.com/

将示例的域名改为我设置的harbor服务器域名地址,执行命令如下:

# 创建证书文件夹
mkdir -p /etc/docker/certs.d/server01.harbor.com
# 拷贝服务器证书
cp server01.harbor.com.cert /etc/docker/certs.d/server01.harbor.com/
# 拷贝服务器私钥
cp server01.harbor.com.key /etc/docker/certs.d/server01.harbor.com/
# 拷贝自签的颁发证书机构ca证书
cp ca.crt /etc/docker/certs.d/server01.harbor.com/

执行如下:

If you mapped the default nginx port 443 to a different port, create the folder /etc/docker/certs.d/yourdomain.com:port, or /etc/docker/certs.d/harbor_IP:port.

如果将默认nginx端口443 映射到其他端口 port,请创建文件夹/etc/docker/certs.d/yourdomain.com:port/etc/docker/certs.d/harbor_IP:port。 也就是证书也要加上对应修改的端口号,不然无法生效。这个坑还是挺隐藏的。

4.重新启动Docker Engine。 Restart Docker Engine.
systemctl restart docker

You might also need to trust the certificate at the OS level. See Troubleshooting Harbor Installationfor more information.

The following example illustrates a configuration that uses custom certificates.

您可能还需要在操作系统级别信任证书。有关更多信息,请参见 对Harbour安装进行故障排除。 以下示例说明了使用自定义证书的配置。

# 示例
/etc/docker/certs.d/
    └── yourdomain.com:port
       ├── yourdomain.com.cert  <-- Server certificate signed by CA
       ├── yourdomain.com.key   <-- Server key signed by CA
       └── ca.crt               <-- Certificate authority that signed the registry certificate

部署或重新配置Harbor。 Deploy or Reconfigure Harbor

If you have not yet deployed Harbor, see Configure the Harbor YML File for information about how to configure Harbor to use the certificates by specifying the hostname and https attributes in harbor.yml.

如果尚未部署Harbor,请参阅 配置Harbor YML文件,以获取有关如何通过在中指定hostnamehttps属性来配置Harbor使用证书的信息harbor.yml。 当然,我现在也才刚配置好CA证书,下面来看看harbor.yml如何配置。

参阅一下Harbor YML 文件的配置参数,访问:https://goharbor.io/docs/1.10/install-config/configure-yml-file/

那么首先配置一下Harbor 的 YML文件先。

1. 配置一下Harbor 的 YML文件

首先回到Harbor安装包的解压路径,如下:

1.1 配置hostname
1.2 配置CA证书路径

好了,先配置这两项吧,其他保持默认先。

注意:这是harbor自带的nginx服务。

1.3 配置完毕,则执行安装目录下的install.sh安装脚本进行安装

https://goharbor.io/docs/1.10/install-config/run-installer-script/

这里面提到有多种安装的方式,我在这里就采用默认的安装方式吧。不搞那么多先。

默认安装Harbor,不安装Notary,Clair,Chart Repostiory 服务。Default installation without Notary, Clair, or Chart Repository Service

The default Harbor installation does not include Notary or Clair service. Run the following command

默认的Harbor安装不包括Notary或Clair服务。运行以下命令

sudo ./install.sh

在服务器执行如下:

安装成功之后,显示运行着的容器如下:

1.4 安装成功之后,测试访问Harbor服务

If the installation succeeds, you can open a browser to visit the Harbor interface at http://reg.yourdomain.com, changing reg.yourdomain.com to the hostname that you configured in harbor.yml. If you did not change them in harbor.yml, the default administrator username and password are admin and Harbor12345.

如果安装成功,则可以打开浏览器以访问Harbor界面http://reg.yourdomain.com,将其更改reg.yourdomain.com为在中配置的主机名harbor.yml。 如果未更改harbor.yml中的管理员用户名和密码,则默认的管理员用户名和密码为adminHarbor12345

使用浏览器访问看看,我设置的域名为:https://server01.harbor.com

这里可以看到已经能够使用浏览器访问harbor的https服务了。下面来看看使用docker登陆。

Log in to the admin portal and create a new project, for example, myproject. You can then use Docker commands to log in to Harbor, tag images, and push them to Harbor.

登录到管理门户并创建一个新项目,例如myproject。然后,您可以使用Docker命令登录到Harbor,标记图像并将其推送到Harbor。

docker login reg.yourdomain.com
docker push reg.yourdomain.com/myproject/myrepo:mytag

使用默认的管理员用户名以及密码登陆Harbor:

可以看到登陆成功了,下面来尝试push一个镜像上去。

不过,在push镜像之间,首先要在web管理端创建一个项目,提供镜像存放,如下:

# 从docker hub下载centos镜像
[root@server01 harbor]# docker pull centos

# 给centos镜像打tag标签:harbor服务域名/对应的项目/镜像名称:版本号tag
[root@server01 harbor]# docker tag centos:latest server01.harbor.com/library/centos:latest

# 将镜像推送至harbor仓库
[root@server01 harbor]# docker push server01.harbor.com/library/centos:latest
The push refers to repository [server01.harbor.com/library/centos]
0683de282177: Pushed 
latest: digest: sha256:9e0c275e0bcb495773b10a18e499985d782810e47b4fce076422acb4bc3da3dd size: 529
[root@server01 harbor]# 

在web端可以查看已经push上去的镜像信息,如下:

2.运行prepare脚本以启用HTTPS。Run the prepare script to enable HTTPS.

Harbor uses an nginx instance as a reverse proxy for all services. You use the prepare script to configure nginx to use HTTPS. The prepare is in the Harbor installer bundle, at the same level as the install.sh script.

Harbor使用nginx作所有服务的反向代理。可以使用prepare脚本来配置nginx为使用HTTPS。该prepare在Harbor的安装包中。 因为我前面是直接配置好CA证书,所以刚才执行 install.sh 安装之后,使用浏览器直接就访问了 https 的Harbor服务。下面再来执行多一下这个prepare看看有什么效果。

# 其实这个prepare的作用是用来初始化将harbor.yml转化为docker-compose.yml文件
./prepare

在服务器执行如下:

从打印的信息来看,大概就是将这个目录作为根目录,设置相关的配置。

3.如果Harbor正在运行,执行以下命令,可以停止并删除现有实例。 If Harbor is running, stop and remove the existing instance.

Your image data remains in the file system, so no data is lost.

数据保留在文件系统中,因此不会丢失任何数据。

docker-compose down -v

在服务器执行如下:

4.启动Harbor服务。Restart Harbor:
docker-compose up -d

执行如下:

基本上到了这里,单机版本的Harbor已经可以使用了。

当然还有很多的配置,例如:高可用部署、重新配置Harbor生命周期、自定义Harbor token服务等等,可以继续查询官网的文档配置。

更多的官网配置

高可用部署:https://goharbor.io/docs/1.10/install-config/harbor-ha-helm/

重新配置Harbor生命周期:https://goharbor.io/docs/1.10/install-config/reconfigure-manage-lifecycle/

自定义Harbor token服务:https://goharbor.io/docs/1.10/install-config/customize-token-service/

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 需求
  • Harbor介绍
  • Harbor相关地址
  • 安装Harbor
    • 环境要求
      • 安装 docker-ce
        • 卸载旧版本
        • 使用 docker hub 仓库安装:
      • 安装 docker-compose
        • 下载Harbor安装包
          • 解压Harbor安装包
          • 配置对Harbor的HTTPS访问
            • 生成证书颁发机构证书 Generate a Certificate Authority Certificate
              • 1. 生成CA证书私钥 ca.key。Generate a CA certificate private key.
              • 2. 根据上面生成的CA证书私钥,再来生成CA证书 ca.crt。 Generate the CA certificate.
            • 生成服务器证书 Generate a Server Certificate
              • 1.生成私钥 yourdomain.com.key。 Generate a private key.
              • 2.生成证书签名请求(CSR)yourdomain.com.csr。Generate a certificate signing request (CSR).
              • 3. 生成一个x509 v3扩展文件。Generate an x509 v3 extension file.
              • 4. 使用该v3.ext文件为您的Harbor主机生成证书 yourdomain.com.crt。Use the v3.ext file to generate a certificate for your Harbor host.
            • 提供证书给Harbor和Docker。Provide the Certificates to Harbor and Docker
              • 1. 将服务器证书yourdomain.com.crt和密钥yourdomain.com.key复制到Harbor主机上的certficates文件夹中。Copy the server certificate and key into the certficates folder on your Harbor host.
              • 2. 将服务器证书yourdomain.com.crt的编码格式转换为yourdomain.com.cert,提供Docker使用。 Convert yourdomain.com.crt to yourdomain.com.cert, for use by Docker.
              • 3.将服务器证书,密钥和CA文件复制到Harbor主机上的Docker certificate文件夹中。必须首先创建docker对应的文件夹。 Copy the server certificate, key and CA files into the Docker certificates folder on the Harbor host. You must create the appropriate folders first.
              • 4.重新启动Docker Engine。 Restart Docker Engine.
              • 1. 配置一下Harbor 的 YML文件
              • 2.运行prepare脚本以启用HTTPS。Run the prepare script to enable HTTPS.
              • 3.如果Harbor正在运行,执行以下命令,可以停止并删除现有实例。 If Harbor is running, stop and remove the existing instance.
              • 4.启动Harbor服务。Restart Harbor:
          • 部署或重新配置Harbor。 Deploy or Reconfigure Harbor
          • 更多的官网配置
          相关产品与服务
          容器服务
          腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档