当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- September 3, 2020: naked writing algorithm: loop matrix traversal.
- Application insights application insights use application maps to build request link views
- JVM class loading mechanism
- How to create an interactive kernel density chart
- September 9, 2020: naked writing algorithm: two threads print numbers 1-100 in turn.
- Points to be considered when deleting mapping field of index in ES
- 心理咨询app开发所具备的优点与功能
- 【涂鸦物联网足迹】物联网基础介绍篇
- 2020-08-17: how to solve data skew in detail?
- 高速公路二维码定位报警系统
猜你喜欢
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
python3操作Jenkins模块api
JVM class loading mechanism
Unexpected element.. required element
Stm32f030c6t6 compatible to replace mm32spin05pf
Dynamsoft barcode reader v7.5!
The Interpreter pattern of behavior pattern
Event monitoring problem
Es create a new index database and copy the old index library, practice pro test effective!
What grammar is it? ]
随机推荐
DC-1 target
8.Swarm创建维护和水平扩展Service
[learning] interface test case writing and testing concerns
How to optimize the decoding performance of dynamsoft barcode reader
Introduction to Huawei cloud micro certification examination
Gantt chart grouping activities tutorial
Git remote library rollback specified version
20 XR projects roadshows, nearly 20 capital institutions attended! We sincerely invite you to attend the 2020 qcomm XR eco Partner Conference
预留电池接口,内置充放电电路及电量计,迅为助力轻松搞定手持应用
实验一
迅为iMX6开发板-设备树内核-menuconfig的使用
Benefits and functions of auto maintenance app development
2020-08-15: under what circumstances should data tasks be optimized?
python3操作Jenkins模块api
如何才能快速正确的部署甘特图
List to map (split the list according to the key, and the value of the same key is a list)
FreeSWITCH视频会议“标准”解决方案
What grammar is it? ]
Stm32f030c6t6 compatible to replace mm32spin05pf
JS array the usage of array is all here (array method reconstruction, array traversal, array de duplication, array judgment and conversion)