Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker Operation and maintenance deployment of the "practical" Open Source Project-Building Cluster deployment with the help of dockerSwarm (9)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Original articles, welcome to reprint. Reprint please indicate: Reprint from IT people story meeting, thank you!

Original link address: "Practical chapter" Open source project docker operation and maintenance deployment-build cluster deployment with dockerSwarm (IX)

In order to integrate the learning knowledge, all clusters are currently placed on a virtual machine. What if this virtual machine goes down? As the saying goes, don't put all eggs in one basket, split the nodes of various clusters and deploy them. We should deploy various nodes into machines and multiple hosts. In this way, we don't worry about which host to hang.

Source code: github.com/limingios/netFuture/blob/master/docker-swarm/

Talk about Docker Swarm.

Swarm is a member of docker's three swordsmen. As mentioned before, you can watch intermediate and advanced.

docker machine Kubernetes Engine docker compose Script Service docker swarm Container Cluster Technology

Decentralized design

Swarm Manager also takes on the role of worker node.

Swarm Worker Run Container Deployment Project

Swarm has no central node, and hanging on to one of them will not hang the others. Swarm Manager If the master dies, immediately elect a new master.

Creating a Cluster Environment

First of all, the docker environment has been installed on the machine.

docker swarm init Add to swarm cluster #Add to manager docker swarm join-token manager#Add to worker docker swarm join-token worker environment Build application IP address Service configuration Install application Installation method docker-swarm-manager1192.168.66.100docker-swarm-manager1 single core 2g memory docker-swarm-manager 1docker-swarm-manager2192.168.66.101docker-swarm-manager2 single core 2g memory docker-swarm-manager 2docker-swarm-manager node1192.168.66.102docker-swarm-node1 single core 2g memory docker-swarm-node 1docker-swarm-node2192.168.66.103docker-swarm-node2 single core 2g memory docker-swarm-node2docker

docker swarm environment

A total of 4 nodes, 2 manager nodes, 2 work nodes, manager is not only management, but also work, to put it bluntly, a total of 4 work nodes.

Creating docker swarm clusters

su -#password vagrantdocker swarm init

Note: If you encounter dual network cards when creating a new cluster, you can specify which IP to use. For example, the above example may encounter the following error.

Error response from daemon: could not choose an IP address toadvertise since this system has multiple addresses on differentinterfaces (10.0.2.15 on enp0s3 and 192.168.66.100 on enp0s8) - specify one with --advertise-addr

Create docker swarm again 192.168.66.100

docker swarm init --advertise-addr 192.168.66.100 --listen-addr 192.168.66.100:2377docker swarm join-token manager

Create docker swarm again 192.168.66.101

The current node joins the swarm cluster as manager

docker swarm join --token SWMTKN-1-4itumtscktomolcau8a8cte98erjn2420fy2oyj18ujuvxkkzx-9qutkvpzk87chtr4pv8770mcb 192.168.66.100:2377

Create docker swarm again 192.168.66.102

The current node joins the swarm cluster as a worker

docker swarm join --token SWMTKN-1-4itumtscktomolcau8a8cte98erjn2420fy2oyj18ujuvxkkzx-f2dlt8g3hg86gyc9x6esewtwl 192.168.66.100:2377

Create docker swarm again 192.168.66.103

The current node joins the swarm cluster as a worker

docker swarm join --token SWMTKN-1-4itumtscktomolcau8a8cte98erjn2420fy2oyj18ujuvxkkzx-f2dlt8g3hg86gyc9x6esewtwl 192.168.66.100:2377

View swarm clusters

It can only be executed within the manager node.

After the leader hangs, the reachable can manage the cluster.

docker node ls

View the network of swarm clusters

It can only be executed within the manager node.

docker network ls

Create a shared network between containers

It can only be executed within the manager node.

docker network create -d overlay --attachable swarm_testdocker network ls

At present, there are 4 machines. If you want the containers in 4 machines to be shared, overlay the network. You only need to create the container--net=swarm_test.

Create 5 pxc containers 192.168.66.100

Create 2 containers. As mentioned before, how to create, the most important thing is to use the shared network of swarm.

docker volume create v1docker volume create backup1#add domain name resolution echo "nameserver 8.8.8.8"| tee /etc/resolv.conf > /dev/null sudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh|sh -s http://b81aace9.m.daocloud.iosudo systemctl restart dockerdocker run -d -p 3306:3306 --net=swarm_test \ --name=node1 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v1:/var/lib/mysql \ --privileged \ -v backup1:/data \ percona/percona-xtradb-clusterdocker ps

docker volume create v2docker run -d -p 3307:3306 --net=swarm_test \ --name=node2 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v2:/var/lib/mysql \ --privileged \ -v backup1:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps

192.168.66.101

Create a container. As mentioned before, how to create, the most important thing is to use the shared network of swarm.

docker volume create v3docker volume create backup3docker run -d -p 3307:3306 --net=swarm_test \ --name=node3 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v3:/var/lib/mysql \ --privileged \ -v backup3:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps

192.168.66.102

Create a container. As mentioned before, how to create, the most important thing is to use the shared network of swarm.

docker volume create v4docker volume create backup4docker run -d -p 3307:3306 --net=swarm_test \ --name=node4 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v4:/var/lib/mysql \ --privileged \ -v backup4:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps 192.168.66.103

Create a container. As mentioned before, how to create, the most important thing is to use the shared network of swarm.

docker volume create v4docker volume create backup4docker run -d -p 3307:3306 --net=swarm_test \ --name=node4 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v4:/var/lib/mysql \ --privileged \ -v backup4:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps

container cluster

In this diagram, draw 4 linux hosts, all installed docker virtual machine, if I want to install A program now, directly select Docker-1 this host container to install A program, so there is no problem. But single node single container deployment, once this node hangs, A program will not, in order to prevent this we have redundant design, directly in Docker-2 this host container also install A program, so that Docker-1 inside A program hangs, Docker-2 inside A program can also run. This function is a bit like Load Balancer, but it really is. Docker swarm provides something different from Load Balancer. Swarm only provides the management of container status. If the A program in Docker-1 hangs and finds that there are originally two, now it becomes a danger, and immediately one is up. Real-time guarantee of quantity in docker container.

Container clusters are suitable for scenarios

Container clusters are not suitable for stateful applications, such as databases, caches, etc.

Swarm exit #Manager exit must add--forcedocker swarm leave --force delete node service docker stop#Manager node needs to be demoted docker node rm docker network first

PS: This time, I mainly said three important points: build a containerized communication network through the docker-swarm network, and when creating a cluster--net joins the network created by docker-swarm to facilitate communication. Which are suitable for containerized clusters, databases and caches. How to manipulate nodes in docker-swarm.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report