环境
IP | 备注 |
---|---|
192.168.1.10 | docker、harbor |
192.168.1.20 | docker、harbor |
告知master、slave机器都需要在安装docker、docker-compose、harbor, 然后master下载nginx镜像修改tag标签进行上传到私有仓库 尝试master-harbor远程复制slave-harbor 成功~
修改主机名、免密登录
代码语言:javascript复制[root@localhost ~]# hostname master
[root@localhost ~]# bash
[root@master ~]#
[root@localhost ~]# hostname slave
[root@localhost ~]# bash
[root@slave ~]#
master
代码语言:javascript复制echo '192.168.1.20 slave' >> /etc/hosts
[root@master ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:sBcmGls3wHzdl9qio/mjFuBvq1s5P4XaqHNkHypqTv4 root@master
The key's randomart image is:
---[RSA 2048]----
| o. . . . |
| o.. . . o |
| . .= |
| =.* o o . |
| o...S o . |
| .. .= . |
| . X |
| o. o.@o= |
| o oEXo oo |
----[SHA256]-----
[root@master ~]# ssh-copy-id -i slave
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'slave (192.168.1.20)' can't be established.
ECDSA key fingerprint is SHA256:dnnDcAA2qVnA31i7mtr9LYJmH2veu2 r4t 19qUSqqw.
ECDSA key fingerprint is MD5:0e:f3:c1:3c:dc:5f:12:66:ae:c9:01:51:66:db:bb:02.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@slave's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'slave'"
and check to make sure that only the key(s) you wanted were added.
## 测试登录
[root@master ~]# ssh slave
Last login: Fri Dec 25 09:17:17 2020 from 192.168.1.250
[root@slave ~]# exit
登出
Connection to slave closed.
master、slave安装docker、harbor
代码语言:javascript复制yum -y install yum-utils
yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
[root@master ~]# systemctl start docker
[root@master ~]# docker --version
Docker version 20.10.1, build 831ebea
安装docker-compose工具、harbor仓库
代码语言:javascript复制[root@master bin]# chmod x docker-compose
[root@master bin]# docker-compose -version
docker-compose version 1.25.4, build 8d51620a
[root@master ~]# tar -zxf harbor-offline-installer-v1.6.3.tgz
[root@master ~]# cd harbor
[root@master harbor]# vi harbor.cfg
7行 hostname = 192.168.1.10 #修改自己的ip
[root@slave harbor]# vi harbor.cfg
7行 hostname = 192.168.1.20 #修改自己的ip
[root@master harbor]# ./install.sh ##进行安装
修改docker配置文件添加仓库地址
代码语言:javascript复制[root@master harbor]# vim /usr/lib/systemd/system/docker.service
13行 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 192.168.1.10 #添加地址
[root@master harbor]# systemctl daemon-reload && systemctl restart docker
查看harbor服务状态
代码语言:javascript复制docker ps -a
查看是否都是正常状态
如果不是重新发布
[root@master harbor]# docker-compose down
[root@master harbor]# docker-compose up -d
测试登录
[root@master harbor]# docker login 192.168.1.10
Username: admin
Password: 默认密码Harbor12345
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
访问
测试上传镜像
docker tag SOURCE_IMAGE[:TAG] 192.168.1.10/test/IMAGE[:TAG] docker push 192.168.1.10/test/IMAGE[:TAG]
代码语言:javascript复制[root@master harbor]# docker pull nginx
[root@master harbor]# docker tag nginx:latest 192.168.1.10/test/nginx:latest
[root@master harbor]# docker push 192.168.1.10/test/nginx:latest
The push refers to repository [192.168.1.10/test/nginx]
4eaf0ea085df: Pushed
2c7498eef94a: Pushed
7d2b207c2679: Pushed
5c4e5adc71a8: Pushed
87c8a1d8f54f: Pushed
latest: digest: sha256:13e4551010728646aa7e1b1ac5313e04cf75d051fa441396832fcd6d600b5e71 size: 1362