私有的docker私有镜像站仓库harbor

▶ 需要准备的文件

harbor 方便在企业内部实现私有的容器镜像仓库,方便镜像的分发。

  • 需要准备3个文件
    • docker compose 文件
    • harbor 文件
    • TLS 证书文件

docker hub 在部署当中需要 docker compose 来做容器的编排部署。

部署 harbor 有两种模式,一种是在线模式,一种是离线模式,在线模式由于受到网络环境的影响部署的时间会比较长,网络就会不稳定就会导致无法正常使用,所以一般也就推荐使用离线部署的模式,离线部署就需要用到离线的包。

在访问 harbor 的过程中,http 与 https 这两种协议都可以使用,为了安全性就要使用 SSL 证书,在 harbor 的配置文件当中都会有所涉及。

▷ 获取 docker compose 文件

对于安装 docker compose 文件的时候,CPU 建议配置到2核,内存是4G以上为满足harbor后面的增长需求。

这里我使用的 docker compose 的下载地址:

https://objects.githubusercontent.com/github-production-release-asset-2e65be/15045751/56e530c4-050d-4fb2-a8ab-b9451171b912?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241010%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241010T150425Z&X-Amz-Expires=300&X-Amz-Signature=e5fb58d7f455d5e24eb2b35b9b3d92fb667c57e0282021b25a1a994fbe0daee8&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Ddocker-compose-linux-x86_64&response-content-type=application%2Foctet-stream
[root@server bin]# pwd
/root/bin

[root@server bin]# mv docker-compose-linux-x86_64 docker-compose

[root@server bin]# chmod +x docker-compose

[root@server bin]# docker-compose version
Docker Compose version v2.29.6

▷ 获取 harbor 文件

[root@server bin]# cd /home

[root@server home]# wget https://github.com/goharbor/harbor/releases/download/v2.11.1/harbor-offline-installer-v2.11.1.tgz  
--snip--
2024-10-10 23:30:00 (1.91 MB/s) - ‘harbor-offline-installer-v2.11.1.tgz’ saved [658192407/658192407]

[root@server home]# ll
total 642768
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz

▷ 准备证书文件-获取TLS文件

https://www.toolhelper.cn/SSL/SSLGenerate 用于自己实验使用的证书生成网站。

这里准备的文件是 harbor-offline-installer-v2.11.1.tgz 这个文件。

此时在 /home 目录中则就有 harbor 的文件 和 证书文件 这两个文件。

[root@server home]# ll
total 642780
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz
-rw-r--r--. 1 root root      5253 Oct 10 23:50 ssl_generate.zip

▶ 解压与配置文件


▷ 解压和配置准备

解压上面的两个文件

[root@server home]# tar -xzvf harbor-offline-installer-v2.11.1.tgz
harbor/harbor.v2.11.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl

[root@server home]# unzip ssl_generate.zip
Archive:  ssl_generate.zip
  inflating: generate.pfx
  inflating: cert.pem
  inflating: private.key

此时就有:

[root@server home]# ll
total 642788
-rw-r--r--. 1 root root      1263 Oct 10 23:36 cert.pem
-rw-r--r--. 1 root root      2620 Oct 10 23:36 generate.pfx
drwxr-xr-x. 2 root root       123 Oct 11 12:20 harbor
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz
-rw-r--r--. 1 root root      1714 Oct 10 23:36 private.key
-rw-r--r--. 1 root root      5253 Oct 10 23:50 ssl_generate.zip

此时将认证文件放在 harbor 目录下:

[root@server home]# ll
total 642788
-rw-r--r--. 1 root root      1263 Oct 10 23:36 cert.pem
-rw-r--r--. 1 root root      2620 Oct 10 23:36 generate.pfx
drwxr-xr-x. 2 root root       123 Oct 11 12:20 harbor
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz
drwx------. 2 hp   hp          83 Aug 15 09:34 hp
-rw-r--r--. 1 root root      1714 Oct 10 23:36 private.key
-rw-r--r--. 1 root root      5253 Oct 10 23:50 ssl_generate.zip

[root@server home]# mv cert.pem generate.pfx private.key harbor 

进入 harbor 目录后,找到 harbor 的配置文件,这个配置文件是 harbor.yml.tmpl 用于生效的 harbor 的配置文件是 harbor.yml

使用 cp 既保存了先前的 harbor.yml.tmpl 也有了配置文件 harbor.yml

[root@server home]# cd harbor/
[root@server harbor]# cp harbor.yml.tmpl harbor.yml

