1、安装virtualbox
在/etc/yum.repos.d/目录下新建virtualbox.repo
写入:
[virtualbox] name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearchenabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
执行安装命令
#更新yum缓存yum clean all yum makecache#查找适合自己版本的virtualboxyum search VirtualBox# 安装VirtualBox-5.2.x86_64
安装docker-machine
官方指导安装docker-machine
官方centos安装docker
1、安装docker2、执行如下: base=https://github.com/docker/machine/releases/download/v0.16.0 && curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine && sudo install /tmp/docker-machine /usr/local/bin/docker-machine
3、 使用docker-machine创建两台虚拟机
$ docker-machine create --driver virtualbox myvm1 $ docker-machine create --driver virtualbox myvm2 $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS myvm1 - virtualbox Running tcp://192.168.99.100:2376 v17.06.2-cemyvm2 - virtualbox Running tcp://192.168.99.101:2376 v17.06.2-ce
如果出现This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory 则需要重启进入bios设置Intel Virtualization Technology设置成abled即可。
通过这两台启动swarm集群,myvm1作为管理节点,myvm2作为工作节点第一台机器充当管理器,执行管理命令并验证工作人员加入群,第二台是工作人员。
使用docker-machine ssh向VM发送命令。 docker swarm init可以指定myvm1成为一个swarm管理节点 执行命令参考如下: $ docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.104:2377" Swarm initialized: current node (x500bs7lrweto9chkg6xq2ybd) is now a manager. To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-197eaghawf5wqunblowkmgwjojv38ugtmscs943xrrz0jk6bpc-4uor1vdi4cleb5kqq2ri7s17g \ 192.168.99.104:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. 将myvm2 作为工作节点加入swarm $ docker-machine ssh myvm2 "docker swarm join \ --token SWMTKN-1-197eaghawf5wqunblowkmgwjojv38ugtmscs943xrrz0jk6bpc-4uor1vdi4cleb5kqq2ri7s17g \ > 192.168.99.104:2377" This node joined a swarm as a worker.
作者:勃列日涅夫
链接:https://www.jianshu.com/p/698bfe3732a0