Detailed explanation of docker's high availability configuration

Detailed explanation of docker's high availability configuration

Docker Compose

Docker Compose divides the managed containers into three layers: project, service, and container. All files in the directory where Docker Compose is running (docker-compose.yml, extends files or environment variable files, etc.) form a project. If no special project name is specified, the current directory name is used. A project can contain multiple services, and each service defines the image, parameters, and dependencies of the container running. A service can include multiple container instances. Docker Compose does not solve the problem of load balancing, so other tools are needed to achieve service discovery and load balancing.

Install Docker Compose

Get docker-compose-linux-x86_64 and put it in the /bin directory, make a soft link and add executable permissions

chmod +x docker-compose-linux-x86_64
ln -s docker-compose-linux-x86_64 docker-compose

Import haproxy and nginx to facilitate subsequent load balancing tests

docker load -i haproxy
docker load -i nginx

Write the compose configuration file in /tmp/

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


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

[root@foundation50 compose]#vim web1/Dockerfile
FROM 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

Check

View haproxy statistics

Visit 172.25.50.1

Health Check

Shutdown web3


docker swarm

Prepare three virtual machines

Install Docker on server1, server2, and server3 and start the service

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

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

Check the node status on server1


Nginx has been imported before, and then flsak is imported to 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 the load balancing of different backends, a statement showing the host name is written in Python and imported into 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, start three backend service nodes, and 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, polling is completed every three times, achieving load balancing

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 monitoring page

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  How to modify the initial password of MySQL on MAC

>>:  Summary of four ways to loop through an array in JS

Recommend

Server concurrency estimation formula and calculation method

Recently, I need to stress test the server again....

MySQL multi-table join introductory tutorial

Connections can be used to query, update, and est...

vue-table implements adding and deleting

This article example shares the specific code for...

How to get/calculate the offset of a page element using JavaScript

question By clicking a control, a floating layer ...

A practical record of troubleshooting a surge in Redis connections in Docker

On Saturday, the redis server on the production s...

Reasons why MySQL kill cannot kill threads

Table of contents background Problem Description ...

mysql 8.0.19 win10 quick installation tutorial

This tutorial shares the installation tutorial of...

Vue.js cloud storage realizes image upload function

Preface Tip: The following is the main content of...

MySQL Packet for query is too large problem and solution

Problem description: Error message: Caused by: co...

Things to note when writing self-closing XHTML tags

The img tag in XHTML is so-called self-closing, w...

MySQL 8.0.12 installation steps and basic usage tutorial under Windows

This article shares the installation steps and us...

MySQL 8.0.17 installation and usage tutorial diagram

Written in front In the past and in the current p...

Detailed explanation of HTML basics (Part 2)

1. List The list ul container is loaded with a fo...

MySQL query_cache_type parameter and usage details

The purpose of setting up MySQL query cache is: C...