Docker Swarm 基础6

2021-11-29 19:18:16 浏览数 (1)

可见通过投票自动选举出103为主节点,104为备份节点,主节点是投票选出的而不是谁先加入谁就一定是主节点,103和104上都有运行中的容器,但目前还看不到,因为没有安装swarm代理节点


添加一个节点

安装完swarm代理节点后就可以通过管理节点使用到该服务器上的资源

代码语言:javascript复制
[root@h104 ~]# docker run -d swarm join --advertise=192.168.100.104:2375 consul://192.168.100.104:8500
055469770d50b477642717e3ebcd795eca26806bc1d55a547d60ac4559991b79
[root@h104 ~]# docker ps -a 
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                     PORTS                                                                            NAMES
055469770d50        swarm                       "/swarm join --advert"   3 seconds ago       Up 1 seconds               2375/tcp                                                                         sharp_engelbart
a6a0adaa76a8        swarm                       "/swarm manage -H :40"   50 minutes ago      Up 50 minutes              2375/tcp, 0.0.0.0:4000->4000/tcp                                                 sad_mestorf
3b12ab97b20f        progrium/consul             "/bin/start -server -"   17 hours ago        Up About an hour           53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 0.0.0.0:8500->8500/tcp   consul
236348a3c9ff        docker:5000/ci/jnkns-img2   "/bin/tini -- /usr/lo"   7 weeks ago         Exited (143) 4 weeks ago                                                                                    jenkins01
[root@h104 ~]# docker -H :4000 info 
Containers: 4
Images: 9
Server Version: swarm/1.1.3
Role: replica
Primary: 192.168.100.103:4000
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 1
 h104: 192.168.100.104:2375
  └ Status: Healthy
  └ Containers: 4
  └ Reserved CPUs: 0 / 2
  └ Reserved Memory: 0 B / 2.044 GiB
  └ Labels: executiondriver=native-0.2, kernelversion=3.10.0-327.4.4.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
  └ Error: (none)
  └ UpdatedAt: 2016-03-23T06:44:50Z
Kernel Version: 3.10.0-327.4.4.el7.x86_64
Operating System: linux
CPUs: 2
Total Memory: 2.044 GiB
Name: a6a0adaa76a8
[root@h104 ~]# 

添加另一个节点

代码语言:javascript复制
[root@docker ~]# docker run -d swarm join --advertise=192.168.100.103:2375 consul://192.168.100.104:8500
592ca6995b4d66344686d588f066db6a6dc7018e45052704bdf9728d36cca807
[root@docker ~]# docker -H :4000 info
Containers: 8
Images: 17
Server Version: swarm/1.1.3
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 2
 docker: 192.168.100.103:2375
  └ Status: Healthy
  └ Containers: 4
  └ Reserved CPUs: 0 / 2
  └ Reserved Memory: 0 B / 4.045 GiB
  └ Labels: executiondriver=native-0.2, kernelversion=3.10.0-327.4.4.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
  └ Error: (none)
  └ UpdatedAt: 2016-03-23T06:45:32Z
 h104: 192.168.100.104:2375
  └ Status: Healthy
  └ Containers: 4
  └ Reserved CPUs: 0 / 2
  └ Reserved Memory: 0 B / 2.044 GiB
  └ Labels: executiondriver=native-0.2, kernelversion=3.10.0-327.4.4.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
  └ Error: (none)
  └ UpdatedAt: 2016-03-23T06:45:49Z
Kernel Version: 3.10.0-327.4.4.el7.x86_64
Operating System: linux
CPUs: 4
Total Memory: 6.09 GiB
Name: de2669846044
[root@docker ~]# 

此时,Swarm 的集群已经构建完成和成功启动,同时符合高可用的架构,并且可以通过添加更多的服务发现节点,swarm管理节点,普通swarm节点来进一步提升系统的稳定性、可用性和负载能力

0 人点赞