Linux Enterprise-docker cluster compose and high-availability Docker swarm

Source: Internet
Author: User
Tags python script docker compose docker swarm haproxy

One. Docker Compose

Docker Compose divides the managed containers into three tiers, engineering (project), Services (service), and Containers (CONTAIENR). All files (docker-compose.yml, extends files, or environment variable files, etc.) in the directory under which Docker Compose runs are part of a project, and the current directory name is the same if no specific project name is specified. A project can contain multiple services, each of which defines the image, parameters, and dependencies that the container runs. One service can include multiple container instances, and Docker Compose does not solve the problem of load balancing, so other tools are needed to realize service discovery and load balancing.
Docker Compose is a tool for creating and running multi-container applications. Using Compose first requires writing
The Compose file describes multiple container services and the associations between them, and then launches all the containers by command based on the configuration.
Dockerfile can define a container, and a Compose template file (YAML format) can define an application that contains multiple interrelated containers. The Compose project was written in Python, based on the Docker API we will learn in the following experiment.


Two. Docker Compose configuration test

Configuring the Environment redhat7.2

1. Put docker-compose-linux-x86_64 files under/bin, and do soft links and executable permissions to facilitate the invocation of commands

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/31/7413fd4903f62436355cee16a41a4e63.png "title=" Screenshot from 2017-10-31 10-25-39.png "alt=" 7413fd4903f62436355cee16a41a4e63.png "/>


2. Test import Haproxy and nginx image, do load balancing


3. Write the Compose configuration file under TMP

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/32e65442323707e0c9f00bef6122f7b7.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-09-31.png "alt=" 32e65442323707e0c9f00bef6122f7b7.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/cc4a397e98430b1f57ae03f62809a33b.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-08-12.png "alt=" Cc4a397e98430b1f57ae03f62809a33b.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/059fc8c52c8a1046547ad10ce6430434.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-28-53.png "alt=" 059fc8c52c8a1046547ad10ce6430434.png "/>


4. Creating Backend Services

Web1 for HTTPD,WEB2 and WEB3, respectively, to create a default access directory

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/98a2ca899ca49b5efaad8ef0a0875578.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-16-20.png "alt=" 98a2ca899ca49b5efaad8ef0a0875578.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/299d23c757e83714f9eb2f141d0d131b.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-13-49.png "alt=" 299d23c757e83714f9eb2f141d0d131b.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/6b1170ca6716efe6b5322863078e120d.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-15-04.png "alt=" 6b1170ca6716efe6b5322863078e120d.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/c784882c864dbc52799e36fb4b3766f0.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-15-41.png "alt=" C784882c864dbc52799e36fb4b3766f0.png "/>


5. Set up the configuration installation httpd service and boot httpd service files in the Web1 httpd service

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/4fe49694d16a6ae9dc60fa50b609df64.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-20-57.png "alt=" 4fe49694d16a6ae9dc60fa50b609df64.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/43b20273a6987408a1157ab10e6509ae.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-20-19.png "alt=" 43b20273a6987408a1157ab10e6509ae.png "/>


6. Build Haroxy.cfg Load Balancer profile in Haproxy

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/a8a30407851c3ae7d1ecdba58fa9a524.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-24-16.png "alt=" A8a30407851c3ae7d1ecdba58fa9a524.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/7e1a5c262c363d6bc6ca384ef7609961.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-24-02.png "alt=" 7e1a5c262c363d6bc6ca384ef7609961.png "/>


7. Executing the docker-compose up command in the compose directory will consolidate output from all containers


docker-compose Complete structure

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/3da850dd5a5fa0fcdd3d4ffd9b67db87.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-34-05.png "alt=" 3da850dd5a5fa0fcdd3d4ffd9b67db87.png "/>



650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/31/7a079bb56dfc85202bcbf0587d1c65e7.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-24-44.png "alt=" 7a079bb56dfc85202bcbf0587d1c65e7.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/519923e50c287ab6e24527474d0407f8.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-31-56.png "alt=" 519923e50c287ab6e24527474d0407f8.png "/>


8. Configuration Complete for load balancing

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/84f7b31a79bf62a53ac56db049154e26.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-30-16.png "alt=" 84f7b31a79bf62a53ac56db049154e26.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/666d346464460ecc20c5bf98bbe510e2.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-30-19.png "alt=" 666d346464460ecc20c5bf98bbe510e2.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/c057acc4c881958d6126514554d632fb.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-30-22.png "alt=" C057acc4c881958d6126514554d632fb.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/0474285fe1d60e8f1e83b1e02efdcc78.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-30-25.png "alt=" 0474285fe1d60e8f1e83b1e02efdcc78.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/8160f3b30c3e96320369ad7e338aea29.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-30-49.png "alt=" 8160f3b30c3e96320369ad7e338aea29.png "/>


