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

Set up Swarm cluster

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

Share

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

A brief introduction to Swarm

Swarm project, through the aggregation of multiple Docker Engine together to form a dozen docker-engine to provide external container cluster services. At the same time, the cluster provides Swarm API, and users can use the Docker cluster as if they were using Docker Engine.

Swarm is a relatively simple set of tools for managing Docker clusters so that Docker clusters are exposed to users as a virtual whole. Swarm uses the standard Docker API interface as its front-end access port. in other words, various forms of Docker Client (dockerclient in go,docker_py,docker, etc.) can communicate directly with Swarm, and Swarm is almost entirely developed in GE language.

Second, the working principle of Swarm

1 、 Swarm

Cluster management and orchestration uses SwarmKit embedded in the Docker engine, which can start Swarm mode during Docker initialization or join an existing Swarm

2 、 Node

A node (node) is the actual column of the Docker engine that has been added to swarm. When you deploy the application to the cluster, you will submit the service definition to the management node, then the Manager management node dispatches tasks to the worker node, the manager node also performs the orchestration and cluster management functions to maintain the state of the cluster, and the work node receives and executes the tasks from the manager node. Typically, the manager node can also be a worker node, and the work node reports the current status to the manager node.

3. Service (Service)

A service is the definition of a task to be performed on the work node, which is executed on the work node, and the container image needs to be specified when the service is created.

4. Task (Task)

Tasks are commands executed in the docker container, and the manager node assigns tasks to the work node based on a specified number of copies of the task.

Third, the function of each module of Swarm

Docker swarm: cluster management, subcommands by init,join,leave,updata. (docker swarm-help for help)

Docker service: the service is created, and the subcommands are created by create,inspect,update,remove,tasks. (docker service-help for help)

Node is a docker engine entity added to the swarm cluster, which can run multiple node,node on a physical machine into:

1) Manager node (management node): performs the management function of the cluster, maintains the state of the cluster, and selects a leader node to perform scheduling tasks.

2) Work node (work node): receives and executes tasks, participates in container cluster load scheduling, and is only used to host task.

Service service: a service is the definition of executing tasks on the work node. Create a service that defines the images used by the container and the commands that the container runs.

Task task: a task contains a container and its running commands. Task is the executing entity of service, and task starts the docker container and performs tasks in the container.

IV. Swarm deployment

1. System environment

Two centos 7s correspond to swarm01 and swarm02 respectively

Swarm01:192.168.80.100

Swarm02:192.168.80.110

2. Modify the host name

Hostnamectl set-hostname swarm01hostnamectl set-hostname swarm02vi / etc/hosts / / modify the hosts file separately

192.168.80.100 swarm01

192.168.80.110 swarm02

3. Install docker (each must be installed)

Vi / etc/yum.repos.d/CentOS-Base.repo

Add the yum source of docker at the last line

[docker-repo]

Name=Docker Repository

Baseurl= https://yum.dockerproject.org/repo/main/centos/7/

Enabled=1

Gpgcheck=1

Gpgkey= https://yum.dockerproject.org/gpg

Yum install-y docker-engine

4. Change the mirror source of docker

Mkdir / etc/dockervi / etc/docker/daemon.json

{

"registry-mirrors": ["http://hub-mirror.c.163.com"]"

}

Or

{

"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]"

}

Systemctl daemon-reload / / reload configuration file

5. Modify docker listening port

Swarm communicates by listening on port 2375, so you need to set up port 2375 listening before using Swarm for cluster management. All CVM nodes docker enable 2375 listening. The configuration method varies with different docker versions.

Vi / lib/systemd/system/docker.service

Add:-H tcp://0.0.0.0:2375-H unix:///var/run/docker.sock to ExecStart

Systemctl start docker / / start dockernetstat-anput | grep 2375 / / View the listening port

6. Swarm installation (two sets are installed separately)

Docker pull swarm / / pull swarmdocker images from docker repository to check whether the download is successful

Docker swarm init-- advertise-addr 192.168.80.100 / / initialize Swarm

-- work nodes in advertis-addr:swarm use this IP address to contact manager

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.

Docker node ls / / View nodes. Only native machines join the swarm cluster.

7. Add cluster nodes

Execute the following command on the swaram02 machine

Docker swarm join\-- token SWMTKN-1-0mp5blsez01rkhdngyx7qnwapwfaugexq0llasg5t4mlr0rpdj-2i3qqd7ejsl73ga5fqncmeroe\ 192.168.80.1002377

Docker node list / / View on swarm01

8. Upgrade or downgrade the node (only on the primary node)

Docker node promote swarm02 / / upgrade swarm02 to primary node docker node demote swarm01 / / downgrade swarm02 to worker node docker node list / / View on swarm02

9. Create a swarm cluster network (on swarm02)

Docker network create-- driver overlay skynetdocker network ls / / View the network

10. Swarm deploy http (on the primary node swarm02)

Docker service create-p 80:80-- name webserver-- replicas 4 httpd

-- name: service name

-- replicas: number of service replica sets

-p: Port Mappin

Docker service ls / / View the list of services

Docker service ps webserver | grep Running / / View specific service enablement

Web visits 192.168.80.100 and 192.168.80.110 respectively

Note: httpd is not deployed on swarm02, but web pages can be accessed, indicating that the swarm01 node has received the task deployment of the master node.

11. Swarm image management (on swar02)

Docker pull portainer/portainer / / pull the image management image docker run-d-p 9000 name prtainer-test portainer/portainer 9000-- restart=always-- name prtainer-test portainer/portainer / / start the image

Web browser visits 192.168.80.110V9000

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