当前位置:网站首页>7. Swarm builds clusters
7. Swarm builds clusters
2020-11-06 22:38:00 【Taizhu-yj】
Use dokcer Problems that will come up :
- How to manage so many containers ?
- How to easily expand horizontally
- If the container down 了 , How can I resume the boot ?
- How to update the container without affecting the business ?
- How to monitor and track these containers ?
- How to schedule container creation ?
- Protect private data ?
Docker It comes with a container arrangement tool :Swarm Mode

Manager Node as manager , To maintain high availability , You can't deploy just one , If there are multiple deployment, there is a problem of how to synchronize the state .docker Built in distributed database , adopt raft Agreement assurance Manager Information is synchronized , There's no cleft brain .
Worker Nodes are work nodes , It also needs to be with other Worker Node data synchronization , Use Gossip The protocol synchronizes the information .

We go through swarm manager Node to deploy a service, We don't know about this service Which container nodes will eventually run on .swarm manager According to some strategies , For example, memory. , Hard disk resources, etc , take service Deployed in some container node in .

3 nodes swarm cluster setup
1. On the first machine , establish docker swarm manager command
docker swarm init --advertise-addr=192.168.8.117 This machine IP
Create success , Returns the docker swarm join --token SWMTKN-1-1aud6ztpiwgujisqn20gb9lfldziidj0dz7lww3puod36t5j5d-c6azyl8d0rhhzd8c25u9laxxp 192.168.8.117:2377 For others docker swarm join This machine , Build clusters .

