The content of the invention
To overcome the shortcomings of that above-mentioned prior art is present, the purpose of the present invention is to provide a kind of Docker containers actively to bearBalancer and method are carried, to realize being actively discovered and login mechanism in real time, and general load equalizer is used, is DockerContainer cluster provides service, it is ensured that to application without intrusion, facilitate system to carry out containerization transformation.
It is that, up to above and other purpose, the present invention proposes a kind of Docker containers active load balancer, including:
Mirror image modular converter, for providing the Docker foundation images comprising application manager and being converted to pending applicationDocker mirror images;
Application manager, for starting the Docker mirror images, and according to default application message, parses and performs the pending applicationStartup order, and send registration request, the application is registered to distributed coordination server;
Distributed coordination server, for disposing distributed coordination service;
Detector, for monitoring the application situation of change on the distributed coordination server, will send out using situation of changeDeliver to load balancing proxy server;
Load balancing proxy server, by the application situation of change is according to the configuration data of configuration template conversion certain format and holdsOK, and it is configured to Universal load balanced device;
Universal load balanced device, for disposing Universal load balancing service.
Further, the mirror image modular converter includes:
Foundation image, the Docker that the basic environment needed for depositing the application manager and pending application in advance buildsMirror image, and using this mirror image as the foundation image of pending application, and it is stored in mirror image warehouse;
Order receiver module, the identification information for receiving the pending application;
Mirror image builds module, builds pending application mirror image by Dockerfile, and be uploaded to mirror image warehouse.
Further, the application manager includes:
Parameter analysis of electrochemical module, for parsing default application message;
Command execution module, order is performed for receiving the application that the Parameter analysis of electrochemical module is parsed, and is performed this and is ordered and obtainCommand execution results, if if implementing result is normal, calling and applying Registering modules;
Using Registering modules, for the state letter for obtaining the Parameter analysis of electrochemical module data for parsing and obtaining pending applicationCease, and interim conversation is set up with the distributed coordination server and link, the status details of the application are registered to distribution associationAdjust server;
Health examination module, for the health condition according to default health examination order poll application, and result is notified to be somebody's turn to doUsing Registering modules.
Further, when the Docker containers are registered to the distributed coordination server by this using Registering modules,Judge the distributed coordination server directory whether there is this using corresponding catalogue, if nothing, in distributed coordination server woundBuild new catalogue and simultaneously in one new node of the directory creating.
Further, the detector includes:
Module is monitored, for monitoring the application situation of change on the distributed coordination server, if using correspondingDocker container instance states change, and trigger the first sending module;
First sending module, for that will be sent to load balancing proxy server using situation of change.
Further, the load balancing proxy server includes:
First receiver module, is attached with first sending module and maintains heartbeat, first receiver module receive this firstThe instruction that sending module is sent, and call data resolution module;
Data resolution module, the format analysis instruction according to configuration template module now, and incoming second order performs mouldBlock;
Configuration template module, its masterplate data are different according to the load equalizer that load balancing proxy server is acted on behalf of;
Second command execution module, writes data into the Universal load equalizer configuration file directory, performs the Universal load equalThe reset command of weighing apparatus.
To reach above-mentioned purpose, the present invention also provides a kind of Docker containers active load equalization methods, including following stepSuddenly:
Step one, receives pending application file, presets pending application details;
Step 2, Docker mirror images are converted to by the pending application file;
Step 3, orders in the execution Docker mirror images using startup;
Step 4, sends registration request, and the application is registered into distributed coordination server;
Step 5, obtains the log-on message from distributed coordination server, obtains the change number of application example correspondence containerAccording to, and the data are parsed, by configuration template, more new configuration file to Universal load balanced device.
Further, step 5 is further included:
The directory node in distributed coordination device is applied in monitoring, and the change information of directory node is sent into load balancing agencyDevice;
Change information is synchronized to by Universal load balanced device according to configuration template.
Further, in step 2, the identification information of the pending application file is write according to specificationDockerfile, pending application mirror image is built by pending application foundation mirror image with pending application by Dockerfile.
Further, in step 4, the Docker containers of the pending application are maintained with the distributed coordination serverInterim conversation, when application is abnormal, disconnection immediately is linked with the distributed coordination server, and is automatically exited from.
Compared with prior art, a kind of Docker containers active load balancer of the invention and method, are managed by applicationReason device initiates to connect and carry out to register application container information to distributed coordination server, and real-time to application container health and fitness informationMonitoring, and active synchronization feeds back to distributed coordination server, using detector according to the information master of distributed coordination serverIt is dynamic to update to load equalizer, Docker containers are successfully mounted to load equalizer, make full use of Universal load balanced deviceRipe production and O&M experience, for tradition application Docker containerization transformations, are effectively reduced improvement cost, the present invention byContainer actively initiates to connect and registered to load equalizer, and using mature and stable load equalizer, the process is without pre-First configure equilibrium allocation file and load equalizer need not be restarted, be automatically obtained load balancing, overcome current containerMiddle load-balancing method is difficult in adapt to be used to provide asking for back-end services, dynamic change container cluster in cloud computing systemTopic.
Specific embodiment
Below by way of specific instantiation and embodiments of the present invention are described with reference to the drawings, those skilled in the art canFurther advantage of the invention and effect are understood by content disclosed in the present specification easily.The present invention also can be different by otherInstantiation implemented or applied, the various details in this specification also can based on different viewpoints with application, without departing substantially fromVarious modifications and change are carried out under spirit of the invention.
Fig. 1 is a kind of system architecture diagram of Docker containers active load balancer of first embodiment of the invention.Such asShown in Fig. 1, a kind of Docker containers active load balancer of the invention, including:Mirror image modular converter 101, application manager102nd, distributed coordination server 103, detector 104, load balancing proxy server 105 and Universal load balanced device 106.
Mirror image modular converter 101, for providing the Docker foundation images comprising application manager and by pending applicationBe converted to Docker mirror images.
Specifically, mirror image modular converter 101 is the Docker environment of deployment success, it include foundation image 301,Order receiver module 302 and mirror image build module 303, and application manager has been housed in advance with pending application in the moduleThe Docker mirror images that the basic environment of needs builds, and using this mirror image as pending application foundation image 301, while also depositingIt is placed on mirror image warehouse.Pending application will be stored in mirror image conversion equipment using modes such as ftp, tftp, scp, wget correspondingCatalogue.Order receiver module 302 receives user input by the identification information of pending application, and the mark of the pending application is believedBreath including application name, using starting, cease and desist order, port, using information such as additional information and health examination orders, and parseWith the local Dockerfile masterplates that prestore, new Dockerfile is formed, mirror image is built module 303 and built by DockerfilePending application mirror image, and mirror image warehouse is uploaded to, now this at least includes application manager, pending application using mirror imageAnd corresponding parameter.
Application manager 102, for starting the Docker mirror images, and according to default application message, parses pending answeringStartup order, and the order is performed, and registration request is sent, the application is registered to distributed coordination server.
Specifically, application manager 102 is including Parameter analysis of electrochemical module 311, command execution module 312, using Registering modules313rd, health examination module 314.Wherein Parameter analysis of electrochemical module 311 is responsible for the default application message of parsing, the default application letterBreath includes:Application name, using starting, cease and desist order, port, using additional information etc., will include that application be opened using order is performedIt is dynamic to order, command execution module 312 is passed to using ceasing and desisting order;Command execution module 312, for receiving Parameter analysis of electrochemical module311 applications for parsing perform order, perform this and order and obtain command execution results, if if implementing result is normal, callingUsing Registering modules 313;Got parms the data and obtain pending that parsing module 311 parses using Registering modules 313The status information of application, and set up interim conversation with distributed coordination server 103 and link, by the status details of the application:HoldDevice status information, container IP, port, application name, distributed coordination server 103 is registered to using additional information, when find shouldWith the abnormal phenomenons such as machine of such as delaying, automatic disconnection links with distributed coordination server 103.Wherein, when the Docker shouldDuring with starting, the Parameter analysis of electrochemical module 312 parses the presupposed information of acted on behalf of application, call instruction performing module 312Perform application and start order, and the distributed coordination server 103 is notified by application Registering modules 313, in the file meshRecord is lower to be created and the corresponding file of the pending application.After a Docker container for performing application starts successfully,Using Registering modules 313 will using application message be registered to distributed coordination server 103 correspondence application under file asApplication node example.
In detail, when Docker containers are registered to distributed coordination server 103 by application Registering modules 313, sentenceThe disconnected catalogue of distributed coordination server 103 whether there is this using corresponding catalogue, if nothing, in distributed coordination server 103Create new catalogue and simultaneously in one new node of the directory creating, the IP and application port of container are the name of the nodeClaim.When the application has new Docker examples to produce, new Docker examples will be all registered under the catalogue.When the application certainIndividual Docker examples are delayed machine, then application Registering modules 313 disconnect the connection with distributed coordination server 103, same time-division automaticallyCloth coordination service device 103 deletes the log-on message of the Docker examples.
Health examination module 314 is main and according to the health condition of default health examination order poll application, and will knotFruit notifies to apply Registering modules 313.Health examination module 314 mainly checks for the container that fails, and failure container can beFinger can not provide the container of normal service.For example, when the detection container of health examination module 314 there occurs abnormal such as container and healthCheck module 314 can not healthy heartbeat, container process phenomenon, the i.e. container such as surprisingly stop service can not being provided, now can be withThink that the container is failure container.Optionally, for any one container, the container and health examination module 314 can be monitoredCommunication connection whether disconnect, if health examination module 314 monitor the container for failure container.Health examination module 314 is led toKnow using Registering modules 313 will automatically with the break link of distributed coordination server 103 so that distributed coordination server103 delete the failure container node.
Distributed coordination server 103, for disposing distributed coordination service.In the specific embodiment of the invention, distributionFormula coordination service device 103 can have one or more, when there is multiple distributed coordination servers 103, the plurality of distributed associationAdjusting server 103 is used to form distributed coordination service group, and can be selected from the plurality of distributed coordination server 103One leader (leader), wherein, distributed coordination server 103 is used to dispose distributed coordination service.In the present embodimentZookeeper is used as distributed coordination server for deployment, and zookeeper is a distributed coordination server increased income.It isOne software that Consistency service is provided for Distributed Application, there is provided function include:Configuring maintenance, domain name service, distributionSynchronous, group service etc..It is specifically intended that when the modification of the data stored in zookeeper directory nodes, child node catalogueChange etc., once change can notify to set the client for monitoring, this function is zookeeper most important for applicationCharacteristic, the function that can be realized by this characteristic includes the centralized management of configuration, cluster management, distributed lock etc..Herein,Main configuring maintenance and distributed synchronization this two functions of having used in zookeeper, wherein, in distributed coordination clothesA file directory is safeguarded in business device 103, is existed and the multiple application corresponding file of difference in this document catalogue.That is,There are multiple files under this document catalogue, each file correspondence one is applied, at least one node under each file,Each node one Docker container instance of correspondence.Such that it is able to manage application by the file and node of zookeeperAnd the Docker examples of application, it is possible to realize to Docker container state change managements, that is, realize to Docker containersIt was found that.
For example, default/apps/catalog is the parent directory of all applications, if using entitled in presupposed informationHelloworld, port is 8080, application one Docker example of correspondence, and container IP is 172.17.0.2, then shouldCatalogue with correspondence zookeeper is /apps/catalog/helloworld, the corresponding zookeeper sections of the Docker examplesPoint is /apps/catalog/helloworld/172.17.0.2:8080, if this application again increase newly a Docker example andDocker containers IP is 172.17.0.3, then this is /apps/catalog/helloworld/ using zookeeper nodal directories172.17.0.2:8080 and/apps/catalog/helloworld/172.17.0.3:8080.If the IP is172.17.0.3 Docker containers are delayed machine, then this is changed into/apps/catalog/helloworld/ using corresponding node172.17.0.2:8080.By means of the file directory and node and application and the corresponding relation of Docker examples of zookeeper,Application one catalogue of correspondence, Docker containers one corresponding relation for directory node of correspondence can be realized.
Detector 104, for corresponding all application file folders in monitoring distributed coordination service device 103.This document is pressed from both sidesFolder Name correspondence Apply Names, unique one file with the entitled Folder Name of application of correspondence of each application.Detector 104 includes monitoring the sending module of module 331 and first, in this specific embodiment, is starting pending applicationAfter Docker examples, the Docker example details can be registered to the distributed coordination server 103, monitor module 331 and examineMeasure and there occurs change using catalogue/apps/catalog, and read using the node details of catalogue/apps/catalog, byFirst sending module 332 sends corresponding instruction notification load balancing proxy server 105 and increases an application example information newly, to generalLoad equalizer 106 updates configuration.Alternatively, when one of Docker examples of pending application stop or machine of delaying, healthCheck that module 314 detects the example and exception occurs, notify that application Registering modules 313 disconnect and distributed coordination server 103Link, distributed coordination server 103 deletes this directory node information, now monitors module 331 and is immediately detected and applies meshRecord/apps/catalog catalogues there occurs change, and notification payload equilibrium proxy server 105 deletes one, to Universal load balanced device106 update configuration.
Load balancing proxy server 105, for by configuration template, more new configuration file to Universal load balanced device 106.
Specifically, load balancing proxy server 105 includes the first receiver module 341, data resolution module 342, configuration templateModule 343, the second command execution module 344.Load balancing proxy server 105 and the deployment 106 of Universal load balanced device are in same clothesBusiness device.First receiver module 341 is attached and maintains heartbeat by Transmission Control Protocol and the first sending module 332, and first receives mouldBlock 341 receives the instruction that the first sending module 332 is sent, and calls data resolution module 342.The basis of data resolution module 342The format analysis of the configuration template module 343 now instructions, masterplate data are according to load balancing generation in configuration template module 343The load equalizer acted on behalf of of reason device 105 is different, and masterplate data are had nothing in common with each other, such as nginx applicable configuration and lvs,Keepalived applicable configuration is different, and data resolution module 342 press masterplate data and will be successfully put into and face after instruction parsesWhen region of memory, call the second command execution module 344.Second command execution module 344 is preset Universal load balanced device 106 and is matched somebody with somebodyPut file path, startup, stopping, reset command and assign the control authority of execution Universal load balanced device 106, when data parse mouldAfter incoming second command execution module 344 of data that block 342 will be parsed, the second command execution module 344 reads above-mentioned interimRegion of memory writes data into the configuration file catalogue of Universal load balanced device 106, and perform Universal load balanced device 106 restarts lifeOrder.
Universal load balanced device 106, for disposing Universal load balancing service.In the present embodiment, Universal load is balancedDevice 106 may be located in independent server, it is also possible in the server cluster being made up of some servers.Such asNginx and lvs are the soft load equalizers increased income, and current industry has accumulated more knowhow, research and development, fortune for enterpriseDimension and learning cost are substantially reduced.Nginx and lvs differences, lvs have when four laminar flow amounts is processed significant performance butHigher to network requirement, nginx is usually used in seven layers of load balancing, relatively low to network environment requirement.Because Universal load is balancedDevice 106 is familiar to the person skilled in the art, be will not be repeated here.
In the present invention, application manager can also operate in non-Docker containers environment with pending application, or holdThe load balancing of application cluster is realized under device environment together.A kind of Docker for being illustrated in figure 2 second embodiment of the invention holdsThe system architecture diagram of device active load device in a balanced way, wherein, application manager 203 pre-sets application message:Application name, shouldWith starting, cease and desist order, port, using additional information etc., after application manager 203 starts, should by the parsing of Parameter analysis of electrochemical moduleWith details, and start it is pending apply 204, after pending application 204 starts successfully, will be using reality by application manager 203The status information of example, host IP, port, application name, distributed coordination server 205 is registered to using additional information.It is differentBe:1st, application example becomes host IP by container IP, and 2, the application example port of same host operation can not be identical,The processing procedure of each module is basically identical with first embodiment afterwards, repeats no more.
The step of Fig. 3 is a kind of Docker containers active load equalization methods of third embodiment of the invention flow chart.Such asShown in Fig. 3, a kind of Docker containers active load equalization methods of the invention comprise the following steps:
Step 301, receives pending application file, presets pending application details.Wherein described pending application details includeUsing start order, cease and desist order, Apply Names, version number, using additional information(TCP/HTTP), and application end messageBreath.
Step 302, Docker mirror images are converted to by the pending application file.Specifically, by pending application fileIdentification information, such as Apply Names, using start order, cease and desist order, port, using additional information and health examination lifeOrder etc. writes Dockerfile according to specification, and pending application foundation mirror image is built with pending application by DockerfilePending application mirror image, i.e. Docker mirror images.
Step 303, orders in the execution Docker mirror images using startup.That is, when pending application has succeededWhen being configured to Docker mirror images, start the mirror image, and according to default application message, parse the startup order of pending application,And perform the order.
Step 304, sends registration request, and the application is registered into distributed coordination server.Taken in the registration requestWith the container IP of application message in the Docker containers, application port information, Apply Names, using additional information etc..In the specific embodiment of the invention, now distributed coordination server creates a catalogue with application name as title, and in the meshRecord is lower to create a node, the wherein entitled container IP of the node and port, such as 172.17.0.2:8080, other information is as answeredStored in the node with additional information.The Docker containers of pending application remain interim with distributed coordination serverSession sessions, when application is abnormal, disconnection immediately is linked with distributed coordination server, and is automatically exited from.Due to pointCloth coordination service uses interim session sessions, the interim conversation once disconnecting, and distributed coordination server is simultaneously deleted at onceExcept all information of the node.
Step 305, obtains the log-on message, the i.e. change of application example correspondence container from distributed coordination serverData, and the data are parsed, by configuration template, more new configuration file to load equalizer.Specifically, step 305Further include:
The directory node in distributed coordination device is applied in step S1, monitoring, and the change information of node is sent into load balancingProxy server.Learnt according to above-mentioned steps S304, it is a catalogue that newly-increased application has succeeded in distributed coordination server registration, mainThe dynamic nodal information read under the catalogue, once having newly-increased Node registry under detecting the catalogue, sends instructions to downstream module i.e.Load balancing proxy server, the instruction carries directory name(That is to say application name), all nodenames under the catalogue(That is to say sectionPoint instance address)And additional information;
Step S2, load equalizer, such as nginx, lvs are synchronized to according to configuration template by change information.According to above-mentioned steps S1Learn, the instruction that load equalizer proxy server receiving step S1 sends is included applies lower all nodal informations, then load balancingProxy server is the parameter for being converted into load equalizer identification according to configuration template relevant parameter, and writes corresponding configuration file,Wherein load balancing proxy server should preset load equalizer configuration file path, startup, stopping, reset command.Have in the present inventionIn body embodiment, the configuration template respectively has difference according to the load equalizer selected.
A kind of flow chart of Docker containers active load equalization methods that Fig. 4 is provided for the specific embodiment of the invention, such asShown in Fig. 4, the method can include:
Step S401, presets application message, is a new mirror image by pending application build.Specifically, by pending applicationIdentification information:Application name, using starting, cease and desist order, port, using additional information and health examination order according to specificationWrite-in Dockerfile, pending application mirror is built by pending application foundation mirror image with pending application by DockerfilePicture.
Step S402, disposes distributed coordination server, such as zookeeper in distributed coordination server.It is distributedCoordination service device can be single node or cluster mode.Especially, when such as catalogue, son once occurs in distributed coordination serverNode, data etc. change, and can monitor client with proactive notification, can realize occurring when application example node by this characteristicChange can immediately notify that downstream module is processed in time.
Step S403, described in above-mentioned steps S401, pending application is successfully configured to Docker mirror images, starts the mirrorPicture, and according to default application message, the startup order of pending application is parsed, and the order is performed, then answered according to defaultInspected periodically with health examination sentence and apply health degree.
Step S404, after pending application success starts, the status details of the application is included:Container state information,Container IP, port, application name, distributed coordination service that above-mentioned steps S402 deployment success is registered to using additional informationDevice, now distributed coordination server creates a catalogue with application name as title, and a node is created under the catalogue, itsIn the node entitled container IP and port, such as 172.17.0.2:8080, other information such as application additional information storage is at thisIn node.The Docker containers of pending application maintain interim session sessions with distributed coordination server, when application is differentChang Shi, immediately disconnection is linked with distributed coordination server, and is automatically exited from.Due to using interim with distributed coordination serviceSession sessions, once disconnecting, distributed coordination server simultaneously deletes all information of the node to the interim conversation at once.
Step S405, in the deployment load balancing service of Universal load balanced device such as nginx, lvs.Load equalizer and eachNode, each node container network ensure interconnect, the network plan based on container intercommunication can using port mapping, directlyPath or the mode of overlay network, the network plan is familiar to the person skilled in the art, be will not be repeated here.
The directory node in distributed coordination device is applied in step S406, monitoring, and the change information of node is sent to negativeCarry balanced proxy server.Learnt according to above-mentioned steps S404, it is one that newly-increased application has succeeded in distributed coordination server registrationCatalogue, actively reads the nodal information under the catalogue, once having newly-increased Node registry under detecting the catalogue, sends instructions to downstreamModule is load balancing proxy server, and the instruction carries directory name(That is to say application name), all nodenames under the catalogue(It is node instance address)And additional information.
Step S407, load equalizer such as nginx, lvs are synchronized to according to configuration template by change information.According to above-mentioned stepRapid S406 learns that the instruction that load equalizer proxy server receiving step S406 sends is included applies lower all nodal informations, thenLoad balancing proxy server is to be converted into the parameter that load equalizer is recognized according to configuration template relevant parameter, and write-in is matched somebody with somebody accordinglyPut file.Wherein load balancing proxy server should preset load equalizer configuration file path, startup, stopping, reset command.
The above method makes to apply the ruuning situation moment under Docker environment to feed back on SiteServer LBS, by adoptingWith the mechanism of general load equalizer and Active Registration, so as to by application call person from changeable, complicated Docker containers groundLocation is converted to and accesses fixed load equalizer address, whole-process automatic discovery, automatic registration, to caller unaware, Er QieyingCan also apply equally applicable under host or virtual machine environment with pending simultaneously with manager.
Relative and above-described embodiment, further, in the present embodiment in S401 in the device in advance by Program ManagerWith pending application need basic environment be configured to new Docker mirror images as pending application foundation image step itIt is preceding also to include:The basic environment that pending application needs is obtained from mirror image warehouse.Specifically, mirror image warehouse is used for memory imageFile, including basic environment, the foundation image of pending application, the pending application mirror image that pending application needs are new to buildMirror image is unifiedly stored to mirror image warehouse.In the present embodiment, mirror image conversion equipment, each node are connected with the communication of mirror image Warehouse Establishing.
In sum, a kind of Docker containers active load balancer of the invention and method, using application manager masterIt is dynamic to register container change information, while interim conversation mechanism is used using detector and distributed coordination server, without logicalHeartbeat mode is crossed in real time to monitor distributed coordination server, once container finds change, by using load balancing generationThe change information of the container is write Universal load balanced device by reason device, application containerization transformation is present invention can be suitably applied to, to existingHave using without constraint and limitation;Container situation of change can in time be monitored without using heartbeat mechanism, so as to avoid heartbeatThe timeout issue for causing;From the soft load equalizer of universal industrialization, to study, relatively low using the cost requirement of, O&M, saveThe research and development of enterprise and O&M cost, also illustrate under non-container environment in the embodiment of the present invention, will be treated by application managerThe situation of change for performing application is synchronized on load equalizer, and satisfaction is applied the need for isomerous environment is run.
The above-described embodiments merely illustrate the principles and effects of the present invention, not for the limitation present invention.AnyArt personnel can be modified above-described embodiment and are changed under without prejudice to spirit and scope of the invention.Therefore,The scope of the present invention, should be as listed by claims.