9. Health Check , close web3, Access normal , restart Web3, service OK

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/31/167d4308f6ce1545e1f8dd95e5b8affc.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-32-24.png "alt=" 167d4308f6ce1545e1f8dd95e5b8affc.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/a8f440b8a093c8b4e16d66cb0f7e23f7.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-32-34.png "alt=" A8f440b8a093c8b4e16d66cb0f7e23f7.png "/>


650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/31/9aa22a18cbd98fb5e21e6f8700eac50e.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-33-01.png "alt=" 9aa22a18cbd98fb5e21e6f8700eac50e.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/47b8e147f8d730078d8434df084a542e.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-33-10.png "alt=" 47b8e147f8d730078d8434df084a542e.png "/>



Three. High availability of load balancer for Docker swarm

Swarm is a relatively simple set of tools that Docker launched in early December 2014 to manage the Docker set
Group, it turns a group of Docker hosts into a single, virtual host. Swarm using the standard Docker API
Interface as its front-end access entry, in other words, various forms of Docker client (Docker client in Go, Docker_py,docker, etc.) can communicate directly with Swarm. Swarm almost all in the Go language to complete development. Swarm Deamon is just a scheduler (Scheduler) plus router (router), Swarm itself does not run the container, it just accepts requests sent by the Docker client, dispatches the appropriate node to run the container, which means that even Swarm For some reason, the nodes in the cluster will also run as usual, and when Swarm resumes running, it collects the rebuilt cluster information.


1. Configuring the Environment

redhat7.2,7.2 comes with swarm tools

Server1 Master

Server2 from

Server3 from


2. Installation

Server1,server2,server3 installing Docker and starting the service

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/f7bbcc9ca98832770f106329c3a99c6a.png "style=" float: none; "Title=" screenshot from 2017-10-31 11-57-34.png "alt=" F7bbcc9ca98832770f106329c3a99c6a.png "/>


3. Create a cluster

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/31/60c0c991367ec42c827d791e803d1725.png "title=" Screenshot from 2017-10-31 13-56-14.png "alt=" 60c0c991367ec42c827d791e803d1725.png "/>

Copy the Docker swarm join to 172.25.29.1:2377 and copy them into the shell of Server2 and Server3, respectively.

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/1d0d057174f80fd24987c465ab45b653.png "style=" float: none; "Title=" screenshot from 2017-10-31 14-25-06.png "alt=" 1d0d057174f80fd24987c465ab45b653.png "/>


650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/7c555a99b8ed8ee109f93eb37bd316d0.png "style=" float: none; "Title=" screenshot from 2017-10-31 14-25-23.png "alt=" 7c555a99b8ed8ee109f93eb37bd316d0.png "/>


View node status on Server1 after completion, cluster configuration complete

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/50cfdb119be088c5bd3aeec20726a570.png "style=" float: none; "Title=" screenshot from 2017-10-31 14-25-29.png "alt=" 50cfdb119be088c5bd3aeec20726a570.png "/>


4.Docker Swarm load balancing High availability experiment

Server1,server2,server3 Import Nginx Image

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/918be8c43882df25eb86228b6beabd53.png "style=" float: none; "Title=" screenshot from 2017-10-31 14-28-20.png "alt=" 918be8c43882df25eb86228b6beabd53.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/7524f8cc64ec3dd703b3a2c55f5f3883.png "style=" float: none; "Title=" screenshot from 2017-10-31 14-28-24.png "alt=" 7524f8cc64ec3dd703b3a2c55f5f3883.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/8b0fee32afbbd765f3c1cf6fc9c55987.png "style=" float: none; "Title=" screenshot from 2017-10-31 14-28-29.png "alt=" 8b0fee32afbbd765f3c1cf6fc9c55987.png "/>



5. Import flask frame Mirror, Server1,server2,server3

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/40dafd535025fd62e60325c6a3ab395d.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-24-51.png "alt=" 40dafd535025fd62e60325c6a3ab395d.png "/>


Due to load balancing, host names need to be displayed on Nginx Web pages to differentiate load balancing on different backend

