In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The three swordsmen in the docker container are swarm, compose and machine. This article will give you a detailed introduction to the installation and use of swarm, compose and machine. I hope you can get something from this article.
One of the three swordsmen in Docker swarm cluster
Docker docker2 docker3
192.168.1.1 192.168.1.20 192.168.1.30
Turn off the firewall and selinux. 3 dockerhost add dns domain name resolution to distinguish hostname.
Bash or restart
[root@docker ~] # ping docker2
Whether the Ping domain name can be connected. (time synchronization)
The Docker version must be: v1.12 version begins.
Experiment:
1) describe the characteristics of each node of docker swarm and summarize the concepts of swarm, node, manager node, worker node and service.
Swarm: a cluster of hosts running docker engin (engine).
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: receives and executes tasks that are dispatched by manager node, and the default manager node is also a work node, but it can be set to manager-only node. Let it only be responsible for choreography and management.
Service: used to define commands executed on the worker.
You can do without worker node, but not without Manager node.
2) deploy a swarm cluster that requires 3 dockerhost,docker01 to be manager node,02 and 03 to be worker node.
1 "initialize the cluster
[root@docker] # docker swarm init-- advertise-addr 192.168.1.10
/ /-- advertise-addr: specifies the address to communicate with other node.
Save tokens (tokens can only be saved for 24 hours)
The result returned above tells us that initialization was successful, and if you want to add a work node, run the following command:
Docker swarm join-- token SWMTKN-1-0blimv9lspg990gyt0l9knlpvcxx6xioyqh7p6mxkuxvckui9t-149nryrras3u9vr52n0nc14ui 192.168.1.1purl 2377
Note: token is only valid for 24 hours.
If you want to add a manager node: run the following command
Docker swarm join-toker manager
When the other two nodes join successfully, we can specify docker node ls to view the node details.
View node information
[root@docker ~] # docker node ls
This star represents the terminal where it is located:
Apply to leave the cluster: (docker2,docker3)
[root@docker2 ~] # docker swarm leave: (after applying to leave a cluster, checking the node status will change to down, and then you can delete it through manager node)
Node left the swarm.
[root@docker3 ~] # docker swarm leave
Node left the swarm.
Delete a node
[root@docker ~] # docker node rm docker2
Docker2
[root@docker ~] # docker node rm docker3
Docker3
3) promote 02 and 03 to manager node, and then restore 02 and 03 to worker node. If you downgrade 01 to worker node at this time, ask if it is OK. (not allowed)
Generate token: can be manager identity or worker identity
[root@docker ~] # docker swarm join-token manager | worker
To add a manager to this swarm, run the following command:
Docker swarm join-- token SWMTKN-1-0blimv9lspg990gyt0l9knlpvcxx6xioyqh7p6mxkuxvckui9t-e7en15s0hzdibnuj1dnp0hwd4 192.168.1.1purl 2377
Docker node demote: demote: downgrade the manager of the swarm node to worker
Docker node promote: promotion: upgrade the worker of the swarm node to manager
4) deploy a servcie service, which requires the use of a httpd image with the name test. Eight copies are required. And swarm cluster requires that manager nodes do not participate in the work.
2 deploy docker swarm cluster network
Overlay: overlay network:
[root@docker] # docker network create-d overlay-- attachable docker
Mjzqlj8edarzxkiqayr0e5ib9
/ / 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.
3 "deploy a graphical web UI interface.
To run as a container
Import image package: myvisualizer.tar
[root@docker ~] # docker load
< myvisualizer.tar docker run -d -p 8080:8080 -e HOST=192.168.1.1 -e PORT=8080 -v /var/run/docker.sock:/var/run/docker.sock --name visualizer dockersamples/visualizer:latest 然后通过浏览器fangwen验证 如果访问不到,需开启路由转发 [root@docker ~]# echo net.ipv4.ip_forward = 1 >> / etc/sysctl.conf [root@docker ~] # sysctl-pnet.ipv4.ip_forward = 1
4 "create service (service)
Import nginx.tar image package
[root@docker ~] # docker load
< nginx.tar [root@docker ~]# docker service create --replicas 1 --network docker --name web2 -p 80 nginx:latest [root@docker ~]# docker service ps web2 //--replicas:副本数量。 大概可以理解为:一个副本等同一个容器 //查看service: docker service ls //查看service信息: docker service ps XXX 创建5个副本(容器) [root@docker ~]# docker service create --replicas 5 --network docker --name web -p 80 nginx:latest 删除副本 [root@docker ~]# docker service rm web1 就算本地有镜像,也会上网查找最新的nginx镜像。 [root@docker ~]# docker service scale web=8 Scale:扩容 ("active"|"pause"|"drain")活动/暂停/不参加 //设置manager node不参加 [root@docker ~]# docker node update docker --availability drain 5》搭建私有仓库。 之前的文章有,这里就不多说了: 6》自定义镜像 要求:基于httpd镜像,更改主访问界面内容。镜像tag版本为v1。 [root@docker ~]# mkdir {v1,v2,v3}[root@docker v1]# vim index.html[root@docker v1]# vim DockerfileFROM httpdADD index.html /usr/local/apache2/htdocs/index.html[root@docker v1]# docker build -t 192.168.1.1:5000/httpd:v1 .[root@docker v1]# docker push 192.168.1.1:5000/httpd:v1 **v2**[root@docker v1]# cd ../v2[root@docker v2]# ls[root@docker v2]# echo 22222 >Index.html [root@docker v2] # cat > Dockerfile FROM httpd > ADD index.html / usr/local/apache2/htdocs/index.html > EOF [root@docker v2] # docker build-t 192.168.1.1:5000/httpd:v2. * * v3 steps * [root@docker v3] # echo 33333333 > index.html [root@docker v3] # cat > Dockerfile FROM httpd > ADD index.html / usr/local/apache2/htdocs/index.html > EOF [root@docker v3] # docker build-t 192.168.1. 1:5000/httpd:v3 .Sending build context to Docker daemon 3.072kBStep 1 Compact 2: FROM httpd-- > ff0f8d389b3aStep 2 Acer 2: ADD index.html / usr/local/apache2/htdocs/index.html-- > 0bdecd412589Successfully built 0bdecd412589Successfully tagged 192.168.1.1:5000/httpd:v3
7. Publish a service based on the above image
Requirement: the number of copies is 3. The service name is bdqn
[root@docker] # docker service create-- replicas 3-- name bdqn-p 80:80 192.168.1.1:5000/httpd:v1
The default ingress network, including the custom network created, provides a unified entrance to the container that the back end really provides services to users.
Docker service create-- replicas 3-- name test-p 80 192.168.1.1:5000/httpd:v1
* expansion and reduction of service capacity (scale)
30000-32767
[root@docker ~] # docker service scale bdqn=6
You can set the number of copies directly through scale for capacity expansion and reduction.
Upgrade and rollback of services
[root@docker] # docker service update-- image 192.168.1.1:5000/httpd:v2 bdqn
/ / smooth updates
[root@docker] # docker service update--image 192.168.1.1:5000/httpd:v3-- update-parallelism 2-- update-delay 1m bdqn
PS: by default, swarm updates only one copy at a time, and there is no wait time between the two copies, so we can use the
-- update-parallelism 2: the number of copies set and updated
-- update-delay: specify the time interval for rolling updates
Docker service rollback bdqn
Roll back: do it.
Ps: note: the rollback operation of docker swarm can only be rolled back to the state of the last operation by default, not continuously. *
After reading the above, do you have any further understanding of the three Musketeers in the docker container? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.
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.