harbor安装

下载地址: https:///goharbor/harbor/releases

## 下载 
wget https:///goharbor/harbor/releases/download/v2.9.4/harbor-offline-installer-v2.9.4.tgz

## 解压
解压
tar xf harbor-offline-installer-v2.9.4.tgz

## 编辑配置文件
cp harbor.yml.tmpl harbor.yml

  5 hostname: 172.19.10.1
  6
  7 # http related config
  8 http:
  9   # port for http, default is 80. If https enabled, this port will redirect to https port
 10   port: 80
 11
 12 # https related config
 13 #https:
 14 #  # https port for harbor, default is 443
 15 #  port: 443
 16 #  # The path of cert and key files for nginx
 17 #  certificate: /your/certificate/path
 18 #  private_key: /your/private/key/path

35 # Remember Change the admin password from UI after launching Harbor.
 36 harbor_admin_password: 123.com
 37
 38 # Harbor DB configuration
 39 database:

Harbor搭建Docker私有仓库_docker


执行安装脚本

[root@test-ops harbor]# ./

[Step 0]: checking if docker is installed ...

Note: docker version: 26.0.0

[Step 1]: checking docker-compose is installed ...

Note: Docker Compose version v2.25.0

[Step 2]: loading Harbor images ...
2a1ecf1a5624: Loading layer [==================================================>]  40.28MB/40.28MB
1ffa30c514e7: Loading layer [==================================================>]  115.6MB/115.6MB
Loaded image: goharbor/nginx-photon:v2.9.4
fe9d27457645: Loading layer [==================================================>]  9.117MB/9.117MB
8a1bd330387a: Loading layer [==================================================>]  4.096kB/4.096kB
de5aec39cfef: Loading layer [==================================================>]  3.072kB/3.072kB
b2dc5f9b0adc: Loading layer [==================================================>]  209.9MB/209.9MB
867f6775e77c: Loading layer [==================================================>]  17.45MB/17.45MB
3d23e7d1c061: Loading layer [==================================================>]  228.1MB/228.1MB
Loaded image: goharbor/trivy-adapter-photon:v2.9.4
8e8d9c5fab4c: Loading layer [==================================================>]  115.6MB/115.6MB
8c2100da7b2f: Loading layer [==================================================>]   6.46MB/6.46MB
beb75a4af778: Loading layer [==================================================>]  245.8kB/245.8kB
8b93536ed20c: Loading layer [==================================================>]  1.233MB/1.233MB
Loaded image: goharbor/harbor-portal:v2.9.4
303f42b51cc2: Loading layer [==================================================>]  11.61MB/11.61MB
f6d69dd1d0ad: Loading layer [==================================================>]  3.584kB/3.584kB
8dbc774dc94d: Loading layer [==================================================>]   2.56kB/2.56kB
baba5716726a: Loading layer [==================================================>]  58.75MB/58.75MB
5b67417f435d: Loading layer [==================================================>]  5.632kB/5.632kB
31a7f7742aaa: Loading layer [==================================================>]  122.4kB/122.4kB
a9bc112e775d: Loading layer [==================================================>]  80.38kB/80.38kB
3c10f76aad84: Loading layer [==================================================>]  59.74MB/59.74MB
6c5eb2684647: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.9.4
807b050bbb83: Loading layer [==================================================>]  125.3MB/125.3MB
00b81cc4331d: Loading layer [==================================================>]  3.584kB/3.584kB
73d4601a8fa0: Loading layer [==================================================>]  3.072kB/3.072kB
873b556fed34: Loading layer [==================================================>]   2.56kB/2.56kB
d34eaff1dda9: Loading layer [==================================================>]  3.072kB/3.072kB
875416323a99: Loading layer [==================================================>]  3.584kB/3.584kB
04668820172e: Loading layer [==================================================>]  20.48kB/20.48kB
Loaded image: goharbor/harbor-log:v2.9.4
fc9708739fba: Loading layer [==================================================>]  11.61MB/11.61MB
5fbf23947d53: Loading layer [==================================================>]  3.584kB/3.584kB
8980553d20e3: Loading layer [==================================================>]   2.56kB/2.56kB
394a06e3fead: Loading layer [==================================================>]  44.64MB/44.64MB
0b32832b0417: Loading layer [==================================================>]  45.43MB/45.43MB
Loaded image: goharbor/harbor-jobservice:v2.9.4
649c2fb761b1: Loading layer [==================================================>]  11.61MB/11.61MB
dee3ec490421: Loading layer [==================================================>]  27.58MB/27.58MB
ce1ae31f2333: Loading layer [==================================================>]  4.608kB/4.608kB
67b43b0afe41: Loading layer [==================================================>]  28.37MB/28.37MB
Loaded image: goharbor/harbor-exporter:v2.9.4
7410b8d05205: Loading layer [==================================================>]  106.8MB/106.8MB
6d047e1bd50c: Loading layer [==================================================>]  47.71MB/47.71MB
c87b036184e3: Loading layer [==================================================>]  13.59MB/13.59MB
3a5d244d03b3: Loading layer [==================================================>]  65.54kB/65.54kB
879613b8145c: Loading layer [==================================================>]   2.56kB/2.56kB
d2cd9b4bcddc: Loading layer [==================================================>]  1.536kB/1.536kB
cba7f0d728dd: Loading layer [==================================================>]  12.29kB/12.29kB
3254d17aca93: Loading layer [==================================================>]  2.741MB/2.741MB
ec67e6c79557: Loading layer [==================================================>]  429.6kB/429.6kB
Loaded image: goharbor/prepare:v2.9.4
9680f9b537e4: Loading layer [==================================================>]  16.08MB/16.08MB
5c80f459c1fa: Loading layer [==================================================>]  173.8MB/173.8MB
b4a8872dec5a: Loading layer [==================================================>]  25.53MB/25.53MB
273925008692: Loading layer [==================================================>]   18.3MB/18.3MB
61756a3742aa: Loading layer [==================================================>]   5.12kB/5.12kB
6aef2ba5f411: Loading layer [==================================================>]  6.144kB/6.144kB
06b8309f6264: Loading layer [==================================================>]  3.072kB/3.072kB
2378215d8cc7: Loading layer [==================================================>]  2.048kB/2.048kB
61639698f424: Loading layer [==================================================>]   2.56kB/2.56kB
11138989c354: Loading layer [==================================================>]   7.68kB/7.68kB
Loaded image: goharbor/harbor-db:v2.9.4
5476b1e98825: Loading layer [==================================================>]  8.603MB/8.603MB
21306bf47b19: Loading layer [==================================================>]  4.096kB/4.096kB
b6a29409bcb0: Loading layer [==================================================>]  17.39MB/17.39MB
f923c3b9c6b2: Loading layer [==================================================>]  3.072kB/3.072kB
b65b25d422a3: Loading layer [==================================================>]  32.69MB/32.69MB
f33443527772: Loading layer [==================================================>]  50.88MB/50.88MB
Loaded image: goharbor/harbor-registryctl:v2.9.4
297dfef001b5: Loading layer [==================================================>]  16.08MB/16.08MB
628e609117e3: Loading layer [==================================================>]  110.6MB/110.6MB
d3164a9024b3: Loading layer [==================================================>]  3.072kB/3.072kB
3bbb99540044: Loading layer [==================================================>]   59.9kB/59.9kB
0b8ee78ceda9: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.9.4
a4efec05118e: Loading layer [==================================================>]  8.603MB/8.603MB
fc5a28753b96: Loading layer [==================================================>]  4.096kB/4.096kB
e7ebcb1d0d37: Loading layer [==================================================>]  3.072kB/3.072kB
f5a739f25b3b: Loading layer [==================================================>]  17.39MB/17.39MB
3bdc4fd383a7: Loading layer [==================================================>]  18.19MB/18.19MB
Loaded image: goharbor/registry-photon:v2.9.4


