Docker swarm builds cluster environment

First, prepare the environment server to install the Docker environment

Docker version: Docker Version 20.10.1, Build 831ebea

Mongodb version: 4.2.7

CentOS Linux Release 7.7.1908 (Core)

Two, three accessible servers such as

10.11.32.25

10.11.32.26

10.11.32.27

Third, cluster steps

Select an active server (10.11.32.25) and run the following command

Docker swarm init --advertise-addr 10.11.32.25Copy the code

Other servers are added to the primary node

docker swarm join --token SWMTKN-1-42w2dmkv2u18k9d6vi65rhqggjcqcc31iijnecd4bbi43bmom2-b3o89g28thkcken0v3qxtczuj 172.16.10.85:2377
Copy the code

View the token method of the manger node

docker swarm join-token manager 
Copy the code

View the cluster server list

docker node ls
Copy the code

A non-management node is upgraded to a management node

Docker node promote the host name of the working node 1Copy the code

Create a network

docker network create -d overlay --attachable GIE-IOT-network
Copy the code

Check the network

docker network ls
Copy the code

Write the yML file of the service (such as redis.yml) and start the container

docker stack deploy -c redis.yml redis

Swarm: delete the node and dissolve the swarm

1, non-primary node demoted to working node (primary node executed)

docker node promote nodeID
Copy the code

2, the work node leaves the cluster (execute the work segment)

docker swarm leave --force 
Copy the code

Delete node (primary node operation)

docker node rm nodeId
Copy the code

\