Docker Swarm 基础5

2021-11-29 19:17:54 浏览数 (2)

创建 Swarm 集群

有了发现服务作基础,接下来就要创建 Swarm 管理节点,我们创建两个节点(分别在不同的服务器上)来模拟高可用架构

创建第一个管理节点

代码语言:javascript复制
[root@h104 ~]# docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise 192.168.100.104:4000 consul://192.168.100.104:8500
a6a0adaa76a8771bf373998832deaa236d68513bb5f9de0b3051c49761447e1a
[root@h104 ~]# docker ps -a 
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                     PORTS                                                                            NAMES
a6a0adaa76a8        swarm                       "/swarm manage -H :40"   3 seconds ago       Up 1 seconds               2375/tcp, 0.0.0.0:4000->4000/tcp                                                 sad_mestorf
3b12ab97b20f        progrium/consul             "/bin/start -server -"   16 hours ago        Up 20 minutes              53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 0.0.0.0:8500->8500/tcp, 8301-8302/udp   consul
236348a3c9ff        docker:5000/ci/jnkns-img2   "/bin/tini -- /usr/lo"   7 weeks ago         Exited (143) 4 weeks ago                                                                                    jenkins01
[root@h104 ~]#  

创建第二个管理节点

代码语言:javascript复制
[root@docker ~]# docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise 192.168.100.103:4000 consul://192.168.100.104:8500
de2669846044ea05851f69a643846d55b0f87c1f1d9abd29bcb90c71fa91bb0f
[root@docker ~]# docker ps -a 
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS                   PORTS                              NAMES
de2669846044        swarm                         "/swarm manage -H :40"   3 seconds ago       Up 2 seconds             2375/tcp, 0.0.0.0:4000->4000/tcp   high_wright
f616e3e353bc        ci-infrastructure/jnkns-img   "/bin/tini -- /usr/lo"   7 weeks ago         Exited (0) 7 weeks ago                                      jenkins01
71de3ba93794        registry:2                    "/bin/registry /etc/d"   8 weeks ago         Up 2 hours               0.0.0.0:5000->5000/tcp             registry
[root@docker ~]# 

Note: 涉及的网络端口有必要在防火墙上放行,打开方法

代码语言:javascript复制
[root@docker ~]# firewall-cmd --list-all 
public (default, active)
  interfaces: eno16777736 eno33554960
  sources: 
  services: dhcpv6-client ssh
  ports: 3306/tcp 80/tcp 40000/tcp 8080/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@docker ~]# firewall-cmd --add-port 4000/tcp
success
[root@docker ~]# firewall-cmd --list-all 
public (default, active)
  interfaces: eno16777736 eno33554960
  sources: 
  services: dhcpv6-client ssh
  ports: 3306/tcp 80/tcp 40000/tcp 8080/tcp 4000/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@docker ~]#

有必要打开的端口为 4000/tcp、2375/tcp、8500/tcp

PORT

Comment

4000/tcp

管理节点用来接受请求的端口

2375/tcp

Docker 引擎接受请求的端口

8500/tcp

发现服务用来接受请求的端口

此时已经可以使用命令对管理节点发送请求

代码语言:javascript复制
[root@h104 ~]# docker -H :4000 info 
Containers: 0
Images: 0
Server Version: swarm/1.1.3
Role: replica
Primary: 192.168.100.103:4000
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 0
Kernel Version: 3.10.0-327.4.4.el7.x86_64
Operating System: linux
CPUs: 0
Total Memory: 0 B
Name: a6a0adaa76a8
[root@h104 ~]# docker -H :4000 ps -a 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@h104 ~]# 
----------
[root@docker ~]# docker -H :4000 info
Containers: 0
Images: 0
Server Version: swarm/1.1.3
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 0
Kernel Version: 3.10.0-327.4.4.el7.x86_64
Operating System: linux
CPUs: 0
Total Memory: 0 B
Name: de2669846044
[root@docker ~]# docker -H :4000 ps -a 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@docker ~]#

0 人点赞