▷ 配置

[root@server harbor]# vim harbor.yml
--snip--
  3 # The IP address or hostname to access admin UI and registry service.
  4 # DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
  5 hostname: reg.mydomain.com

  ==> 修改第5行
  5 hostname: www.harborexample.com

hostname:修改成域名或者是 IP 地址,这里我使用的是 www.harborexample.com 域名。


 16   # The path of cert and key files for nginx
 17   certificate: /your/certificate/path
 18   private_key: /your/private/key/path

 ==> 修改第 17-18 行
 17   certificate: /home/harbor/cert.pem
 18   private_key: /home/harbor/private.key

后面的 47 行默认配置了 harbor 的 admin 用户登陆的密码是 Harbor12345datebase 的数据密码是 root123

47 harbor_admin_password: Harbor12345
 48
 49 # Harbor DB configuration
 50 database:
 51   # The password for the root user of Harbor DB. Change this before any production use.
 52   password: root123

▶ 执行与预备安装脚本

执行预备脚本:

[root@server harbor]# ./prepare
prepare base dir is set to /home/harbor
Unable to find image 'goharbor/prepare:v2.11.1' locally
v2.11.1: Pulling from goharbor/prepare
21fde6fe7256: Pull complete
e7d411dc7b71: Pull complete
956686c6154d: Pull complete
ccc241b37d9f: Pull complete
--snip--

这会拉取镜像文件。


执行安装脚本

[root@server harbor]# ./install.sh

[Step 0]: checking if docker is installed ...
--sni--
[+] Running 10/10
 ✔ Network harbor_harbor        Created                                                                              0.2s
 ✔ Container harbor-log         Started                                                                              0.5s
 ✔ Container harbor-portal      Started                                                                              1.8s
 ✔ Container registry           Started                                                                              1.9s
 ✔ Container redis              Started                                                                              1.4s
 ✔ Container harbor-db          Started                                                                              1.9s
 ✔ Container registryctl        Started                                                                              1.8s
 ✔ Container harbor-core        Started                                                                              2.2s
 ✔ Container nginx              Started                                                                              3.4s
 ✔ Container harbor-jobservice  Started                                                                              2.9s
✔ ----Harbor has been installed and started successfully.----

这样 harbor 的配置与安装就算简单的完成了。


用户名是 admin, 密码是 Harbor12345


▶ 验证运行情况

[root@server harbor]# docker ps
CONTAINER ID   IMAGE                                 COMMAND                  CREATED         STATUS                   PORTS                                                                                NAMES
e5b90d66a877   goharbor/harbor-jobservice:v2.11.1    "/harbor/entrypoint.…"   6 minutes ago   Up 6 minutes (healthy)                                                                                        harbor-jobservice
6f3cae3fd8fa   goharbor/nginx-photon:v2.11.1         "nginx -g 'daemon of…"   6 minutes ago   Up 6 minutes (healthy)   0.0.0.0:80->8080/tcp, [::]:80->8080/tcp, 0.0.0.0:443->8443/tcp, [::]:443->8443/tcp   nginx
24b256df6c94   goharbor/harbor-core:v2.11.1          "/harbor/entrypoint.…"   6 minutes ago   Up 6 minutes (healthy)                                                                                        harbor-core
7882833acb96   goharbor/harbor-db:v2.11.1            "/docker-entrypoint.…"   6 minutes ago   Up 6 minutes (healthy)                                                                                        harbor-db
743eb9f226e6   goharbor/redis-photon:v2.11.1         "redis-server /etc/r…"   6 minutes ago   Up 6 minutes (healthy)                                                                                        redis
d3045620b287   goharbor/registry-photon:v2.11.1      "/home/harbor/entryp…"   6 minutes ago   Up 6 minutes (healthy)                                                                                        registry
27a4de039809   goharbor/harbor-registryctl:v2.11.1   "/home/harbor/start.…"   6 minutes ago   Up 6 minutes (healthy)                                                                                        registryctl
426620cf7a97   goharbor/harbor-portal:v2.11.1        "nginx -g 'daemon of…"   6 minutes ago   Up 6 minutes (healthy)                                                                                        harbor-portal
605cae889833   goharbor/harbor-log:v2.11.1           "/bin/sh -c /usr/loc…"   6 minutes ago   Up 6 minutes (healthy)   127.0.0.1:1514->10514/tcp                                                            harbor-log

harbor 的运行依赖于9个容器!

posted @ 2024-10-09 23:10  takenika  阅读(127)  评论(0)    收藏  举报