Docker容器学习 --- machine介绍和使用

**本篇实验基于docker的swarm集群:
https://blog.csdn.net/aaaaaab_/article/details/81946787**
什么是docker-machine:

什么是docker-machine,简单来说就是给你快速创建一个docker容器环境的,
怎么说呢,如果你要给100台阿里云ECS安装上docker,传统方式就是你一台一
台ssh上去安装,但是有了docker-machine就不一样了,你可以快速给100台
ecs安装上docker,怎么快速法呢,你看完这文章就知道了。还有就是你要在
本地快读创建docker集群环境,我总不能一台一台创建虚拟机吧,所以
docker-machine可以解决这个问题。总之docker-machine就是帮助你快速去
创建安装docker环境的工具,这样说应该没什么问题吧

将三个节点的swarm集群节点使用docker swarm leave离开,然后systemctl stop docker即可恢复环境,主节点离开swarm集群使用 –force。
在真机安装docker-machine:

[root@foundation38 Desktop]# cd /usr/local/bin/ 
[root@foundation38 bin]# mv /home/kiosk/Desktop/docker-machine-Linux-x86_64-1.15.0 .
[root@foundation38 bin]# ls
docker-compose                      docker-machine-Linux-x86_64-1.15.0  rht-vmicons
docker-compose-Linux-x86_64-1.22.0  rht-vmctl                           rht-vmsetkeyboard
[root@foundation38 bin]# ln -s docker-machine-Linux-x86_64-1.15.0 docker-machine
[root@foundation38 bin]# docker-machine -v  测试安装
docker-machine version 0.15.0, build b48dc28d
[root@foundation38 bin]# ssh-keygen   搭建免密
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
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:
2f:70:35:0d:32:4e:aa:27:bc:f2:08:16:67:3f:d6:5c [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|        + .      |
|       + o o     |
|      . . o .    |
|   . .   . .     |
| . o+ o SE       |
|  + .+oo..       |
|... .+ o. .      |
|.. +. .  .       |
|  . .            |
+-----------------+

这里写图片描述
配置三台虚拟机的解析:

[root@foundation38 bin]# vim /etc/hosts
[root@foundation38 bin]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.38.100 www.westos.org bbs.westos.org
172.25.38.6 www.westos.org bbs.westos.org bbs.westos.org daolian.westos.org
172.25.38.11 test1
172.25.38.12 test2
172.25.38.13 test3
172.25.38.250 westos.org

这里写图片描述
配置真机与集群节点的免密:

[root@foundation38 bin]# cd /root/.ssh/
[root@foundation38 .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[root@foundation38 .ssh]# ssh-copy-id 172.25.38.11
[root@foundation38 .ssh]# ssh-copy-id 172.25.38.12
[root@foundation38 .ssh]# ssh-copy-id 172.25.38.13

这里写图片描述
测试免密连接:

[root@foundation38 .ssh]# ssh [email protected]
Last login: Thu Aug 23 15:23:19 2018 from westos.org
[root@test1 ~]# exit
logout
Connection to 172.25.38.11 closed.
[root@foundation38 .ssh]# ssh [email protected]
Last login: Thu Aug 23 15:23:48 2018 from westos.org
[root@test2 ~]# exit
logout
Connection to 172.25.38.12 closed.
[root@foundation38 .ssh]# ssh [email protected]
Last login: Thu Aug 23 15:23:59 2018 from westos.org
[root@test3 ~]# exit
logout
Connection to 172.25.38.13 closed.

这里写图片描述
配置集群节点:

[root@foundation38 .ssh]# docker-machine create --driver generic  --generic-ip-address=172.25.38.11 test1
[root@foundation38 .ssh]# docker-machine create --driver generic  --generic-ip-address=172.25.38.12 test2
[root@foundation38 .ssh]# docker-machine create --driver generic  --generic-ip-address=172.25.38.13 test3
[root@foundation38 .ssh]# docker-machine ls
NAME    ACTIVE   DRIVER    STATE     URL                       SWARM   DOCKER        ERRORS
test1   -        generic   Running   tcp://172.25.38.11:2376           v17.03.1-ce   
test2   -        generic   Running   tcp://172.25.38.12:2376           v17.03.1-ce   
test3   -        generic   Running   tcp://172.25.38.13:2376           v17.03.1-ce   

这里写图片描述
docker-machine会自动给其他节点开启docker服务:
这里写图片描述
这里写图片描述
这里写图片描述
小结:

docker-machine的优势就是可以批量部署多台服务器,本实验实例就是可以给多台安装docker服务的节点自动开启服务,而且不需要切换节点进行各个节点的配置。

猜你喜欢

转载自blog.csdn.net/aaaaaab_/article/details/81985574