A Python-written statement that displays the hostname, importing the flask and OS

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/31/2a03c57860748dcdbfd47fbd3b3063d4.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-21-04.png "alt=" 2a03c57860748dcdbfd47fbd3b3063d4.png "/>



6.server1 single-machine run read Python file, see if you can see the host name

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

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/02e2472be81236b99965023dfe1c93a4.png "title=" Screenshot from 2017-10-31 15-25-02.png "alt=" 02e2472be81236b99965023dfe1c93a4.png "/>


Commit Save

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/2baa516ef8f9df8b4485fc8ae15d6884.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-26-53.png "alt=" 2baa516ef8f9df8b4485fc8ae15d6884.png "/>


Test whether the Python script that writes the host name is displayed as normal

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/a7bd98a128e5cc6444cf09c45d2c7fad.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-29-59.png "alt=" A7bd98a128e5cc6444cf09c45d2c7fad.png "/>


can display container name, test normal, can encapsulate commit

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/3e161054b9b0497fe09bcc377a9eec7e.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-30-06.png "alt=" 3e161054b9b0497fe09bcc377a9eec7e.png "/>

7. Export the mirrored Python:demo image with the demo.py script added to the test to Demo.tar

Close the container and export

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/31/e589b625d017becc409d31d5d79f38b8.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-41-21.png "alt=" E589b625d017becc409d31d5d79f38b8.png "/>


8.server2 and Server3 Import flask and demo images respectively

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/418e92b07abcdd0bbdc8713b5b1e6941.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-41-04.png "alt=" 418e92b07abcdd0bbdc8713b5b1e6941.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/eb3f9a890e00de4bb634e31de41cd370.png "style=" float: none; "Title=" screenshot from 2017-10-31 15-41-11.png "alt=" Eb3f9a890e00de4bb634e31de41cd370.png "/>



9. Create a cluster named Flask and start 3 backend service nodes to read the demo.py script under Python

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/a3ffeb895fee1aac64311d71d7f86dd0.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-40-43.png "alt=" A3ffeb895fee1aac64311d71d7f86dd0.png "/>



10. Browser Test after launch

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/90effcdde72e061baf6fc4358017b423.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-41-12.png "alt=" 90effcdde72e061baf6fc4358017b423.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/ecf58364d6196e36f048f34bfd94b911.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-41-18.png "alt=" Ecf58364d6196e36f048f34bfd94b911.png "/>

3 Back-end service polling

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/31/f3040cda7f64e9892d28ec6b583cb712.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-41-26.png "alt=" F3040cda7f64e9892d28ec6b583cb712.png "/>


11. Turn back-end services into 8 nodes

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/31/7867c9e10ee0e7f6ab7d535dc75090aa.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-42-35.png "alt=" 7867c9e10ee0e7f6ab7d535dc75090aa.png "/>


Display polling

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/31/6f8ab379cf2425816042481f8f1ad0a2.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-42-52.png "alt=" 6f8ab379cf2425816042481f8f1ad0a2.png "/>



Four. Docker swarm Visual Web monitoring interface

1. Import Visualizer image

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/31/6680fafde6b696fdf700028060ab094f.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-47-37.png "alt=" 6680fafde6b696fdf700028060ab094f.png "/>


2. Create

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/31/ad9bff7c8dd26e88df65bfea53cec5a0.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-50-27.png "alt=" Ad9bff7c8dd26e88df65bfea53cec5a0.png "/>

View Container

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/31/7fbdbb259cc9ce41dae7626340bd944e.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-50-41.png "alt=" 7fbdbb259cc9ce41dae7626340bd944e.png "/>


3. Browser input address, view monitoring interface

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/31/d902d1aa1560cc884f4656000d7b1fcf.png "style=" float: none; "Title=" screenshot from 2017-10-31 16-57-58.png "alt=" D902d1aa1560cc884f4656000d7b1fcf.png "/>



4. Timed Updates

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/bbfa179374f849d754245deae56d9018.png "style=" float: none; "Title=" screenshot from 2017-10-31 17-21-36.png "alt=" Bbfa179374f849d754245deae56d9018.png "/>

Update-parallelism 2 per update 2

Update-delay 10s updated 1 times every 10 seconds

Nginx Update Nginx Image every time

To update a cluster named flask


Graphic Change Image:nginx

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/31/a245cbaa2fc19e269957f8f0cee38391.png "style=" float: none; "Title=" screenshot from 2017-10-31 17-21-05.png "alt=" A245cbaa2fc19e269957f8f0cee38391.png "/>



Linux Enterprise-docker cluster compose and high-availability Docker swarm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.