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

How to use jsonp in vue

Table of contents 1. Introduction 2. Installation...

MySQL NULL data conversion method (must read)

When using MySQL to query the database and execut...

Detailed tutorial on downloading mysql on Windows 10

MySQL versions are divided into Enterprise Editio...

JavaScript ECharts Usage Explanation

I used ECharts when doing a project before. Today...

In-depth explanation of Session and Cookie in Tomcat

Preface HTTP is a stateless communication protoco...

A few things about favicon.ico (it’s best to put it in the root directory)

Open any web page: for example, http://www.baidu....

How to implement Ajax concurrent request control based on JS

Table of contents Preface Ajax serial and paralle...

Solution to Vue data assignment problem

Let me summarize a problem that I have encountere...

Detailed explanation of the use of Linux time command

1. Command Introduction time is used to count the...

How to change the domestic image source for Docker

Configure the accelerator for the Docker daemon S...

Detailed explanation of react setState

Table of contents Is setState synchronous or asyn...

Instructions for using JSON operation functions in Mysql5.7

Preface JSON is a lightweight data exchange forma...

Document Object Model (DOM) in JavaScript

Table of contents 1. What is DOM 2. Select elemen...

Vue template compilation details

Table of contents 1. parse 1.1 Rules for intercep...

Detailed introduction of Chrome developer tools-timeline

1. Overview Users expect the web applications the...