Swarm集群搭建

官网:

https://docs.docker.com/engine/swarm/

 

工作模式:

https://docs.docker.com/engine/swarm/how-swarm-mode-works/nodes/

 

 

 

 

 

搭建集群

 

 

 

 

 

 

 

 

 

 

1、Docker-1初始化

[root@WALKER ~]# docker swarm init --advertise-addr 192.168.0.103
Swarm initialized: current node (rk8308ds1mbzbaxll8oeiyzal) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-5ojh0lt68xhlea80uw52gjtvo7o3fgj8slykf6bdzegw5jfyyb-bi7jgk4p40ei99rrlych8jl7v 192.168.0.103:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

[root@WALKER ~]#

 

初始化节点:docker swarm init

加入一个节点:docker swarm join

获取令牌:docker swarm join-token manager

        docker swarm join-token worker

 

 

2、Docker-2加入节点

[root@WALKER ~]# docker swarm join --token SWMTKN-1-5ojh0lt68xhlea80uw52gjtvo7o3fgj8slykf6bdzegw5jfyyb-bi7jgk4p40ei99rrlych8jl7v 192.168.0.103:2377
This node joined a swarm as a worker.
[root@WALKER ~]#

3、在Docker-1上查看一下节点

docker node ls

 

 

 

 4、让其他节点加入

Docker-1上生成命令:docker swarm join-token worker

 

 [root@WALKER ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-5ojh0lt68xhlea80uw52gjtvo7o3fgj8slykf6bdzegw5jfyyb-bi7jgk4p40ei99rrlych8jl7v 192.168.0.103:2377
(让其他主机输入这个命令)
[root@WALKER ~]#

 

 

 

 

 

如何想让Docker-4成为manager节点,在Docker-1上输入docker swarm join-token manager,生成的命令Docker-4输入

 

 

 

如果我们这里加入节点错误,需要关闭Docker-4的防火墙:systemctl stop firewalld

 

 

 

 

 

 

我们去Docker-1上再次查看一下节点:

 

 

 

 

5、小结

一共就两个步骤:

(1)生成主节点init

(2)其他节点加入(manager或者worker)

 

(注意:我们这里有2主2从,其实是不科学的,至少要有3主!)

 

posted @ 2022-04-24 10:54  屯子里唯一的架构师  阅读(129)  评论(0编辑  收藏  举报