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

Common pitfalls of using React Hooks

React Hooks is a new feature introduced in React ...

Node script realizes automatic sign-in and lottery function

Table of contents 1. Introduction 2. Preparation ...

How to use async and await correctly in JS loops

Table of contents Overview (Loop Mode - Common) D...

Difference between MySQL btree index and hash index

In MySQL, most indexes (such as PRIMARY KEY, UNIQ...

Summary of CSS3 practical methods (recommended)

1. Rounded border: CSS CodeCopy content to clipbo...

MySQL data type optimization principles

MySQL supports many data types, and choosing the ...

Practical operation of using any font in a web page with demonstration

I have done some research on "embedding non-...

Bootstrap 3.0 study notes grid system principle

Through the brief introduction in the previous tw...

How to change the root user's password in MySQL

Method 1: Use the SET PASSWORD command mysql> ...

Summary of using the reduce() method in JS

Table of contents 1. Grammar 2. Examples 3. Other...

HTML+CSS to achieve responsive card hover effect

Table of contents accomplish: Summarize: Not much...

How to create a MySQL database and support Chinese characters

Let's first look at the MySQL official docume...