1. Introduction
Docker Client includes Docker Manager and Docker Worker. Docker Manager manages Docker cluster and also undertakes the work of Docker Worker.
2. Create a Swarm cluster. The following uses four Docker nodes as an example
# --listen-addr IP :port Manager node
Swarm --advertise-addr IP address of the advertise-addr IP address of the advertise-addr
docker swarm init
Add manager or worker nodes to cluster by executing the corresponding command
Paste the instructions after execution onto the other three Dockers for execution, and you can add them
docker swarm join-token manager
docker swarm join-token work
Swarm Swarm can only execute this command on the Manager node
docker node ls
Copy the code
- Check the Swarm cluster network
docker network ls
Copy the code
Swarm is a shared network created by Swarm. It is not used for communication between containers. It is used to manage Swarm clusters
- Create a shared network for containers to communicate with each other
docker network create -d overlay --attachable swarm_test
Copy the code
- To create a PXC cluster, use the sWARM_test network
docker volume create v1
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=a11111 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=a111111 -v v1:/var/lib/mysql -v backup:/data --privileged --name=node1 --net=swarm_test pxc
Copy the code
To open the second host, do the following
docker volume create v2
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=a11111 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=a111111 -e CLUSTER_JOIN=node1 -v v2:/var/lib/mysql -v backup:/data --privileged --name=node1 --net=swarm_test pxc
Copy the code
To open the third host, do as follows
docker volume create v3
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=a11111 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=a111111 -e CLUSTER_JOIN=node1 -v v3:/var/lib/mysql -v backup:/data --privileged --name=node1 --net=swarm_test pxc
Copy the code
To open the fourth host, do as follows
docker volume create v4
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=a11111 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=a111111 -e CLUSTER_JOIN=node1 -v v4:/var/lib/mysql -v backup:/data --privileged --name=node1 --net=swarm_test pxc
Copy the code
- If you want to view the network IP address for Node1
docker inspect node1
Copy the code
3. Exit the Swarm cluster and log in to the docker node
docker stop node
docker rm node
docker swarm leave --force
Copy the code
Manager must use the –force parameter to exit the cluster
4. Passively exited the Swarm cluster from the management node
Docker node Demote Node ID Docker node RMCopy the code
Delete any node must stop its Docker service first, Manager node must demote Manager node first, and then delete
Then, log in to the node host
docker stop node
docker rm node
service docker stop
Copy the code
Finally, cut back to the Manager node and execute
Docker node ls DOCker node RM node IDCopy the code