In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
one。 A brief introduction to the concept and principle of Docker Swarm Docker Swarm
Swarm is developed using the Objective C language. Writing Swarm applications in early versions also makes Objective C provide support for the Java language from Swarm version 2.0, and may support JavaScript, C++, Python, Perl and other languages in the future. The latest version of Swarm, Swarm 2.1.1, can be run in different versions of Unix, Linux, Windows95, Windows98, WindowsNT, and Windows2000.
The simulation of socio-economic system is based on the theoretical study of complex adaptive system (Complex Adaptive System, referred to as CAS). Through "relatively simple micro individual activities can highlight the complex behavior at the macro level", it opens the way for the research and practice of social sciences to take the flight of contemporary new technology.
How Docker Swarm works
The Docker client sends a request to the Swarm manager through Docker API, and the Swarm Manager invokes a node in the cluster through the daemon to perform the task. Because the containers are running on the nodes, Swarm, as an independent cluster management tool, will not affect the normal operation of all nodes in the cluster because it cannot work properly for some reason. When the service returns to normal, Swarm reads the log to perform the recovery action of the cluster. The architecture diagram is shown in figure 1:
Figure 1.Docker Swarm architecture diagram
Action
Since 1994, the Santa Fe Institute (SFI) has carried out a research project to develop a toolset to help scientists analyze complex adaptive systems. This simulation toolset is called Swarm. In 1995, SFI released the beta version of Swarm.
Users can use the class library provided by Swarm to build a simulation system, so that the subjects and elements in the system interact with each other through discrete events. Since Swarm does not impose any constraints on the interaction between model and model elements, Swarm should be able to simulate any physical or social system. In fact, there are people writing programs in Swarm in a wide range of research fields, including biology, economics, physics, chemistry and ecology.
The purpose of the Swarm project is to create an efficient, reliable and reusable software experimental instrument through the cooperation of scientists and software engineers. It can give scientists a standard set of software tools, just like providing a well-equipped software laboratory to help people focus on research rather than making tools.
Swarm is actually a set of class libraries written in Objective-C, an object-oriented C language. Some graphical interfaces, such as charts, buttons, and windows, are described in TCL/TK. Swarm initially ran only under the Unix operating system and the X Windows interface, and in April 1998, with the release of version 1.1, Swarm introduced a version that could run on Windows 95/98/NT. In 1999, Swarm provided support for Java, which made Swarm more and more useful for non-computer professionals.
two。 Main points of Docker Swarm
The load of Swarm is very low. As far as I can see, the CPU load of Swarm for scheduling and communication is very low. Therefore, the management node (Manager) of the Swarm can act as a working node (Worker) at the same time. If you need to build a very large cluster (1000 + nodes), the management node needs more resources, but for small and medium-sized clusters, the resources needed by the management node are negligible.
The network communication (service discovery, load balancing, and communication between containers) of the Swarm cluster is very reliable. When you open a service port, any node in the Swarm cluster can access it. Load balancing is also provided by Swarm. Some of the problems encountered before will be mentioned later, but they have been resolved after Docker 1.13.
three。 Experimental environment host IP address service docker01192.168.1.11swarm+overlay+webUIdocker02192.168.1.13nginxdocker03192.168.1.20nginx
All three hosts turn off the firewall, disable selinux, modify hostname, time synchronization, and add domain name resolution.
The docker version must be: from v1.12 (you can view the version using docker version)
1. Turn off the firewall and disable Selinux [root @ localhost ~] # systemctl stop firewalld [root@localhost ~] # hostnamectl set-hostname docker03 [root@localhost ~] # su-2. Time synchronization mv / etc/localtime / etc/localtime.bkcp / usr/share/zoneinfo/Asia/Shanghai/etc/localtime3. Modify the hostname (all three) [root@localhost ~] # hostnamectl set-hostname docker01 [root@localhost ~] # su-4. Add domain name resolution [root@docker01 ~] # vim / etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.1.11 docker01192.168.1.13 docker02192.168.1.20 docker03 IV. Swarm principle
Swarm: a cluster of multiple hosts running docker engin
Node: each docker engin is a node, divided into manager and worker.
Manager node: responsible for performing container choreography and cluster management, keeping and maintaining swarm in the desired state. Swarm can have multiple manager node, and they will automatically coordinate and elect a leader to perform orchestration tasks. But on the contrary, you can't do without manager node.
Worker node: accept and execute the tasks assigned by manager node, and the default manager node is also a worker node, but you can set it to manager-only node so that it is only responsible for orchestration and management.
Service: used to define commands executed on the worker.
Basic command operation
Docker swarm leave: apply to leave a cluster, and then check that the status of the node will become down, and then delete it through manager node.
Docker node rm xxx: delete a node
Docker swarm join-token [manager | worker]: generates a token, which can be a manager or worker identity.
Docker node demote (downgrade): downgrade the swarm node from manager to worker
Docker node promote (upgrade): upgrade the work of swarm nodes to manager
Docker node ls: view cluster information (only on hosts in the manager role)
Docker service scale web05=6: dynamic expansion and reduction of container
Docker service ps web01: view the nodes on which the created container runs
Docker service ls: view the services created
Docker swarm leave: get out of this cluster
Docker node rm docker03: remove docker03 from the server of the manager role
Docker node update-- availability drain docker01: set host docker01 not to run containers, but containers that are already running will not stop
Docker node update-- label-add mem=max docker03: change the label of the docker03 host to mem=max
Docker service update-- replicas 8-- image 192.168.20.6:5000/lvjianzhao:v2.0-- container-label-add 'node.labels.mem==max' lvjianzhao05: upgrade the service to 8 containers and specify to run on the host labeled with mem=max
five。 Docker01 initializes the cluster [root@docker01 ~] # docker swarm init-- advertise-addr 192.168.1.11
-- advertise-addr: specifies the address to communicate with other docker.
The result returned above tells us that the initialization was successful, and if you want to add a work node, run the following command:
Note: tokens are only valid for 24 hours
After the above command is executed, the machine automatically joins the swarm cluster. This will create a cluster token and obtain a globally unique token as the unique identity of the cluster. This token value will be used later when other nodes are added to the cluster. Where the-- advertise-addr parameter indicates that worker nodes in other swarm use this ip address to contact the manager. The output of the command contains commands on how other nodes join the cluster.
If you want to add manager nodes: run the following command
6. Simple operations of swarm cluster 1.docker02 and docker03 join the cluster with worker [root@docker03 ~] # docker swarm join-- token SWMTKN-1-5kxn9wloh7npnytklwbfciesr9di7uvu521gwnqm9h2n0pbokj-1e60wt0yr5583e4mzwbxnn3a8 192.168.1.11:2377docker01 to view the cluster [root@docker01 ~] # docker node ls
Note: the "*" here represents the node to which it currently belongs.
two。 Delete Node docker02 and docker03 request to leave a Cluster [root@docker02 ~] # docker swarm leave docker Delete docker02 and docker03 Node [root@docker01 ~] # docker node rm docker02 [root@docker01 ~] # docker node rm docker03docker01 View Cluster [root@docker01 ~] # docker node ls
3.docker02 and docker03 join the cluster docker01 with manager to generate manager tokens [root@docker01 ~] # docker swarm join-token manager
Docker02 and docker03 join the cluster docker swarm join-- token SWMTKN-1-5kxn9wloh7npnytklwbfciesr9di7uvu521gwnqm9h2n0pbokj-cz6hbyv9r5htyqwj5tfol65aa 192.168.1.11:2377docker01 view the cluster [root@docker01 ~] # docker node ls
4.docker02 and docker03 downgrade docker01 (manager) downgrade docker02 and docker03 to worker [root@docker01 ~] # docker node demote docker02 [root@docker01 ~] # docker node demote docker03 View Cluster [root@docker01 ~] # docker node ls
seven。 Deploy docker swarm Cluster Network overlay: overlay Network
Overlay networks manages communication between docker daemons in Swarm. Containers can be attached to one or more existing overlay networks to enable communication between containers
[root@docker01 ~] # docker network create-d overlay-- attachable docker//attachable: this parameter must be added, otherwise it cannot be used in the container.
When we created the network, we didn't deploy a storage service, such as consul, because docker swarm comes with storage.
Docker01 View Network
However, you will find that the other two will not discover this network, so you need to wait to create a service service based on this network to see it.
[root@docker01 ~] # docker network ls
eight。 Docker01 deploy a graphical webUI interface 1.docker01 import image [root@docker01~] # docker pull dockersamples/visualizer2. Launch a container [root@docker01 ~] # docker run-d-p 8080 HOST=192.168.1.100-e PORT=8080-v / var/run/docker.sock:/var/run/docker.sock-- name visualiaer dockersamples/visualizer3 based on the image. Verify http://192.168.1.11:8080/ through browser access
If you cannot access the web page, you need to enable routing and forwarding.
[root@docker01] # echo net.ipv4.ip_forward = 1 > > / etc/sysctl.conf [root@docker01] # sysctl-p9. Create service (service) 1. Create a service service based on nginx container [root@docker01 ~] # docker pull nginx// download nginx image (all three) [root@docker01 ~] # docker service create-- replicas 1-- network docker-- name web1-p 80:80 nginx:latest [root@docker01 ~] # docker service create-- replicas 1-- network docker-- name web2-p 80 nginx:latest
/ /-- replicas: number of copies
It can be understood that a copy is equal to a container.
two。 View the created service service [root@docker01 ~] # docker service ls
View a servicefuw [root@docker01 ~] # docker service ps web1 separately
[root@docker01 ~] # docker service ps web2
3. View the web interface
4. Create five service services based on nginx container [root@docker01 ~] # docker service create-- replicas 5-- network docker-- name web-p 80 nginx:latest web interface view
5. Suspend docker02web View (Discovery Services are assigned to other servers)
6. Restore docker02web view (found that the service did not return to docker02)
10. Realize the capacity expansion and reduction of docker container. Delete web1 and web2 service [root@docker01 ~] # docker service rm web1 web22. Expansion and reduction of containers
(1) capacity expansion
[root@docker01 ~] # docker service scale web=8
(2) reduction
[root@docker01 ~] # docker service scale web=3
3. Set manager node not to work [root@docker01 ~] # docker node update docker01-- availability drain
Setting the host docker01 will not run containers, but containers that are already running will not stop
There are three options that can be configured after the "--availability" option, as follows:
"active": work; "pause": temporarily not working; "drain": permanent non-working
[root@docker01 ~] # docker node ls
Web interface view
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.