react 前端框架如何驱动企业数字化转型与创新发展
596
2022-11-13
Docker----DockerSwarm集群环境搭建
(1)创建四个虚拟机(1核2G即可)
这里四个虚拟机ip分别为:
192.168.145.128192.168.145.129192.168.145.130192.168.145.131
(2)每个虚拟机安装docker
参照 Docker----CentOS7系统上Docker的安装与卸载 为四个虚拟机安装docker
(3)查看docker swarm 帮助文档
[root@localhost ~]# docker swarm --helpUsage: docker swarm COMMANDManage SwarmCommands: ca Display and rotate the root CA init Initialize a swarm join Join a swarm as a node and/or manager join-token Manage join tokens leave Leave the swarm unlock Unlock swarm unlock-key Manage the unlock key update Update the swarmRun 'docker swarm COMMAND --help' for more information on a command.[root@localhost ~]#
(4)查看docker swarm init 的帮助文档
[root@localhost ~]# docker swarm init --helpUsage: docker swarm init [OPTIONS]Initialize a swarmOptions: --advertise-addr string Advertised address (format:
(5)在192.168.145.128上创建一个swarm集群
[root@localhost ~]# docker swarm init --advertise-addr 192.168.145.128Swarm initialized: current node (wsqaq4isrzhlgphnnaqxucy6r) is now a manager.To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-50iq7p13l75w9oken3xqgqpnr 192.168.145.128:2377To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.[root@localhost ~]#
(6)查看当前集群中的节点信息
如下,表示当前集群中只有一个leader主节点
[root@localhost ~]# docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSIONwsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Leader 20.10.10[root@localhost ~]#
(7)在192.168.145.128 上查看增加manager节点的方法
[root@localhost ~]# docker swarm join-token managerTo add a manager to this swarm, run the following command: docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-5n9bpvj1v64wb9cvg7l2fitaj 192.168.145.128:2377[root@localhost ~]#
(8)增加节点
将上述(7)中查询到的增加manager节点的命令复制一下,然后分别在192.168.145.129和192.168.145.130节点上执行 注意:需要在每个虚拟机上关闭防火墙
systemctl stop firewalld
如下,在192.168.145.129节点上:
[root@localhost ~]# docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-5n9bpvj1v64wb9cvg7l2fitaj 192.168.145.128:2377This node joined a swarm as a manager.[root@localhost ~]#
如下,在192.168.145.130节点上:
[root@localhost ~]# docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-5n9bpvj1v64wb9cvg7l2fitaj 192.168.145.128:2377This node joined a swarm as a manager.[root@localhost ~]#
(9)此时,查看集群中节点信息
如下已经有三个manager节点了
[root@localhost ~]# docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSIONfhpe4p0m4gb47pxh48kf9psp8 localhost.localdomain Ready Active Reachable 20.10.10p1cfiyfyxgkhupjj03tvq40ph localhost.localdomain Ready Active Reachable 20.10.10wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Leader 20.10.10[root@localhost ~]#
(10)在manager节点查看加入worker节点的命令
如,在192.168.145.128上查看
[root@localhost ~]# docker swarm join-token workerTo add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-50iq7p13l75w9oken3xqgqpnr 192.168.145.128:2377[root@localhost ~]#
(11)增加worker节点
将上述(10)中查询到的命令复制拷贝到192.168.145.131上执行,增加worker节点 如下:在192.168.145.131上
[root@localhost ~]# docker swarm join --token SWMTKN-1-052n8lzu6tqwlz9osydt5ttcr268i4fxqpbgyps49nmvmh4ym6-50iq7p13l75w9oken3xqgqpnr 192.168.145.128:2377This node joined a swarm as a worker.[root@localhost ~]#
(12)查看集群节点信息
再次在192.168.145.128上查看当前集群节点信息,在任意manager节点上均可查看,
[root@localhost ~]# docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSIONfhpe4p0m4gb47pxh48kf9psp8 localhost.localdomain Ready Active Reachable 20.10.10p1cfiyfyxgkhupjj03tvq40ph localhost.localdomain Ready Active Leader 20.10.10wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Reachable 20.10.10xlgi99te9cchyz9n3ydkycf6k localhost.localdomain Ready Active 20.10.10
此时集群环境已经搭建OK了
(13)验证一下集群环境的高可用
将192.168.145.129环境上的docker服务停掉,模拟节点挂了
[root@localhost ~]# systemctl stop dockerWarning: Stopping docker.service, but it can still be activated by: docker.socket[root@localhost ~]#
(14)查看节点状态
再次回到192.168.145.128节点上查看节点状态,如下。集群整体状态仍然OK
[root@localhost ~]# docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSIONfhpe4p0m4gb47pxh48kf9psp8 localhost.localdomain Ready Active Reachable 20.10.10p1cfiyfyxgkhupjj03tvq40ph localhost.localdomain Down Active Unreachable 20.10.10wsqaq4isrzhlgphnnaqxucy6r * localhost.localdomain Ready Active Leader 20.10.10xlgi99te9cchyz9n3ydkycf6k localhost.localdomain Ready Active 20.10.10[root@localhost ~]#
(15)注意点
需要注意的是,manager节点的个数必须大于等于3时才具有高可用特性,即当manager节点个数大于等于3的时候,挂掉一个节点集群是仍然能正常工作
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~