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

Detailed explanation of High availability configuration of docker

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Docker Compose

Docker Compose divides the managed containers into three layers, engineering (project), service (service) and container (contaienr). All the files (docker-compose.yml, extends files or environment variable files, etc.) under the directory where Docker Compose runs constitute a project, which is the current directory name if no special project name is specified. A project can contain multiple services, and each service defines the images, parameters, and dependencies of the container. A service can include multiple container instances. Docker Compose does not solve the problem of load balancing, so you need to use other tools to achieve service discovery and load balancing.

Install Docker Compose

Get docker-compose-linux-x86_64 and place it in the / bin directory, make soft links and add executable permissions

Chmod + x docker-compose-linux-x86_64ln-s docker-compose-linux-x86_64 docker-compose

Import haproxy and nginx to facilitate subsequent load balancing testing

Docker load-i haproxydocker load-I nginx

Write the compose configuration file in / tmp/

[root@foundation50 compose] # vim docker-compose.yml

Create a file to install the httpd service and start httpd in the web1 httpd service

[root@foundation50 compose] # vim web1/DockerfileFROM rhel7:v1 EXPOSE 80 RUN yum install-y httpd ADD index.html / var/www/html CMD ["/ usr/sbin/httpd", "- D", "FOREGROUND"]

Create a haproxy.cfg configuration file in haproxy

View

View statistics for haproxy

Visit 172.25.50.1

Health examination

Close web3

Docker swarm

Prepare three virtual machines

Server1,server2,server3 install docker and start the service

You need to run docker swarm init on one node, and then run the join command on the other node

[root@server1] # docker swarm init [root@server2~] # docker swarm join\ >-- tokenSWMTKN-1-51igcdpg4cbgaokq535qis01osel396of153sdlp8k0ljn0rou-2m9sltwkc4uq1vfmp79ous0e4\ > 172.25.50.2Viru 2377 This node joined a swarm as a worker.

View node status on server1

Nginx has been imported earlier, and then flsak has been imported into three machines

[root@server1 ~] # docker load-I flask.tar [root@server2 ~] # docker load-I flask.tar [root@server3 ~] # docker load-I flask.tar

To distinguish between different backend load balancers, a statement showing the hostname written by python is used to import flask and os

Open the flask image and put the demo.py script under root

Submit

[root@server1 python] # docker commit vm1 python:demo

Create a cluster named flask and start three back-end service nodes to read the demo.py script under python

test

[root@foundation50 docker] # for i in {1.. 10}: do curl-w "\ n" http://172.25.50.1;done

Because there are three servers, the polling is completed every three times, and the load balance is realized.

Docker swarm visual web monitoring interface

Import the image and create

[root@server1] # docker load-I visualizer.tar [root@server1] # docker service create-- name=viz-- publish=8080:8080/tcp-- constrain=node.role==manager-- mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock dockersamples/visualizer

View the monitoring page

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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