docker machine 准备工作
导入epel安装源
yum install epel-release
添加VirtualBox安装源
cd /etc/yum.repos.d/
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.rep
安装相关依赖包
# yum update
# yum install binutils qt gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms
安装 VirtualBox-6.0
yum install VirtualBox-6.0
启动 VirtualBox
/usr/lib/virtualbox/vboxdrv.sh setup
此时可能会出现报错,一般会出现两种错误,再次列举一下,方便以后
出现缺少某一个版本的
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is not currently set up to build kernel modules (system extensions).
Running the following commands should set the system up correctly:
yum install kernel-devel-3.10.0-693.2.2.el7.x86_64
(The last command may fail if your system is not fully updated.)
yum install kernel-devel
vboxdrv.sh: failed: Look at /var/log/vbox-install.log to find out what went wrong.
此时输入两个命令查看内核版本
ll /usr/src/kernels/
uname -r
两个内核的信息是对不上的,此时需要升级内核,输入下方命令
yum update kernel
更新完成后,手动重启即可
如果使用的是虚拟机,那么需要开启虚拟化
: This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory
此时选中虚拟机,右键设置,然后点击处理器,在右侧虚拟化引擎勾选第一个,然后重启虚拟机即可
创建swarm集群
初始化集群
在 Docker Machine 一节中我们了解到 Docker Machine 可以在数秒内创建一个虚拟的 Docker 主机,下面我们使用它来创建三个 Docker 主机,并加入到集群中。
我们首先创建一个 Docker 主机作为管理节点。
docker-machine create -d virtualbox manager
我们再进入这个容器中
docker-machine ssh manager
[root@localhost ~]# docker-machine ssh manager
( '>')
/) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY.
(/-_--_-\) www.tinycorelinux.net
docker@manager:~$ docker swarm init --advertise-addr 192.168.99.100
Swarm initialized: current node (ooidnt636m2hdmhj35hwc7fgj) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-5421xmjuzjm2chw5ttgu5ro18qpwdrk4q7jxn2tw8k44bdbyio-bdax7i3jbt1u4u05krkhyoeu3 192.168.99.100:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
此时可以获取到这些信息,用于其他节点连接主节点
docker swarm join --token SWMTKN-1-5421xmjuzjm2chw5ttgu5ro18qpwdrk4q7jxn2tw8k44bdbyio-bdax7i3jbt1u4u05krkhyoeu3 192.168.99.100:2377
增加工作节点
增加两个工作节点
节点1:
docker-machine create -d virtualbox worker2
docker-machine ssh worker2
docker@worker2:~$ docker swarm join --token SWMTKN-1-5421xmjuzjm2chw5ttgu5ro18qpwdrk4q7jxn2tw8k44bdbyio-bdax7i3jbt1u4u05krkhyoeu3 192.168.99.100:2377
This node joined a swarm as a worker.
节点2:
docker-machine create -d virtualbox worker:3
docker-machine ssh worker3
docker@worker3:~$ docker swarm join --token SWMTKN-1-5421xmjuzjm2chw5ttgu5ro18qpwdrk4q7jxn2tw8k44bdbyio-bdax7i3jbt1u4u05krkhyoeu3 192.168.99.100:2377
This node joined a swarm as a worker.
查看集群
此时我们已经创建了一个小型的 Swarm 集群,包含一个管理节点和两个工作节点。
此时我们可以进入管理端节点进行进行集群的查看
docker@manager:~$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ooidnt636m2hdmhj35hwc7fgj * manager Ready Active Leader 18.09.1
i770bradnjb2yb65uf53twyb8 worker2 Ready Active 18.09.1
d3oy3bs5xend4zcn9fmfrwwru worker3 Ready Active 18.09.1