5 月 122018
 

Docker Swarm创建集群和加入集群

配置所有节点的hosts文件

[root@swarm1 ~]# vi /etc/hosts
192.168.50.246 swarm1
192.168.50.247 swarm2
192.168.50.248 swarm3
192.168.50.249 swarm4

管理节点初始化swarm集群

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

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

docker swarm join --token SWMTKN-1-2q9wi5wome3llyxy32n9ojusn7sl6peppdk8hqzvz5ofj89ze6-azmitpoe6vsb4q90vdat0b82l 192.168.50.246:2377

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

[root@swarm1 ~]#

查看监听

[root@swarm1 ~]# netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::2377 :::* LISTEN
tcp6 0 0 :::7946 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
[root@swarm1 ~]#

设置防火墙规则,允许节点间通信

[root@swarm1 ~]# iptables -I INPUT -p tcp --dport 2377 -j ACCEPT
[root@swarm1 ~]# iptables -I INPUT -p tcp --dport 7946 -j ACCEPT
[root@swarm1 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@swarm1 ~]#

其他节点加入集群

[root@swarm2 ~]# docker swarm join --token SWMTKN-1-2q9wi5wome3llyxy32n9ojusn7sl6peppdk8hqzvz5ofj89ze6-azmitpoe6vsb4q90vdat0b82l 192.168.50.246:2377
This node joined a swarm as a worker.
[root@swarm2 ~]#

[root@swarm3 ~]# docker swarm join --token SWMTKN-1-2q9wi5wome3llyxy32n9ojusn7sl6peppdk8hqzvz5ofj89ze6-azmitpoe6vsb4q90vdat0b82l 192.168.50.246:2377
This node joined a swarm as a worker.
[root@swarm3 ~]#

[root@swarm4 ~]# docker swarm join --token SWMTKN-1-2q9wi5wome3llyxy32n9ojusn7sl6peppdk8hqzvz5ofj89ze6-azmitpoe6vsb4q90vdat0b82l 192.168.50.246:2377
This node joined a swarm as a worker.
[root@swarm4 ~]#

查看swarm集群信息

[root@swarm1 ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.03.1-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
NodeID: rlle6k39z3xk82f1wqmjpd4m4
Is Manager: true
ClusterID: fys0dd2rq6v2j8ifxbnyp81oc
Managers: 1
Nodes: 4
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Number of Old Snapshots to Retain: 0
Heartbeat Tick: 1
Election Tick: 10
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Force Rotate: 0
Autolock Managers: false
Root Rotation In Progress: false
Node Address: 192.168.50.246
Manager Addresses:
192.168.50.246:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-862.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.849GiB
Name: swarm1
ID: PO2J:RTY3:ZX3Q:EFG2:M6HI:UYRI:HGL4:G2IP:NFQ4:EXIL:K6CQ:Y47I
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
192.168.50.216:5000
127.0.0.0/8
Registry Mirrors:
https://docker.mirrors.ustc.edu.cn/
Live Restore Enabled: false

[root@swarm1 ~]#

在管理节点上查看集群状态

[root@swarm1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
rlle6k39z3xk82f1wqmjpd4m4 * swarm1 Ready Active Leader 18.03.1-ce
fzi0eoey60bd25cklvt5qg6p5 swarm2 Ready Active 18.03.1-ce
59optctp5n9zvv3lvaifel7bx swarm3 Ready Active 18.03.1-ce
ixqldqaby2jrgfqx7ckjpg0zs swarm4 Ready Active 18.03.1-ce
[root@swarm1 ~]#

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据