环境部署
172.25.4.111 server1 master
172.25.4.112 server2 node1
172.25.4.113 server3 node2
下载swarm镜像
[root@server1 ~]# docker pull swarm
Using default tag: latest
latest: Pulling from library/swarm
d85c18077b82: Pull complete
1e6bb16f8cb1: Pull complete
85bac13497d7: Pull complete
Digest: sha256:b866583a3b8791bcd705b7bc0fd94c66b695a1a2dbaeb5f59ed29940e5015dc8
Status: Downloaded newer image for swarm:latest
[root@server2 docker]# docker pull swarm
[root@server3 ~]# docker pull swarm
添加swarm端口2375
[root@server1 ~]# cd /etc/systemd
[root@server1 systemd]# cd system
[root@server1 system]# mkdir /etc/systemd/system/docker.service.d
[root@server1 system]# cd docker.service.d/
[root@server1 docker.service.d]# vim tcp.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
[root@server1 docker.service.d]# systemctl daemon-reload[root@server1 docker.service.d]# systemctl restart docker[root@server1 docker.service.d]# netstat -an| grep 2375tcp6 0 0 :::2375 :::* LISTEN
swarm初始化
[root@server1 ~]# docker swarm init --advertise-addr 172.25.4.111
Swarm initialized: current node (swcvqn11902u3wtm56pjnql80) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-056gfhog6ikop119lyubwt0jp05vwo6jrlx3hpa6nyy5rl2yau-04nm7mao08mlimp57gpseyj36 172.25.4.111:2377 ##添加节点
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
查看集群信息状态
[root@server1 ~]# docker info
Containers: 29
Running: 15
Paused: 0
Stopped: 14
Images: 10
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: active
NodeID: swcvqn11902u3wtm56pjnql80
Is Manager: true
ClusterID: e0zqisbwf6d91y0gv5pzy4su3
Managers: 1
Nodes: 1
Default Address Pool: 10.0.0.0/8
SubnetSize: 24
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: 172.25.4.111
Manager Addresses:
172.25.4.111:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: Red Hat Enterprise Linux Server 7.3 (Maipo)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 992.7MiB
Name: server1
ID: JR7T:SV4V:HFS3:Y3YN:FRV2:AUXI:QKH4:5VI5:BWXH:2NWG:LRTM:TM6D
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:
127.0.0.0/8
Registry Mirrors:
https://z5utl514.mirror.aliyuncs.com/
Live Restore Enabled: false
Product License: Community Engine
查看节点状态
[root@server1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
swcvqn11902u3wtm56pjnql80 * server1 Ready Active Leader 18.09.6
注意上面node ID旁边那个*号表示现在连接到这个节点上
节点的添加
[root@server2 ~]# docker swarm join --token SWMTKN-1-056gfhog6ikop119lyubwt0jp05vwo6jrlx3hpa6nyy5rl2yau-04nm7mao08mlimp57gpseyj36 172.25.4.111:2377
This node joined a swarm as a worker.
[root@server3 ~]# docker swarm join --token SWMTKN-1-056gfhog6ikop119lyubwt0jp05vwo6jrlx3hpa6nyy5rl2yau-04nm7mao08mlimp57gpseyj36 172.25.4.111:2377
This node joined a swarm as a worker.
再次查看集群状态
[root@server1 ~]# docker node ls ##集群创建成功
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
swcvqn11902u3wtm56pjnql80 * server1 Ready Active Leader 18.09.6
fl4z4x46yr101kpeibwxsgi2y server2 Ready Active 18.09.6
6izecw3kpseuecnhadbfphkan server3 Ready Active 18.09.6