In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Swarm was a separate project before Docker version 1.12, and after the release of Docker version 1.12, the project was merged into Docker and became a subcommand of Docker. Currently, Swarm is the only tool provided by the Docker community that natively supports Docker cluster management. It can transform a system composed of multiple Docker hosts into a single virtual Docker host, so that containers can form a subnet network across hosts.
Using Swarm, Docker can easily create container clusters on multiple hosts, and containers can communicate across host networks.
Swarm clusters are divided into Manager nodes and Worker nodes.
Service is used in Swarm to create / manage multiple containers using the same image, multiple containers provide services at the same time, and load balancing among multiple containers. Each Service has a floating IP (VIP), and each container has its own physical IP. Create a Swarm-based Overlay network and mount the Service to this network. The containers in the Service can then interwork with each other through the Service name and IP address.
Here are three machines to build a Swarm cluster
Bd0 192.168.0.109
Bd1 192.168.0.192
Bd2 192.168.0.193
Docker enables remote management
By default, the Docker daemon generates a / var/run/docker.sock file for local process communication without listening on any port, so by default Docker can only use command line operations locally. If you want to remotely operate the Docker host on another machine, you need to have Docker listen on a port in order to communicate remotely.
On my CentOS 7X, first modify the OPTIONS parameter in the Docker configuration file / etc/sysconfig/docker to add
-H unix:///var/run/docker.sock-H 0.0.0.014 5555
The modified parameters are similar.
OPTIONS='--selinux-enabled-- log-driver=journald-- signature-verification=false-H unix:///var/run/docker.sock-H 0.0.0.015 5555'
Then restart the Docker service
$sudo systemctl restart docker.service
Test it
Sudo docker-H: 5555 images
Create a Swarm cluster
Get Swarm image
Download the swarm image on three nodes
$sudo docker pull swarm
Initialize the Swarm cluster
First initialize the Swarm cluster on the bd0 node
$sudo docker swarm initError response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (192.168.0.109 on eth0 and 192.168.122.1 on virbr0)-specify one with-- advertise-addr
The first creation failed because my machine had two network cards, and Swarm didn't know which network card to use to build a cluster, so I needed to use-- advertise-addr to specify which network card to use.
$sudo docker swarm init-- advertise-addr 192.168.0.109Swarm initialized: current node (1egy2ark49q6xokudps5wykhn) is now a manager.To add a worker to this swarm, run the following command: docker swarm join\-- token SWMTKN-1-0x11m2uk7ps9bh7nflkxwirgv0syvacl18rut3hilz4i9lgis3-d9m22hixt0b57hjj81im8bqdl\ 192.168.0.109 Vol 2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Then run the following command on the bd1 and bd2 nodes to join the machine to the cluster
$sudo docker swarm join\-- token SWMTKN-1-0x11m2uk7ps9bh7nflkxwirgv0syvacl18rut3hilz4i9lgis3-d9m22hixt0b57hjj81im8bqdl\ 192.168.0.109VR 2377
This node joined a swarm as a worker.
Let's look at the cluster node information.
$sudo docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUS11ochjq4o1s2m6w4u8jxb37w6 bd1 Ready Active1egy2ark49q6xokudps5wykhn * bd0 Ready Active Leaderb4e2ywnhhd6fhgfxtr1qh5gew bd2 Ready Active
Create a cluster across host networks
First take a look at the cluster network
$sudo docker network lsNETWORK ID NAME DRIVER SCOPE36679de6466b bridge bridge local72e853673d8b docker_gwbridge bridge localb45cef05e017 host host local1zzlk9hpwyqy ingress overlay swarm
Add a Swarm network
$sudo docker network create-driver overlay myswarma04evrfrr4cvnbvrummzvg0mn
After creation, take a look at the cluster network
$sudo docker network lsNETWORK ID NAME DRIVER SCOPE36679de6466b bridge bridge local72e853673d8b docker_gwbridge bridge localb45cef05e017 host host local1zzlk9hpwyqy ingress overlay swarma04evrfrr4cv myswarm overlay swarm
Deployment servic
Here we use nginx services to demonstrate how to create a service cluster.
Download nginx image
$sudo docker pull nginx
Create a service
$sudo docker service create-- replicas 2-- name mynginx-p 8000 name mynginx 80-- network=myswarm nginx5xrm96xveqw5gq63srts1rbhw
Here you create a nginx service that requires two nginx instances. At the same time, in order to be accessed by the external network address, we do a port mapping, which is mapped to port 8000 of the physical host.
View Servic
$sudo docker service lsID NAME REPLICAS IMAGE COMMAND5xrm96xveqw5 mynginx 2 nginx$ sudo docker service ps mynginxID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR1crmc5ecsjoci8xavxzbnbks3 mynginx.1 nginx bd0 Running Running 2 nginx$ sudo docker service ps mynginxID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR1crmc5ecsjoci8xavxzbnbks3 mynginx.1 nginx bd0 Running Running 23 seconds agodivhrq89xhxka8bvb8r9zqqhz mynginx.2 nginx bd2 Running Running 20 seconds ago$ sudo docker service inspect mynginx... "VirtualIPs": [{"NetworkID": "1zzlk9hpwyqyocloxy9j9vct7", "Addr": "10.255.0.6 Addr"}, {"NetworkID": "a04evrfrr4cvnbvrummzvg0mn" "Addr": "10.0.0.2 prime 24"}].
View on bd0
$sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe480d427fd51 nginx:latest "nginx-g'daemon off" 41 seconds ago Up 40 seconds 80/tcp mynginx.1.1crmc5ecsjoci8xavxzbnbks3
View on bd2
$sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc12d4f9eb457 nginx:latest "nginx-g'daemon off" 56 seconds ago Up 52 seconds 80/tcp mynginx.2.divhrq89xhxka8bvb8r9zqqhz
The service has been created and started, so let's access http://bd0:8000 in the browser to verify the status of the nginx service.
Failover of the service
First, let's take a look at the status of the current service.
$sudo docker service ps mynginxID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR1crmc5ecsjoci8xavxzbnbks3 mynginx.1 nginx bd0 Running Running 23 seconds agodivhrq89xhxka8bvb8r9zqqhz mynginx.2 nginx bd2 Running Running 20 seconds ago
Then stop the service on bd2
$sudo docker kill mynginx.2.divhrq89xhxka8bvb8r9zqqhzmynginx.2.divhrq89xhxka8bvb8r9zqqhz
Observe the service status again, as follows:
$sudo docker service ps mynginxID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR1crmc5ecsjoci8xavxzbnbks3 mynginx.1 nginx bd0 Running Running 6 minutes agobr5iyie0dr945ixnq7s77kunr mynginx.2 nginx bd1 Running Running 4 seconds agodivhrq89xhxka8bvb8r9zqqhz\ _ mynginx.2 nginx bd2 Shutdown Failed 5 seconds ago "task: non-zero exit"
You can see that another instance has been created on bd1 to replace the original instance on bd2.
Expansion / reduction of services
Add service instances
$sudo docker service scale mynginx=3mynginx scaled to 3$ sudo docker service ps mynginxID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR1crmc5ecsjoci8xavxzbnbks3 mynginx.1 nginx bd0 Running Running 7 minutes agobr5iyie0dr945ixnq7s77kunr mynginx.2 nginx bd1 Running Running about a minute agodivhrq89xhxka8bvb8r9zqqhz\ _ mynginx.2 nginx bd2 Shutdown Failed about a minute ago "task: non-zero exit" 985tln0aprsvjthjpve0n6qmz mynginx.3 nginx bd2 Running Preparing 3 seconds ago
Reduce service instanc
$sudo docker service scale mynginx=2mynginx scaled to 2$ sudo docker service ps mynginxID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR1crmc5ecsjoci8xavxzbnbks3 mynginx.1 nginx bd0 Running Running 7 minutes agobr5iyie0dr945ixnq7s77kunr mynginx.2 nginx bd1 Shutdown Shutdown less than a second agodivhrq89xhxka8bvb8r9zqqhz\ _ mynginx.2 nginx bd2 Shutdown Failed about a minute ago "task: non-zero exit" 985tln0aprsvjthjpve0n6qmz mynginx.3 nginx bd2 Running Running 5 seconds ago
Delete a service
$sudo docker service rm mynginx
Summary
The above is the method of Docker using Swarm to set up cluster introduced by the editor to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply you in time. Thank you very much for your support to the website!
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.