Docker Swarm集群搭建
Docker Swarm集群搭建
Alexdocker swarm集群搭建
准备:
- 三台centos
查看当前机器ip
ip a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23[vagrant@swarm-manager ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:5f:94:78 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
valid_lft 84826sec preferred_lft 84826sec
inet6 fe80::5054:ff:fe5f:9478/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:97:19:ed brd ff:ff:ff:ff:ff:ff
inet 192.168.205.10/24 brd 192.168.205.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe97:19ed/64 scope link
valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:1a:a4:85:34 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever初始化主节点
docker swarm init --advertise-addr=192.168.205.10
(先运行的节点会成为master节点)1
2
3
4
5
6
7
8[vagrant@swarm-manager ~]$ docker swarm init --advertise-addr=192.168.205.10
Swarm initialized: current node (20c1eo2g14dkiyy6x22bei0zk) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3yo18735j27focp6obcvlvlzw684mextoz63ebcudave76th9a-67ngk1hmh5mnkm2up6naky796 192.168.205.10:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.node2 加入
1
2
3➜ centos7-3 vagrant ssh swarm-worker2
[vagrant@swarm-worker2 ~]$ docker swarm join --token SWMTKN-1-3yo18735j27focp6obcvlvlzw684mextoz63ebcudave76th9a-67ngk1hmh5mnkm2up6naky796 192.168.205.10:2377
This node joined a swarm as a worker.node3加入
1
docker swarm join --token SWMTKN-1-3yo18735j27focp6obcvlvlzw684mextoz63ebcudave76th9a-67ngk1hmh5mnkm2up6naky796 192.168.205.10:2377
查看节点
1
2
3
4
5[vagrant@swarm-manager ~]$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
20c1eo2g14dkiyy6x22bei0zk * swarm-manager Ready Active Leader 18.05.0-ce
dqb1n6oqy18bpuo101zxa3aym swarm-worker1 Ready Active 18.05.0-ce
bzkzymvsd0mt7ehjmrp64z38z swarm-worker2 Ready Active 18.05.0-ce
docker-machine 创建集群节点
docker-machine create swarm-manger