2. On the second machine , establish docker swarm And add the first machine , command
docker swarm join --token SWMTKN-1-1aud6ztpiwgujisqn20gb9lfldziidj0dz7lww3puod36t5j5d-c6azyl8d0rhhzd8c25u9laxxp 192.168.8.117:2377
Something goes wrong
Error response from daemon: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: Error while dialing dial tcp 192.168.8.117:2377: connect: no route to host"
reason
If you want to use swarm function , Need at all manager node Turn on the node 2377 port .
terms of settlement
Open designated port firewall-cmd --zone=public --add-port=2377/tcp --permanent
Restart the firewall to take effect systemctl restart firewalld
see swarm node
docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
5xeakkex0klrezwb1p5y0pcja localhost.localdomain Ready Active 19.03.13
rk1pu6zgxkh278262d5yprzqi localhost.localdomain Ready Active 19.03.13
ulms2qb8gvnehsmgx7d7dcx9a * localhost.localdomain Ready Active Leader 19.03.13
Steps to build :
1、 Environmental preparation :
1.1、 Three are ready to be installed docker engine Of centos/Ubuntu System host (docker Version must be in
1.12 Version above , The old version does not support swarm)
1.2、docker Container host ip Fixed address , All work nodes in the cluster must have access to the management node
1.3、 The cluster management node must use the appropriate protocol and ensure that the port is available
Cluster management communication :TCP, port 2377
Node communication :TCP and UDP, port 7946
Overlay networks (docker The Internet ):UDP, port 4789 overlay drive
explain : Three container hosts ip The addresses are :
192.168.200.162( The management node )
192.168.200.163( Work node )
192.168.200.158( Work node )
The host names are :manager1、work1 as well as work2
vim /etc/hostname ( You need to restart after the modification )
2、 establish docker swarm
2.1、 stay manager1 Create... On the machine docker swarm colony
docker swarm init ‐‐advertise‐addr 192.168.200.162
(‐‐advertise‐addr Will be IP The address of the machine is set as the cluster management node ; If it's a single node , There is no need to refer to
Count )
2.2、 View management node cluster information :
docker node ls
3、 towards docker swarm Add a work node in the : Execute the following commands in the two work nodes respectively ,ip The address is
manager Node
3.1、 Add two work node
docker swarm join ‐‐token xxx 192.168.200.138:2377 (worker1)
docker swarm join ‐‐token xxx 192.168.200.138:2377 (worker2)
(‐‐token xxx: Add authentication information of work nodes to the specified cluster ,xxx Authentication information is creating docker
swarm When the )
3.2、 Continue to view the differences between the management node cluster information and the previous one
docker node ls
4、 stay docker swarm Deploy services in
stay Docker Swarm When deploying services in a cluster , Both available Docker Hub Start the service with a self-contained image on the , also
You can use self access Dockerfile Build the image to start the service . If you use yourself through Dockerfile Built
To start a service, you must first push the image to Docker Hub Central warehouse . In order to facilitate the study of readers , here
To use the Docker Hub Bring your own alpine Image as an example to deploy cluster services
4.1、 Deployment Services
docker service create ‐‐replicas 1 ‐‐name helloworld alpine ping
docker.com
docker service create Instructions : Used in Swarm Create a cluster based on alpine Mirror service
‐‐replicas Parameters : Specifies that the service has only one replica instance
‐‐name Parameters : Specify the service name after successful creation as helloworld
ping docker.com Instructions : Represents the command to be executed after the service is started
5. see docker swarm Services in the cluster
View the list of services :docker service ls
View details of deploying specific services :docker service inspect The service name
View the allocation and operation of services on cluster nodes :docker service ps The service name
6、 Change the number of copies
stay manager1 On , Change the number of service copies ( The created copies are randomly assigned to different nodes )
docker service scale helloworld=5
7、 Delete service ( At the management node )
docker service rm The service name
8、 Access the service
8.1、 View the network list in the cluster environment :docker network ls
8.2、 stay manager1 Create a overlay For driven networks ( Network connection used by default ingress)
docker network create ‐d=overlay my‐multi‐host‐network
8.3、 In the cluster management node manager1 Put a nginx service
docker service create \
‐‐network my‐multi‐host‐network \
‐‐name my‐web \
‐p 8080:80 \
‐‐replicas 2 \
nginx
8.3、 View the running status of the service in the management node :
docker service ps my‐web
8.4、 Access test
版权声明
本文为[Taizhu-yj]所创,转载请带上原文链接,感谢
边栏推荐
- Dynamsoft barcode reader v7.5!
- 谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
- The essence of transaction and the principle of deadlock
- Bluetooth broadcast chip for Shanghai giant micro
- STM32F030K6T6兼容替换灵动MM32F031K6T6
- 预留电池接口,内置充放电电路及电量计,迅为助力轻松搞定手持应用
- 细数软件工程----各阶段必不可少的那些图
- Interviewer: how about shardingsphere
- Experiment one
- 三步轻松理解Kerberos协议
猜你喜欢

Logo design company, Nanjing

20个XR项目路演,近20个资本机构出席!诚邀您参加2020 Qualcomm XR生态合作伙伴大会

How to add modules to nginx image?

Two dimensional code location and alarm system of Expressway

【涂鸦物联网足迹】涂鸦云平台全景介绍

心理咨询app开发所具备的优点与功能

插件Bilibili新版0.5.5

实验一

Code generator plug-in and creator preform file analysis

RFID fixed assets management system for fire equipment
随机推荐
2020-08-19: what mechanism does TCP ensure reliability?
Git remote library rollback specified version
Configuration of AP hotspot on xunwei-imx6ull development board
汽车维修app开发的好处与功能
The advantages and functions of psychological counseling app
How to start the hidden preferences in coda 2 on the terminal?
非易失性MRAM存储器应用于各级高速缓存
条形码识别器Dynamsoft Barcode Reader v7.5全新上线!
Qt音视频开发46-视频传输UDP版
vue3 新特性
win7 APPCRASH(解决方法)(转)
The Interpreter pattern of behavior pattern
Cloudquery v1.2.0 release
How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
[graffiti Internet of things footprints] panoramic introduction of graffiti cloud platform
STM32F030F4P6兼容灵动微MM32F031F4P6
7.Swarm搭建集群
Common mathematical basic formulas of recursive and backtracking algorithms
2020-09-04: do you understand the function call convention?
高速公路二维码定位报警系统