harbor仓库部署
环境需求:需要在一台已经下载了docker服务的主机上运行。
下载插件
要下载并安装撰写 CLI 插件,请运行:
[root@localhost ~]# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
[root@localhost ~]# mkdir -p $DOCKER_CONFIG/cli-plugins
[root@localhost ~]# ls -a
. .bash_logout .config .tcshrc bao
.. .bash_profile .cshrc .viminfo html
.bash_history .bashrc .docker anaconda-ks.cfg
[root@localhost ~]# ls .docker/
cli-plugins config.json
[root@localhost ~]# curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
配置插件命令
[root@localhost ~]# cd .docker/cli-plugins/
[root@localhost cli-plugins]# ls
docker-compose
[root@localhost cli-plugins]# pwd
/root/.docker/cli-plugins
[root@localhost cli-plugins]# chmod +x docker-compose
[root@localhost cli-plugins]# ll docker-compose
-rwxr-xr-x. 1 root root 25792512 Aug 11 08:48 docker-compose
[root@localhost cli-plugins]# ls
docker-compose
[root@localhost cli-plugins]# ln -s /root/.docker/cli-plugins/docker-compose /usr/bin/
[root@localhost cli-plugins]# cd
[root@localhost ~]# which docker-compose
/usr/bin/docker-compose
[root@localhost ~]# docker-compose version
Docker Compose version v2.7.0
修改配置文件
把那个包上传一下
[root@localhost ~]# ls
anaconda-ks.cfg bao html
[root@localhost ~]# ls
anaconda-ks.cfg bao harbor-offline-installer-v2.5.3.tgz html
[root@localhost ~]# tar xf harbor-offline-installer-v2.5.3.tgz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin etc games harbor include lib lib64 libexec sbin share src
[root@localhost local]# cd harbor/
[root@localhost harbor]# ls
LICENSE harbor.v2.5.3.tar.gz install.sh
common.sh harbor.yml.tmpl prepare
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# vim harbor.yml
#注释掉这些
# https related config
#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
harbor_admin_password: Harbor12345 #这一行是用户名和密码。
#然后修改主机名
[root@localhost harbor]# hostnamectl set-hostname harbor.mydomain.com
[root@localhost harbor]# bash
[root@harbor harbor]#
运行脚本
[root@harbor harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 20.10.17
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 2.7.0
[Step 2]: loading Harbor images ...
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? #这里报了docker服务不在运行中
#这里启动一下服务就可以了
[root@harbor harbor]# systemctl start docker
[root@harbor harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 20.10.17
[Step 1]: checking docker-compose is installed ...
[Step 5]: starting Harbor ...
[+] Running 10/10
⠿ Network harbor_harbor Created 0.3s
⠿ Container harbor-log Started 0.8s
⠿ Container registryctl Started 3.0s
⠿ Container harbor-portal Starte... 2.9s
⠿ Container redis Started 2.8s
⠿ Container registry Started 2.8s
⠿ Container harbor-db Started 2.9s
⠿ Container harbor-core Started 3.4s
⠿ Container harbor-jobservice St... 4.1s
⠿ Container nginx Started 4.1s
✔ ----Harbor has been installed and started successfully.----
[root@harbor harbor]#
#运行脚本后查看端口有没有起来
[root@harbor harbor]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:1514 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
[root@harbor harbor]#
测试一下
设置开机自启
[root@harbor ~]# vim /etc/rc.local
#!/bin/bash
cd /usr/local/harbor #添加这一行
docker-compose start #添加这一行
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#查看是否有执行权限,没有的话就加上去
[root@harbor ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Jan 27 2022 /etc/rc.local -> rc.d/rc.local
[root@harbor ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 516 Aug 11 09:09 /etc/rc.d/rc.local
[root@harbor ~]# chmod +x /etc/rc.d/rc.local
[root@harbor ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 516 Aug 11 09:09 /etc/rc.d/rc.local
[root@harbor ~]#
重启测试一下
[root@harbor ~]# reboot
连接断开
连接成功
Last login: Thu Aug 11 08:30:54 2022 from 192.168.171.1
[root@harbor ~]#
[root@harbor ~]#
[root@harbor ~]#
[root@harbor ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:1514 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 [::]:80 [::]:*
[root@harbor ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4fc3d139d90 goharbor/harbor-jobservice:v2.5.3 "/harbor/entrypoint.…" 14 minutes ago Up 22 seconds (health: starting) harbor-jobservice
c248e8c7c84e goharbor/nginx-photon:v2.5.3 "nginx -g 'daemon of…" 14 minutes ago Up 22 seconds (health: starting) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx
931341d73343 goharbor/harbor-core:v2.5.3 "/harbor/entrypoint.…" 14 minutes ago Up 23 seconds (health: starting) harbor-core
f8c9f5ff08f6 goharbor/redis-photon:v2.5.3 "redis-server /etc/r…" 14 minutes ago Up 23 seconds (health: starting) redis
1ff377f8a392 goharbor/harbor-portal:v2.5.3 "nginx -g 'daemon of…" 14 minutes ago Up 24 seconds (health: starting) harbor-portal
08d185acbc4b goharbor/harbor-db:v2.5.3 "/docker-entrypoint.…" 14 minutes ago Up 24 seconds (health: starting) harbor-db
5eea9bf0c6a8 goharbor/registry-photon:v2.5.3 "/home/harbor/entryp…" 14 minutes ago Up 23 seconds (health: starting) registry
7927c8147b3a goharbor/harbor-registryctl:v2.5.3 "/home/harbor/start.…" 14 minutes ago Up 23 seconds (health: starting) registryctl
faa7264f1114 goharbor/harbor-log:v2.5.3 "/bin/sh -c /usr/loc…" 14 minutes ago Up 25 seconds (health: starting) 127.0.0.1:1514->10514/tcp harbor-log
[root@harbor ~]#
使用harbor
先让harbor服务器各个端口都起来
[root@harbor ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:1514 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
[root@harbor ~]#
然后配置客户端
#要想要在harbor网站上面能够上传服务端的镜像,首先要ping的通服务端
[root@localhost ~]# vim /etc/hosts
进入配置文件,给服务端做映射
192.168.171.133 harbor.mydomain.com #添加这一行
[root@localhost ~]# ping 192.168.171.133
PING 192.168.171.133 (192.168.171.133) 56(84) bytes of data.
64 bytes from 192.168.171.133: icmp_seq=1 ttl=64 time=0.515 ms
64 bytes from 192.168.171.133: icmp_seq=2 ttl=64 time=0.525 ms
64 bytes from 192.168.171.133: icmp_seq=3 ttl=64 time=0.641 ms
可以ping的通
登录服务端
[root@localhost ~]# docker login harbor.mydomain.com
Username: admin
Password:
Error response from daemon: Get "https://harbor.mydomain.com/v2/": dial tcp 192.168.171.133:443: connect: no route to host
[root@localhost ~]#
#要使用服务端的主机名来登录否者就登陆了官方的网站,这里可以看到显示没有配置路由所以有密码也登不上。
[root@localhost ~]# vim /etc/docker/daemon.json
"insecure-registries": ["harbor.mydomain.com"],
#这一行的作用是允许登录不安全的网站,后面接服务端的主机名。
#然后重启服务
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker login harbor.mydomain.com
Login Succeeded
[root@localhost ~]#
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 7a80323521cc 13 days ago 1.24MB
[root@localhost ~]#
#这里镜像名字必须要规范成服务端的名字加网站上那个默认的库.
[root@localhost ~]# docker tag busybox harbor.mydomain.com/library/kangge:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 7a80323521cc 13 days ago 1.24MB
harbor.mydomain.com/library/kangge v0.1 7a80323521cc 13 days ago 1.24MB
[root@localhost ~]#
[root@localhost ~]# docker push harbor.mydomain.com/library/kangge:v0.1
The push refers to repository [harbor.mydomain.com/library/kangge]
084326605ab6: Pushed
v0.1: digest: sha256:98de1ad411c6d08e50f26f392f3bc6cd65f686469b7c22a85c7b5fb1b820c154 size: 527
[root@localhost ~]#
#复制命令后就可以直接粘贴上去可以拉下来了
[root@localhost ~]# docker pull harbor.mydomain.com/library/kangge@sha256:98de1ad411c6d08e50f26f392f3bc6cd65f686469b7c22a85c7b5fb1b820c154
错误解决
//如果有这种报错:
Error response from daemon: Get "http://harbor.mydomain.com/v2/": unauthorized: authentication required
那就必须建议去服务端上修改配置文件
cd /usr/local/harbor #进去这个目录下
修改harbor.yml配置文件里
external_url: https://reg.mydomain.com #把这一行的注释取消掉并删掉后面的端口号
//如果有报这种错的话,建议把docker重新安装一下,当然你有更好的办法记得留言告诉我谢谢。
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.