Harbor私有仓库搭建

摘要

SoftwareVersion
Docker engine20.10.21
Docker Compose1.29.2
Openssl3.0.2
Harbor2.8.0

下载页面

1
wget https://storage.googleapis.com/harbor-releases/release-2.8.0/harbor-offline-installer-v2.8.0.tgz

解压

1
tar xvf harbor-offline-installer-v2.8.0.tgz
1
2
cd harbor/
vi harbor.yml

修改

1
hostname = 192.168.0.2

这里只是简单的测试,所以只编辑这一行,其他的默认不做修改;可根据实际情况做修改!

配置 trivy 使用离线漏洞数据库

1
2
3
trivy:
  skip_update: true
  offline_scan: true

后续修改配置都要重新生成配置文件

1
./prepare

因为docker默认使用的是https连接,而harbor默认使用http连接,所以需要修改docker配置标志insecure registry不安全仓库的主机。当然,harbor也可以设置为https

添加私有仓库地址

1
2
3
4
5
cat << EOF >>/etc/docker/daemon.json
{
    "insecure-registries": ["192.168.1.10"]
}
EOF

重启docker

1
2
systemctl daemon-reload
systemctl restart docker.service
1
./instsall.sh

安装带有Notary服务--with-notary

安装带有trivy服务--with-trivy

安装带有chart仓库服务--with-chartmuseum

其中Clair服务--with-clair已弃用

安装Notary

要安装带有Notary服务的Harbor,请在运行时添加一个参数 install.sh:

1
./install.sh --with-notary

对于安装 Notary 这个参数 ui_url_protocol必须设置为 “https”. 要配置HTTPS,请参考以下部分.

更多关于Notary和Docker内容信任的信息,请参考 Docker’s documentation.

安装带有 Trivy 服务,添加参数当运行 install.sh:

1
./install.sh --with-trivy

使用 chart 仓库

安装带有chart仓库服务的Harbor, 添加参数当你运行install.sh:

1
./install.sh --with-chartmuseum

如果你都想安装 Notary, Trivy and chart repository service ,你必须同时指定

1
./install.sh --with-notary --with-trivy --with-chartmuseum

会拉取好几个镜像下来,及检查环境:

https://img.bwcxtech.com/img/20200928154340.png

1
2
3
4
✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at https://harbor.qmerry.com. 
For more details, please visit https://github.com/vmware/harbor .

到这里基本就安装成功了!

安装完成后会生成如下6个容器:

1
docker ps

https://img.bwcxtech.com/img/20200928154243.png

6、验证

打开浏览器访问:http://192.168.1.10

https://img.bwcxtech.com/img/20200928154238.png

登录私有仓库

1
2
3
4
5
docker login 192.168.1.10
Username: admin
Password:	#(默认密码为:Harbor12345,可在harbor.yml文件中修改)

Login Succeeded
1
2
cd harbor
docker-compose down -v
1
2
cd ..
mv harbor harbor_bak
1
2
wget https://github.com/goharbor/harbor/releases/download/v2.8.1/harbor-offline-installer-v2.8.1.tgz
tar xf harbor-offline-installer-v2.8.1.tgz
1
2
3
4
cd harbor
cp harbor.yml.tmpl harbor.yml
vi harbor.yml
./prepare # 更新配置文件

Harbor v2.1 及之前的版本内置了 Clair 镜像扫描器,在 v2.2 中,Harbor使用了 Aqua Trivy 作为缺省扫描器。Clair 作为可选组件,仍然可以安装使用。

安装带有Notary服务--with-notary

安装带有trivy服务--with-trivy

安装带有chart仓库服务--with-chartmuseum

其中Clair服务--with-clair已弃用

1
./install.sh --with-trivy

下载 oras

1
2
3
4
wget https://github.com/oras-project/oras/releases/download/v1.1.0/oras_1.1.0_linux_amd64.tar.gz
tar -xf oras_1.1.0_linux_amd64.tar.gz
mv oras /usr/local/bin/
chmod +x /usr/local/bin/oras 

进入 trivy 目录

1
cd /data/{harbor_data}/trivy-adapter/trivy/

下载 trivy-db 离线库

1
oras pull ghcr.dockerproxy.com/aquasecurity/trivy-db:2

下载 trivy-java-db 离线库

1
oras pull ghcr.dockerproxy.com/aquasecurity/trivy-java-db:1

{harbor_data}替换为你的 harbor 数据目录

解压离线库

1
2
3
4
tar -xf db.tar.gz -C db
tar -xf javadb.tar.gz -C java-db
rm -f db.tar.gz javadb.tar.gz
chown -R 10000:10000 db java-db

相关内容