首页 > 代码库 > docker swarm 集群创建
docker swarm 集群创建
一、 环境准备
1. 准备3台虚拟机,IP和主机名设置如下
192.168.71.137
manager1
192.168.71.141
worker1
192.168.71.140
worker2
2. 系统和软件版本
系统版本
[root@manager1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
内核版本
[root@manager1 ~]# uname -r
3.10.0-327.36.1.el7.x86_64
docker 版本
[root@manager1 ~]# docker -v
Docker version 1.12.2, build bb80604
3. 防火墙开通相关端口
放行一下端口:
TCP 2377 集群管理通信所需
TCP and UDP 7946 节点间通信所需
TCP and UDP 4789 overlay 网络所需
命令如下:
firewall-cmd --add-port=2377/tcp
firewall-cmd --add-port=2377/tcp --permanent
firewall-cmd --add-port=7946/tcp --add-port 7946/udp
firewall-cmd --add-port=7946/tcp --add-port 7946/udp --permanent
firewall-cmd --add-port=4789/tcp --add-port 4789/udp
firewall-cmd --add-port=4789/tcp --add-port 4789/udp --permanent
二、 swarm集群创建
1. 创建swarm集群
初始化命令如下,我这里用192.168.71.137为manager
docker swarm init --advertise-addr <MANAGER-IP>
[root@manager1 ~]# docker swarm init --advertise-addr 192.168.71.137
Swarm initialized: current node (8d1kzvnv99q2gy82ulrklezom) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-12k7eupx7wbuhdhyb1qo2vu8q49x8k4uq0d0t62ksb8irlylex-6fz55egsirm1l5076pin7ksc6 \
192.168.71.137:2377
To add a manager to this swarm, run ‘docker swarm join-token manager‘ and follow the instructions.
根据以上提示,可知节点加入集群需执行以上返回的那条命令。
查看docker info,显示docker工作在swarm模式
[root@manager1 ~]# docker info
...
Swarm: active
...
查看管理节点已启动起来一个节点
[root@manager1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
8d1kzvnv99q2gy82ulrklezom * manager1 Ready Active Leader
在work1 、worker2上执行加入集群的命令
[root@worker1 ~]# docker swarm join \
> --token SWMTKN-1-12k7eupx7wbuhdhyb1qo2vu8q49x8k4uq0d0t62ksb8irlylex-6fz55egsirm1l5076pin7ksc6 \
> 192.168.71.137:2377
This node joined a swarm as a worker.
[root@worker2 ~]# docker swarm join \
> --token SWMTKN-1-12k7eupx7wbuhdhyb1qo2vu8q49x8k4uq0d0t62ksb8irlylex-6fz55egsirm1l5076pin7ksc6 \
> 192.168.71.137:2377
This node joined a swarm as a worker.
如果上面的命令不记得了,可以在manager1节点上用以下命令查看
[root@manager1 ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-12k7eupx7wbuhdhyb1qo2vu8q49x8k4uq0d0t62ksb8irlylex-6fz55egsirm1l5076pin7ksc6 \
192.168.71.137:2377
在manager1节点上再次查看node列表信息
[root@manager1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
8d1kzvnv99q2gy82ulrklezom * manager1 Ready Active Leader
8iwemhb8ux2fedbdn12c9igii worker2 Ready Active
bdmj4stzpnwmkovonnxj6u4q9 worker1 Ready Active
说明集群已创建完成。
本文出自 “雨还是不停的落下” 博客,请务必保留此出处http://8869176.blog.51cto.com/8859176/1866884
docker swarm 集群创建