部署harbor仓库
1. 安装docker-compose
[root@localhost ~]# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
[root@localhost ~]# mkdir -p $DOCKER_CONFIG/cli-plugins
[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 --:--:-- --:--:-- --:--:-- 0
100 24.5M 100 24.5M 0 0 25340 0 0:16:57 0:16:57 --:--:-- 30274
[root@localhost ~]# ls .docker/
cli-plugins
[root@localhost ~]# cd .docker/cli-plugins/
[root@localhost cli-plugins]# ls
docker-compose
[root@localhost cli-plugins]# chmod +x docker-compose
[root@localhost cli-plugins]# ll
total 25188
-rwxr-xr-x. 1 root root 25792512 Aug 11 19:09 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
//可以查看到版本号,说明docker-compose安装完成
[root@localhost ~]# docker compose version
Docker Compose version v2.7.0
2. 上传解压配置harbor
//下载harbor包
[root@localhost ~]# ls
anaconda-ks.cfg harbor-offline-installer-v2.5.3.tgz
//解压至/usr/local/目录下
[root@localhost ~]# tar xf harbor-offline-installer-v2.5.3.tgz -C /usr/local/
[root@localhost ~]# ls /usr/local/
bin etc games harbor include lib lib64 libexec sbin share src
[root@localhost ~]# cd /usr/local/harbor/
[root@localhost harbor]# ls
LICENSE common.sh harbor.v2.5.3.tar.gz harbor.yml.tmpl install.sh prepare
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
//修改一下主机名
[root@localhost harbor]# hostnamectl set-hostname harbor.example.com
[root@localhost harbor]# bash
[root@harbor harbor]# vim harbor.yml
hostname: harbor.example.com //指定主机名
#https: //注释掉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
[root@harbor harbor]# ls
LICENSE harbor.v2.5.3.tar.gz harbor.yml.tmpl prepare
common.sh harbor.yml install.sh
//执行脚本
[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 ...
ed825a5a3f34: Loading layer 37.6MB/37.6MB
······
✔ ----Harbor has been installed and started successfully.----
[root@harbor harbor]# ss -anlt
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 [::]:*
3. 设置开机自启
//修改配置文件
[root@harbor ~]# vim /etc/rc.local
2 cd /usr/local/harbor
3 docker-compose start
[root@harbor ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Jan 28 2022 /etc/rc.local -> rc.d/rc.local
[root@harbor ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 516 Aug 12 08:22 /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 12 08:22 /etc/rc.d/rc.local
//重启验证
[root@harbor ~]# reboot
[root@harbor ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
124a1a17d027 goharbor/nginx-photon:v2.5.3 "nginx -g 'daemon of…" 13 hours ago Up 4 seconds (health: starting) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx
6c85a0b038fb goharbor/harbor-jobservice:v2.5.3 "/harbor/entrypoint.…" 13 hours ago Up 5 seconds (health: starting) harbor-jobservice
ed6343219d25 goharbor/harbor-core:v2.5.3 "/harbor/entrypoint.…" 13 hours ago Up 5 seconds (health: starting) harbor-core
e12d1822c4a6 goharbor/harbor-db:v2.5.3 "/docker-entrypoint.…" 13 hours ago Up 5 seconds (health: starting) harbor-db
db29ea5a73a0 goharbor/redis-photon:v2.5.3 "redis-server /etc/r…" 13 hours ago Up 4 seconds (health: starting) redis
f469290a8de2 goharbor/registry-photon:v2.5.3 "/home/harbor/entryp…" 13 hours ago Up 5 seconds (health: starting) registry
561995d2b00d goharbor/harbor-registryctl:v2.5.3 "/home/harbor/start.…" 13 hours ago Up 5 seconds (health: starting) registryctl
712b08f83e66 goharbor/harbor-portal:v2.5.3 "nginx -g 'daemon of…" 13 hours ago Up 5 seconds (health: starting) harbor-portal
c3f323a530ab goharbor/harbor-log:v2.5.3 "/bin/sh -c /usr/loc…" 13 hours ago Up 4 seconds (health: starting) 127.0.0.1:1514->10514/tcp harbor-log
[root@harbor ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
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 127.0.0.1:1514 0.0.0.0:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
[root@harbor ~]#
4. 访问登录
5. 应用harbor仓库
//在客户端主机映射关系,进行ping通使系统可以识别主机
[root@client ~]# vim /etc/hosts
192.168.183.131 harbor.example.com
[root@client ~]# ping harbor.example.com
PING harbor.example.com (192.168.183.131) 56(84) bytes of data.
64 bytes from harbor.example.com (192.168.183.131): icmp_seq=1 ttl=64 time=0.425 ms
64 bytes from harbor.example.com (192.168.183.131): icmp_seq=2 ttl=64 time=0.743 ms
^C
--- harbor.example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1003ms
rtt min/avg/max/mdev = 0.425/0.584/0.743/0.159 ms
//在客户端登录到harbor仓库,先编写配置文件
[root@client ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://8r73devx.mirror.aliyuncs.com"],
"insecure-registries": ["harbor.example.com"],
"bip": "192.168.1.1/24"
}
[root@client ~]# systemctl restart docker
[root@client ~]# docker login harbor.example.com
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仓库
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lishuails/httpd a1.1 7f72e0736e76 3 days ago 731MB
harbor.example.com/library/httpd v0.1 7f72e0736e76 3 days ago 731MB
busybox latest beae173ccac6 7 months ago 1.24MB
httpd latest dabbfbe0c57b 7 months ago 144MB
centos latest 5d0da3dc9764 11 months ago 231MB
[root@client ~]# docker push harbor.example.com/library/httpd:v0.1
The push refers to repository [harbor.example.com/library/httpd]
aa3e11e9eb71: Pushed
74ddd0ec08fa: Pushed
v0.1: digest: sha256:31d9767c3c2daaff2b04ce19fc09950dd6674755e5bfb687a5d50ce9020cd1e3 size: 742
- 查看效果
//拉取镜像
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lishuails/httpd a1.1 7f72e0736e76 3 days ago 731MB
busybox latest beae173ccac6 7 months ago 1.24MB
httpd latest dabbfbe0c57b 7 months ago 144MB
centos latest 5d0da3dc9764 11 months ago 231MB
[root@client ~]# docker pull harbor.example.com/library/httpd:v0.1
v0.1: Pulling from library/httpd
Digest: sha256:31d9767c3c2daaff2b04ce19fc09950dd6674755e5bfb687a5d50ce9020cd1e3
Status: Downloaded newer image for harbor.example.com/library/httpd:v0.1
harbor.example.com/library/httpd:v0.1
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lishuails/httpd a1.1 7f72e0736e76 3 days ago 731MB
harbor.example.com/library/httpd v0.1 7f72e0736e76 3 days ago 731MB
busybox latest beae173ccac6 7 months ago 1.24MB
httpd latest dabbfbe0c57b 7 months ago 144MB
centos latest 5d0da3dc9764 11 months ago 231MB
[root@client ~]#
- 创建用户