[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /data/setup/harbor/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir


Note: stopping existing Harbor instance ...
WARN[0000] /data/setup/harbor/harbor/docker-compose.yml: `version` is obsolete


[Step 5]: starting Harbor ...
WARN[0000] /data/setup/harbor/harbor/docker-compose.yml: `version` is obsolete
[+] Running 9/10
 ⠙ Network harbor_harbor        Created                                                                                                                 1.1s
 ✔ Container harbor-log         Started                                                                                                                 0.3s
 ✔ Container harbor-portal      Started                                                                                                                 0.6s
 ✔ Container redis              Started                                                                                                                 0.6s
 ✔ Container harbor-db          Started                                                                                                                 0.5s
 ✔ Container registryctl        Started                                                                                                                 0.6s
 ✔ Container registry           Started                                                                                                                 0.4s
 ✔ Container harbor-core        Started                                                                                                                 0.7s
 ✔ Container harbor-jobservice  Started                                                                                                                 0.9s
 ✔ Container nginx              Started                                                                                                                 1.0s
✔ ----Harbor has been installed and started successfully.----


问题

docker登录harbor私有仓库提示必须使用https

docker login http://172.19.10.6
Username: admin
Password:
Error response from daemon: Get "https://172.19.10.6/v2/": dial tcp 172.19.10.6:443: connect: connection refused

解决办法:

1、停止当前harbor服务: docker-compose down -v

2、查找docker.service所在位置: /usr/lib/systemd/system/docker.service

3、添加 --insecure-registry=172.19.10.6配置

 cat /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry=172.19.10.6 
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Older systemd versions default to a LimitNOFILE of 1024:1024, which is insufficient for many
# applications including dockerd itself and will be inherited. Raise the hard limit, while
# preserving the soft limit for select(2).
LimitNOFILE=1024:524288

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target
# 更新配置 重启docker
systemctl daemon-reload
systemctl restart docker

4、重启harbor: docker-compose up -d

5、查看docker服务有没有加载--insecure-registry=172.19.10.6参数

Harbor搭建Docker私有仓库_docker_02

6、登录测试

docker login 172.19.10.6
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

新版本harbor启动成功但登录一直提示“核心服务不可用”

解决方法:

1、确认harbor.yml配置项账号密码是否正确

2、当前版本docker版本是否太低,如果当前docker版本较低harbor启动后不会有日志输出多次重启等异常现象