CN106790595B - Docker container active load balancing device and method - Google Patents

Docker container active load balancing device and method Download PDF

Info

Publication number
CN106790595B
CN106790595B CN201611241839.XA CN201611241839A CN106790595B CN 106790595 B CN106790595 B CN 106790595B CN 201611241839 A CN201611241839 A CN 201611241839A CN 106790595 B CN106790595 B CN 106790595B
Authority
CN
China
Prior art keywords
application
module
distributed coordination
docker
executed
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611241839.XA
Other languages
Chinese (zh)
Other versions
CN106790595A (en
Inventor
胡中明
胡忠顺
徐玉清
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Ideal Information Industry Group Co Ltd
Original Assignee
Shanghai Ideal Information Industry Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Ideal Information Industry Group Co Ltd filed Critical Shanghai Ideal Information Industry Group Co Ltd
Priority to CN201611241839.XA priority Critical patent/CN106790595B/en
Publication of CN106790595A publication Critical patent/CN106790595A/en
Application granted granted Critical
Publication of CN106790595B publication Critical patent/CN106790595B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1097Protocols in which an application is distributed across nodes in the network for distributed storage of data in networks, e.g. transport arrangements for network file system [NFS], storage area networks [SAN] or network attached storage [NAS]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a Docker container active load balancing device and a method thereof, wherein the method comprises the following steps: receiving an application file to be executed, and presetting details of the application to be executed; converting the application file to be executed into a Docker mirror image; executing an application starting command in the Docker mirror image; sending a registration request, and registering the application to a distributed coordination server; and acquiring the registration information from the distributed coordination server, acquiring the change data of the container corresponding to the application instance, analyzing the data, and updating the configuration file to the universal load balancer through the configuration template.

Description

Docker container active load balancing device and method
Technical Field
The invention relates to the technical field of internet, in particular to a Docker container active load balancing device and method.
Background
The Docker is an open-source application container engine, a single-instance running Docker container cannot meet production requirements, the industry generally adopts a Docker cluster mode to provide services to the outside, at present, a system adopting open-source container cluster management such as kubbernees, messes, swarm and the like is mostly adopted and is combined with basic network solutions such as flannel, weaves, pipeline and the like to solve the problems of the Docker cluster, but the load balance of the Docker container cluster cannot be perfectly solved.
The goal of Docker container discovery is to expose services hidden inside the Docker container, reducing or eliminating communication barriers between Docker containers.
The purpose of the Docker container cluster load balancing is to uniformly forward the normally running containers through the load balancer through Docker container discovery, and a caller has no perception on the transparency of the containers at the rear end of the load balancer. The active load balancing of the Docker container aims to automatically push information such as an application name, an IP address of the Docker container, an application port and the like when the Docker container is successfully started, and mount a Docker container instance to a load balancer, so that the Docker container instance provides service capacity, and manual intervention is not needed in the whole process. The caller can completely don't need to deal with the operation details of the backend Docker container, including the number, ip and port of the Docker container, and whether the Docker container operates in a physical machine or a virtual machine, and as long as there is a normally operating container, the caller can provide services to the outside, and the caller is completely transparent to the user. Meanwhile, for abnormal services, the whole system can respond and process in time, and an abnormal Docker instance is removed from the load balancer list.
Currently, a common load balancing scheme for a Docker cluster, such as kubernets, provides load balancing in three modes: 1. the method of using the host IP + PORT needs to expose the IP of the host to a caller, and particularly needs to switch the caller to other hosts after the hosts are down; 2. the method uses a native self-contained Service mode and provides services to the outside through private IP, and the mode needs that a caller is also in a kubernets cluster, otherwise the private IP cannot access; 3. by using dedicated load balancing in IaaS environments such as GCE and AWS, most enterprises cannot have the dedicated load balancing mode, and all the dedicated load balancing modes cannot meet the requirement of high availability of production.
Obviously, a common Docker cluster load balancing scheme is often dependent on a cluster management system, and the change or upgrade of the cluster management system can cause the failure of the original method; or the performance is lower when multiple time delays exist, so that the information such as the start and stop changes of the Docker container is monitored, and the information is synchronously refreshed on the load balancer; or because of adopting the special load balancer, the requirement for learning and maintenance cost is higher, and the special load balancer is not suitable for technical precipitation, and increases the enterprise cost; or when the service runs in various environments such as Docker environment, vmware and kvm or independently runs in a host environment, the requirement of heterogeneous environment cannot be met.
Disclosure of Invention
In order to overcome the defects in the prior art, the present invention provides an active load balancing apparatus and method for a Docker container, so as to implement a real-time active discovery and registration mechanism, and provide services for a Docker container cluster by using a universal load balancer, thereby ensuring non-intrusion to applications and facilitating containerization transformation of a system.
To achieve the above and other objects, the present invention provides an active load balancing apparatus for a Docker container, comprising:
the mirror image conversion module is used for providing a Docker basic mirror image containing an application manager and converting an application to be executed into the Docker mirror image;
the application manager is used for starting the Docker mirror image, analyzing and executing a starting command of the application to be executed according to preset application information, sending a registration request and registering the application to the distributed coordination server;
a distributed coordination server for deploying distributed coordination services;
the detector is used for monitoring the application change condition on the distributed coordination server and sending the application change condition to the load balancing agent;
the load balancing agent converts the application change condition into configuration data with a certain format according to a configuration template, executes the configuration data and configures the configuration data to a general load balancer;
and the universal load balancer is used for deploying the universal load balancing service.
Further, the image conversion module includes:
the basic mirror image is used for storing the Docker mirror image constructed by the application manager and the basic environment required by the application to be executed in advance, taking the mirror image as the basic mirror image of the application to be executed and storing the mirror image in a mirror image warehouse;
the command receiving module is used for receiving the identification information of the application to be executed;
and the mirror image construction module is used for constructing the application mirror image to be executed through the Dockerfile and uploading the application mirror image to the mirror image warehouse.
Further, the application manager includes:
the parameter analysis module is used for analyzing preset application information;
the command execution module is used for receiving the application execution command analyzed by the parameter analysis module, executing the command and acquiring a command execution result, and if the execution result is normal, calling the application registration module;
the application registration module is used for acquiring the data analyzed by the parameter analysis module and acquiring the state information of the application to be executed, establishing a temporary session link with the distributed coordination server, and registering the state details of the application to the distributed coordination server;
and the health check module is used for polling the health condition of the application according to a preset health check command and informing the application registration module of the result.
Further, when the Docker container is registered to the distributed coordination server through the application registration module, whether the directory of the distributed coordination server exists in the directory corresponding to the application is judged, and if not, a new directory is created in the distributed coordination server and a new node is created in the directory at the same time.
Further, the detector includes:
the monitoring module is used for monitoring the application change condition on the distributed coordination server, and triggering the first sending module if the state of the instance of the Docker container corresponding to the application changes;
and the first sending module is used for sending the application change condition to the load balancing agent.
Further, the load balancing agent comprises:
the first receiving module is connected with the first sending module and maintains heartbeat, receives the instruction sent by the first sending module and calls a data analysis module;
the data analysis module analyzes the instruction according to the format of the configuration template module at the moment and transmits the instruction to the second command execution module;
configuring a template module, wherein template data of the template module are different according to the load balancer of the load balancing agent;
and the second command execution module writes data into the configuration file directory of the universal load balancer and executes a restart command of the universal load balancer.
In order to achieve the above object, the present invention further provides a method for balancing active load of a Docker container, comprising the following steps:
receiving an application file to be executed, and presetting details of the application to be executed;
converting the application file to be executed into a Docker mirror image;
step three, executing an application starting command in the Docker mirror image;
step four, sending a registration request, and registering the application to the distributed coordination server;
and step five, acquiring the registration information from the distributed coordination server, acquiring the change data of the container corresponding to the application instance, analyzing the data, and updating the configuration file to the universal load balancer through the configuration template.
Further, step five further comprises:
monitoring a directory node applied to the distributed coordinator, and sending change information of the directory node to the load balancing agent;
and synchronizing the change information to the universal load balancer according to the configuration template.
Further, in the second step, the identification information of the application file to be executed is written into the Dockerfile according to the specification, and the application base image to be executed and the application to be executed construct an application image to be executed through the Dockerfile.
Further, in step four, the Docker container of the application to be executed maintains a temporary session with the distributed coordination server, and when the application is abnormal, immediately disconnects the link with the distributed coordination server, and automatically exits.
Compared with the prior art, the invention provides a Docker container active load balancing device and a method, which initiate connection and register application container information to a distributed coordination server through an application manager, monitor the health information of the application container in real time, actively and synchronously feed back the information to the distributed coordination server, actively update the information of the distributed coordination server to a load balancer by a detector according to the information of the distributed coordination server, successfully mount the Docker container to the load balancer, fully utilize the mature production and operation and maintenance experience of a general load balancer, effectively reduce the reconstruction cost for the traditional Docker container reconstruction, initiate connection and register from the container to the load balancer, utilize the mature and stable load balancer, do not need to be configured with a balancing configuration file in advance and restart the load balancer in the process, and automatically realize load balancing, the method solves the problem that the existing load balancing method in the container is difficult to adapt to a dynamically-changed container cluster for providing back-end service in a cloud computing system.
Drawings
FIG. 1 is a system architecture diagram of a Docker container active load balancing apparatus according to a first embodiment of the present invention;
FIG. 2 is a diagram of a system architecture of a Docker container active load balancing apparatus according to a second embodiment of the present invention;
FIG. 3 is a flowchart illustrating steps of a method for balancing Docker container active loads according to a third embodiment of the present invention;
fig. 4 is a flowchart of a method for balancing active load of a Docker container according to an embodiment of the present invention.
Detailed Description
Other advantages and capabilities of the present invention will be readily apparent to those skilled in the art from the present disclosure by describing the embodiments of the present invention with specific embodiments thereof in conjunction with the accompanying drawings. The invention is capable of other and different embodiments and its several details are capable of modification in various other respects, all without departing from the spirit and scope of the present invention.
Fig. 1 is a system architecture diagram of a Docker container active load balancing apparatus according to a first embodiment of the present invention. As shown in fig. 1, the invention provides an active load balancing apparatus for a Docker container, including: a mirror conversion module 101, an application manager 102, a distributed coordination server 103, a probe 104, a load balancing agent 105, and a general load balancer 106.
The image conversion module 101 is configured to provide a Docker base image including an application manager and convert an application to be executed into the Docker image.
Specifically, the image conversion module 101 is a successful-deployment Docker environment, and includes a base image 301, a command receiving module 302, and an image construction module 303, where the module has previously stored therein a Docker image constructed by an application manager and a base environment required by an application to be executed, and uses the image as the base image 301 of the application to be executed, and also stores the image in an image repository. And depositing the application to be executed to a corresponding directory of the mirror image conversion device by using ftp, tftp, scp, wget and the like. The command receiving module 302 receives identification information of an application to be executed, which is input by a user and includes information such as an application name, an application start command, a stop command, a port, application additional information and a health check command, and analyzes the identification information and a locally pre-stored Dockerfile template to form a new Dockerfile, the image constructing module 303 constructs an application image to be executed through the Dockerfile and uploads the application image to an image warehouse, and the application image at this time at least includes an application manager, the application to be executed and corresponding parameters.
And the application manager 102 is configured to start the Docker mirror, analyze a start command of an application to be executed according to preset application information, execute the command, send a registration request, and register the application to the distributed coordination server.
Specifically, the application manager 102 includes a parameter parsing module 311, a command execution module 312, an application registration module 313, and a health check module 314. The parameter analyzing module 311 is responsible for analyzing preset application information, where the preset application information includes: the application name, the application start command, the stop command, the port, the application additional information, and the like, and the application execution command including the application start command and the application stop command is transmitted to the command execution module 312; a command executing module 312, configured to receive the application execution command analyzed by the parameter analyzing module 311, execute the command and obtain a command execution result, and if the execution result is normal, invoke the application registering module 313; the application registration module 313 acquires the data analyzed by the parameter analysis module 311 and the status information of the application to be executed, establishes a temporary session link with the distributed coordination server 103, and details the status of the application: the container status information, the container IP, the port, the application name, and the application additional information are registered in the distributed coordination server 103, and when an application abnormality such as downtime is found, the link with the distributed coordination server 103 is automatically disconnected. When the Docker application is started, the parameter parsing module 312 parses preset information of the proxied application, calls the command executing module 312 to execute an application starting command, notifies the distributed coordination server 103 by the application registering module 313, and creates a folder corresponding to the application to be executed under the file directory. Each time a Docker container for executing an application is successfully started, the application registration module 313 registers the application information to a folder under a corresponding application of the distributed coordination server 103 as an application node instance.
In detail, when the Docker container is registered in the distributed coordination server 103 through the application registration module 313, it is determined whether the directory of the distributed coordination server 103 has a directory corresponding to the application, and if not, a new directory is created in the distributed coordination server 103 and a new node is created in the directory at the same time, where the IP and the application port of the container are names of the node. When a new Docker instance is generated by the application, the new Docker instance will be registered under the directory. When a certain Docker instance of the application goes down, the application registration module 313 automatically disconnects the connection with the distributed coordination server 103, and the distributed coordination server 103 deletes the registration information of the Docker instance.
The health check module 314 basically polls the health of the application according to a preset health check command and informs the application registration module 313 of the result. The health check module 314 essentially checks for the presence of a failed container, which may refer to a container that is not capable of providing normal service. For example, a container may be considered to be a failed container when the health check module 314 detects that the container has an anomaly, such as a healthy heartbeat failing in the container and health check module 314, an unexpected stop in the container process, and the like, i.e., the container cannot provide a service. Optionally, for any container, it may be monitored whether the container is disconnected from the health check module 314, if the health check module 314 detects that the container is a failed container. The health check module 314 notifies the application registration module 313 that the link will be automatically disconnected from the distributed coordination server 103, causing the distributed coordination server 103 to delete the failed container node.
A distributed coordination server 103 for deploying distributed coordination services. In an embodiment of the present invention, there may be one or more distributed coordination servers 103, when there are multiple distributed coordination servers 103, the multiple distributed coordination servers 103 are used to form a distributed coordination service group, and a leader (leader) may be selected from the multiple distributed coordination servers 103, where the distributed coordination servers 103 are used to deploy the distributed coordination service. In this embodiment, zookeeper is deployed as a distributed coordination server, which is an open-source distributed coordination server. It is a software that provides a consistent service for distributed applications, and the functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, and the like. It is particularly noted that when data stored in a zookeeper directory node is modified, a child node directory is changed, and the like, once a client for setting monitoring can be notified of the change, the function is the most important characteristic of the zookeeper to the application, and the functions which can be realized by the characteristic include centralized management of configuration, cluster management, distributed locking, and the like. Here, two functions of configuration maintenance and distributed synchronization in zookeeper are mainly used, in which one file directory in which folders corresponding to the plurality of applications respectively exist is maintained in the distributed coordination server 103. That is, there are multiple folders under the file directory, each folder corresponds to an application, there is at least one node under each folder, and each node corresponds to a Docker container instance. Therefore, the application and the Docker instance of the application can be managed through the folder and the node of the zookeeper, and the state change management of the Docker container can be realized, namely the discovery of the Docker container is realized.
For example, preset/apps/catalog is a parent directory of all applications, if an application name in the preset information is helloworld, a port is 8080, the application corresponds to a Docker instance, and the container IP is 172.17.0.2, the directory of the application corresponding to zookeeper is apps/catalog/helloworld, and the zookeeper node corresponding to the Docker instance is apps/catalog/helloworld/172.17.0.2: 8080, if a new Docker instance is added to the application and the Docker container IP is 172.17.0.3, the application zookeeper node directory is/apps/catalog/helloworld/172.17.0.2: 8080 and/apps/catalog/helloworld/172.17.0.3: 8080. if the Docker container with the IP of 172.17.0.3 is down, the node corresponding to the application becomes/apps/catalog/helloworld/172.17.0.2: 8080. by means of the corresponding relation between the file directories and nodes of the zookeeper and the application and the Docker instance, the corresponding relation that one application corresponds to one directory and one Docker container corresponds to one directory node can be achieved.
And the detector 104 is configured to monitor all corresponding application folders in the distributed coordination server 103. The folder name of the folder corresponds to the application name, and each application uniquely corresponds to a folder with the application name as the folder name. In this embodiment, after the Docker instance of the application to be executed is started, details of the Docker instance may be registered in the distributed coordination server 103, and the snooping module 331 detects that the application directory/apps/catalog has changed, reads node details of the application directory/apps/catalog, and sends a corresponding instruction by the first sending module 332 to notify the load balancing agent 105 to add an new piece of application instance information, so as to update the configuration of the general load balancer 106. Optionally, when one of the Docker instances of the application to be executed stops or crashes, the health check module 314 detects that the instance is abnormal, notifies the application registration module 313 to disconnect the link with the distributed coordination server 103, the distributed coordination server 103 deletes the directory node information, at this time, the monitoring module 331 immediately detects that the application directory/apps/catalog is changed, notifies the load balancing agent 105 to delete one, and updates the configuration of the general load balancer 106.
And the load balancing agent 105 is used for updating the configuration file to the general load balancer 106 through the configuration template.
Specifically, the load balancing agent 105 includes a first receiving module 341, a data parsing module 342, a configuration template module 343, and a second command executing module 344. The load balancing agent 105 and the generic load balancer deployment 106 are on the same server. The first receiving module 341 connects to the first sending module 332 through the TCP protocol and maintains the heartbeat, and the first receiving module 341 receives the instruction sent by the first sending module 332 and calls the data parsing module 342. The data parsing module 342 parses the instruction according to the format of the configuration template module 343 at this time, the template data in the configuration template module 343 are different according to the different load balancers proxied by the load balancing proxy 105, for example, the configuration applicable to nginx is different from the configuration applicable to lvs and keepalived, and after the data parsing module 342 successfully parses the instruction according to the template data, the instruction is placed into the temporary memory area, and the second command executing module 344 is called. The second command executing module 344 presets the path of the configuration file of the universal load balancer 106, starts, stops, and restarts commands and gives control authority to execute the universal load balancer 106, and when the data parsing module 342 transmits the parsed data to the second command executing module 344, the second command executing module 344 reads the temporary memory area, writes the data into the configuration file directory of the universal load balancer 106, and executes the restart command of the universal load balancer 106.
A generic load balancer 106 for deploying a generic load balancing service. In this embodiment, the universal load balancer 106 may be located in an independent server, or may be located in a server cluster formed by several servers. For example, nginx and lvs are open-source soft load balancers, and the industry accumulates more production experiences at present, so that the research, development, operation and maintenance and learning costs of enterprises are greatly reduced. nginx differs from lvs in that lvs has significant performance in handling four-layer traffic but has high requirements on the network, and nginx is commonly used for seven-layer load balancing and has low requirements on the network environment. Since the general purpose load balancer 106 is familiar to those skilled in the art, it will not be described herein.
In the invention, the application manager and the application to be executed can also run in a non-Docker container environment, or realize the load balance of the application cluster together in the container environment. Fig. 2 is a system architecture diagram of a device for performing active load balancing on a Docker container according to a second embodiment of the present invention, in which an application manager 203 presets application information: after the application manager 203 is started, the parameter analysis module analyzes the details of the application and starts the application 204 to be executed, and when the application 204 to be executed is started successfully, the application manager 203 registers the state information of the application instance, the host IP, the port, the application name, and the application additional information to the distributed coordination server 205. The difference is that: 1. the application instance is changed from the container IP to the host IP, 2, the application instance ports running on the same host cannot be the same, and then the processing procedures of the modules are basically the same as those of the first embodiment, and are not described again.
Fig. 3 is a flowchart illustrating steps of a method for performing active load balancing on a Docker container according to a third embodiment of the present invention. As shown in fig. 3, the method for active load balancing of a Docker container according to the present invention includes the following steps:
step 301, receiving an application file to be executed, and presetting details of the application to be executed. The details of the application to be executed include an application start command, a stop command, an application name, a version number, application additional information (TCP/HTTP), and application port information.
Step 302, converting the application file to be executed into a Docker mirror image. Specifically, identification information of the application file to be executed, such as an application name, an application start command, a stop command, a port, application additional information, a health check command and the like, is written into the Dockerfile according to a specification, and the application base image to be executed and the application to be executed construct an application image to be executed, namely a Docker image, through the Dockerfile.
And step 303, executing an application starting command in the Docker image. That is, when the application to be executed has been successfully constructed as a Docker image, the image is started, and a start command of the application to be executed is parsed according to the preset application information and executed.
Step 304, sending a registration request to register the application to the distributed coordination server. The registration request carries a container IP of the application information in the Docker container, application port information, an application name, application additional information, and the like. In an embodiment of the present invention, the distributed coordination server creates a directory with the application name as its name, and creates a node under the directory, where the name of the node is the container IP and port, e.g., 172.17.0.2:8080, and other information, e.g., application additional information, is stored in the node. And the Docker container of the application to be executed and the distributed coordination server maintain a temporary session, and when the application is abnormal, the Docker container immediately disconnects the link with the distributed coordination server and automatically exits. And as the temporary session is adopted with the distributed coordination service, the distributed coordination service immediately deletes all information of the node once the temporary session is disconnected.
Step 305, obtaining the registration information, i.e. the change data of the container corresponding to the application instance, from the distributed coordination server, analyzing the data, and updating the configuration file to the load balancer through the configuration template. Specifically, step 305 further includes:
step S1, monitor the directory node of the application in the distributed coordinator, and send the change information of the node to the load balancing agent. According to the step S304, it is known that the newly added application has successfully registered as a directory in the distributed coordination server, node information under the directory is actively read, and once it is detected that a newly added node is registered under the directory, an instruction is sent to a downstream module, that is, a load balancing agent, where the instruction carries a directory name (that is, an application name), names of all nodes under the directory (that is, node instance addresses) and additional information;
step S2, synchronizing the change information to the load balancer, such as nginx, lvs, according to the configuration template. According to the above step S1, if the load balancing agent receives the instruction sent in step S1 and includes information of all nodes under application, the load balancing agent converts the relevant parameters of the configuration template into parameters recognized by the load balancing agent, and writes the parameters into a corresponding configuration file, where the load balancing agent should preset a path, start, stop, and restart commands of the configuration file of the load balancing agent. In particular embodiments of the present invention, the configuration templates vary according to the load balancer chosen.
Fig. 4 is a flowchart of a method for active load balancing of a Docker container according to an embodiment of the present invention, and as shown in fig. 4, the method may include:
step S401, presetting application information, and constructing an application to be executed as a new mirror image. Specifically, the identification information of the application to be executed: and writing the application name, the application starting command, the stopping command, the port, the application additional information and the health check command into the Dockerfile according to the specification, and constructing the application mirror image to be executed by the application base mirror image to be executed and the application to be executed through the Dockerfile.
Step S402, deploying a distributed coordination server, such as zookeeper, in the distributed coordination server. The distributed coordination server may be in a single node or cluster mode. Particularly, once the distributed coordination server has changes such as directories, child nodes, data and the like, the monitoring client can be informed actively, and by means of the characteristic, the downstream module can be informed immediately to process timely when the application instance node changes.
Step S403, as described in step S401, the application to be executed is successfully constructed as a Docker mirror, the mirror is started, the start command of the application to be executed is analyzed according to the preset application information, the command is executed, and then the application health degree is periodically checked according to the preset application health check statement.
Step S404, after the application to be executed is successfully started, including the details of the state of the application: the container state information, the container IP, the port, the application name, and the application additional information are registered with the distributed coordination server that has been successfully deployed in step S402, and at this time, the distributed coordination server creates a directory with the application name as the name, and creates a node under the directory, where the name of the node is the container IP and the port, such as 172.17.0.2:8080, and other information, such as the application additional information, is stored in the node. And the Docker container of the application to be executed and the distributed coordination server maintain a temporary session, and when the application is abnormal, the Docker container immediately disconnects the link with the distributed coordination server and automatically exits. And as the temporary session is adopted with the distributed coordination service, the distributed coordination service immediately deletes all information of the node once the temporary session is disconnected.
Step S405, deploying load balancing services such as nginx and lvs on the universal load balancer. The load balancer ensures interconnection with each node and each node container network, and the network scheme based on container interconnection may adopt a port mapping, direct path or overlay network mode, which is familiar to those skilled in the art and is not described herein again.
Step S406, monitoring the directory node of the application in the distributed coordinator, and sending the change information of the node to the load balancing agent. According to the step S404, it is known that the newly added application has successfully registered as a directory in the distributed coordination server, node information in the directory is actively read, and once it is detected that a newly added node is registered in the directory, an instruction is sent to the downstream module, that is, the load balancing agent, where the instruction carries a directory name (that is, an application name), names of all nodes in the directory (that is, node instance addresses), and additional information.
Step S407, synchronizing the change information to the load balancers such as nginx, lvs according to the configuration template. According to the step S406, it is known that the load balancing agent receives the instruction sent in the step S406, which includes information of all nodes under application, and then the load balancing agent converts the relevant parameters of the configuration template into parameters identified by the load balancing agent, and writes the parameters into a corresponding configuration file. The load balancing agent should preset the load balancing configuration file path, start, stop and restart commands.
The method enables the running condition of the application under the Docker environment to be fed back to the load balancing system at any time, and by adopting a general load balancer and an active registration mechanism, the application caller is converted from a changeable and complex Docker container address to an address accessing a fixed load balancer, the application caller is automatically discovered and automatically registered in the whole process, no perception is provided for the caller, and the application manager can be also applied to the host machine or virtual machine environment together with the application to be executed.
Compared with the above embodiment, further, in this embodiment, before the step of constructing, by the apparatus, a new Docker image as a base image of the application to be executed, in advance, the base environment required by the program manager and the application to be executed by the apparatus in S401, the method further includes: and acquiring the basic environment required by the application to be executed from the mirror image warehouse. Specifically, the mirror image warehouse is used for storing mirror image files, and comprises a basic environment required by the application to be executed, a basic mirror image of the application to be executed and an application mirror image to be executed, and the newly constructed mirror images are uniformly stored in the mirror image warehouse. In this embodiment, the mirror image conversion device, each node, and the mirror image warehouse establish communication connection.
In summary, the device and method for active load balancing of a Docker container of the present invention utilize an application manager to actively register container change information, and simultaneously utilize a detector and a distributed coordination server to employ a temporary session mechanism, there is no need to monitor the distributed coordination server in real time through a heartbeat method, once a container finds a change, the change information of the container is written into a general load balancer by utilizing a load balancing agent, the present invention is applicable to application containerization modification, and there is no constraint and restriction on the existing application; the change condition of the container can be monitored in time without adopting a heartbeat mechanism, so that the overtime problem caused by heartbeat is avoided; the embodiment of the invention also explains that the change condition of the application to be executed is synchronized to the load balancer through the application manager under the non-container environment, thereby meeting the requirement of the application in the operation of heterogeneous environments.
The foregoing embodiments are merely illustrative of the principles and utilities of the present invention and are not intended to limit the invention. Modifications and variations can be made to the above-described embodiments by those skilled in the art without departing from the spirit and scope of the present invention. Therefore, the scope of the invention should be determined from the following claims.

Claims (4)

1. A Docker container active load balancing apparatus, comprising:
the mirror image conversion module is used for providing a Docker basic mirror image containing an application manager and converting an application to be executed into the Docker mirror image;
the application manager is used for starting the Docker mirror image, analyzing and executing a starting command of the application to be executed according to preset application information, and registering the application to the distributed coordination server; the application manager includes:
the system comprises a parameter analysis module, a command execution module, an application registration module and a health check module; wherein, this parameter analysis module is responsible for analyzing predetermined application information, and this predetermined application information includes: the application name, the application start command, the stop command, the port and the application additional information are transmitted to the command execution module, wherein the application execution command comprises an application start command and an application stop command;
the command execution module is used for receiving the application execution command analyzed by the parameter analysis module, executing the command and acquiring a command execution result; if the execution result is normal, the application registration module is called; the application registration module acquires the data analyzed by the parameter analysis module and the state information of the application to be executed, establishes a temporary session link with the distributed coordination server, and details the state of the application: the container state information, the container IP, the port, the application name and the application additional information are registered in the distributed coordination server, and when the application abnormality is found, the link with the distributed coordination server is automatically disconnected; when the Docker application is started, the parameter analysis module analyzes preset information of the proxied application, calls the command execution module to execute an application starting command, informs the distributed coordination server by the application registration module, and creates a folder corresponding to the application to be executed under a file directory; when a Docker container for executing the application is started successfully, the application registration module registers the application information to a folder under the application corresponding to the distributed coordination server as an application node instance;
when the Docker container is registered to the distributed coordination server through the application registration module, judging whether the directory of the distributed coordination server has a directory corresponding to the application, if not, creating a new directory in the distributed coordination server and simultaneously creating a new node in the directory, wherein the IP and the application port of the container are the names of the nodes; when a new Docker instance is generated in the application, the new Docker instance is registered under the directory; when a certain Docker instance of the application goes down, the application registration module automatically disconnects the connection with the distributed coordination server, and meanwhile, the distributed coordination server deletes the registration information of the Docker instance;
the health examination module polls the health condition of the application according to a preset health examination command and informs the application registration module of the result; the health check module checks whether a failed container exists, wherein the failed container is a container which cannot provide normal service; the health check module informs the application registration module to automatically disconnect from the distributed coordination server, thereby causing the distributed coordination server to delete the failed container node;
a distributed coordination server for deploying distributed coordination services; the distributed coordination servers are used for forming a distributed coordination service group and selecting a leader from the distributed coordination servers when the distributed coordination servers are multiple, wherein the distributed coordination servers are used for deploying the distributed coordination services; deploying zookeeper as a distributed coordination server to realize centralized management, cluster management and distributed locks of configuration; maintaining a file directory in the distributed coordination server by using two functions of configuration maintenance and distributed synchronization in the zookeeper, wherein the file directory has folders respectively corresponding to the plurality of applications; that is, there are multiple folders under the file directory, each folder corresponds to an application, there is at least one node under each folder, and each node corresponds to a Docker container instance; therefore, the application and the Docker instance of the application are managed through the folder and the node of the zookeeper, and the state change management of the Docker container is realized, namely the discovery of the Docker container is realized; realizing the corresponding relation that one application corresponds to one directory and one Docker container corresponds to one directory node by means of the corresponding relation between the file directory and the node of the zookeeper and the application and the Docker instance;
the detector is used for monitoring the application change condition on the distributed coordination server and sending the application change condition to the load balancing agent;
the load balancing agent converts the application change condition into configuration data with a certain format according to a configuration template, executes the configuration data and configures the configuration data to a general load balancer; the load balancing agent comprises a first receiving module, a data analysis module, a configuration template module and a second command execution module; the load balancing agent and the universal load balancer are deployed in the same server; the first receiving module is connected with the first sending module through a TCP protocol and maintains heartbeat, and receives the instruction sent by the first sending module and calls the data analysis module; the data analysis module analyzes the instruction according to the format of the configuration template module at the moment, the template data in the configuration template module are different according to different load balancers proxied by the load balancing agent, and the template data are different; the data analysis module successfully analyzes the instruction according to the template data, then puts the instruction into a temporary memory area, and calls the second command execution module; the second command execution module presets the path of the configuration file of the universal load balancer, starts, stops and restarts commands and gives control authority to execute the universal load balancer, and when the data analysis module transmits the analyzed data into the second command execution module, the second command execution module reads the temporary memory area and writes the data into the directory of the configuration file of the universal load balancer and executes the restart command of the universal load balancer;
and the universal load balancer is used for deploying the universal load balancing service.
2. The apparatus of claim 1, wherein the mirror transformation module comprises:
the basic mirror image is used for storing the Docker mirror image constructed by the application manager and the basic environment required by the application to be executed in advance, taking the mirror image as the basic mirror image of the application to be executed and storing the mirror image in a mirror image warehouse;
the command receiving module is used for receiving the identification information of the application to be executed;
and the mirror image construction module is used for constructing the application mirror image to be executed through the Dockerfile and uploading the application mirror image to the mirror image warehouse.
3. A Docker container active load balancing device as claimed in claim 1, wherein the probe comprises:
the monitoring module is used for monitoring the application change condition on the distributed coordination server, and triggering the first sending module if the state of the instance of the Docker container corresponding to the application changes;
and the first sending module is used for sending the application change condition to the load balancing agent.
4. A Docker container active load balancing method comprises the following steps:
receiving an application file to be executed, and presetting details of the application to be executed; the details of the application to be executed include: an application start command, a stop command, an application name, a version number, application additional information, and application port information;
converting the application file to be executed into a Docker mirror image; writing identification information of an application file to be executed into a Dockerfile according to a specification, and constructing an application mirror to be executed, namely a Docker mirror, by the application base mirror to be executed and an application to be executed through the Dockerfile;
step three, executing an application starting command in the Docker mirror image; namely: when the application to be executed is successfully constructed into a Docker mirror image, starting the mirror image, analyzing a starting command of the application to be executed according to preset application information, and executing the command;
step four, sending a registration request, and registering the application to the distributed coordination server; the registration request carries a container IP of the application information in the Docker container, application port information, an application name and application additional information; the distributed coordination server creates a directory with an application name as a name, and creates a node under the directory, wherein the name of the node is a container IP and a port, and other information is stored in the node; the method comprises the steps that a Docker container of an application to be executed maintains a temporary session with a distributed coordination server, when the application is abnormal, a link with the distributed coordination server is immediately disconnected, and the Docker container automatically exits; the distributed coordination server immediately deletes all information of the node;
step five, acquiring the registration information from the distributed coordination server, acquiring the change data of the container corresponding to the application instance, analyzing the data, and updating the configuration file to the universal load balancer through a configuration template; the method specifically comprises the following steps:
step S1, monitoring the directory node applied in the distributed coordination server, and sending the change information of the node to the load balancing agent; the newly added application is successfully registered as a directory in the distributed coordination server, node information under the directory is actively read, and once the newly added node registration under the directory is detected, an instruction is sent to a downstream module, namely a load balancing agent, wherein the instruction carries a directory name, all node names under the directory and additional information;
step S2, synchronizing the change information to the load balancer according to the configuration template, and the load balancing agent receiving the instruction sent in step S1 includes all node information under application, then the load balancing agent converting the relevant parameters of the configuration template into parameters identified by the load balancer and writing the parameters into corresponding configuration files, wherein the load balancing agent should preset the load balancer configuration file path, start, stop and restart commands; the configuration templates differ according to the load balancer selected.
CN201611241839.XA 2016-12-29 2016-12-29 Docker container active load balancing device and method Active CN106790595B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611241839.XA CN106790595B (en) 2016-12-29 2016-12-29 Docker container active load balancing device and method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611241839.XA CN106790595B (en) 2016-12-29 2016-12-29 Docker container active load balancing device and method

Publications (2)

Publication Number Publication Date
CN106790595A CN106790595A (en) 2017-05-31
CN106790595B true CN106790595B (en) 2020-12-22

Family

ID=58923590

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611241839.XA Active CN106790595B (en) 2016-12-29 2016-12-29 Docker container active load balancing device and method

Country Status (1)

Country Link
CN (1) CN106790595B (en)

Families Citing this family (35)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107360018A (en) * 2017-06-05 2017-11-17 小草数语(北京)科技有限公司 Config update method and device
CN107248986A (en) * 2017-06-08 2017-10-13 医惠科技有限公司 A kind of service tray method
CN107294785B (en) * 2017-07-11 2020-07-28 上海帝联信息科技股份有限公司 Automatic deployment method and device for CDN node service and computer readable storage medium
CN109309693B (en) * 2017-07-26 2022-04-29 财付通支付科技有限公司 Multi-service system based on docker, deployment method, device, equipment and storage medium
CN107766052B (en) * 2017-09-18 2020-09-25 网宿科技股份有限公司 Method and device for constructing container mirror image
CN107635002A (en) * 2017-09-21 2018-01-26 浪潮软件股份有限公司 A kind of access method and device of containerization application
CN107885547A (en) * 2017-11-08 2018-04-06 江苏国泰新点软件有限公司 A kind of collocation method of application program, device, configuration equipment and storage medium
CN108021428A (en) * 2017-12-05 2018-05-11 华迪计算机集团有限公司 A kind of method and system that network target range is realized based on Docker
CN108446326B (en) * 2018-02-11 2019-01-29 江苏微锐超算科技有限公司 A kind of isomeric data management method and system based on container
CN108551488A (en) * 2018-05-03 2018-09-18 山东汇贸电子口岸有限公司 Distributed container cluster load balancing method based on domestic CPU and OS
CN108616599B (en) * 2018-05-11 2021-10-29 北京辰森世纪科技股份有限公司 Method and device for registering and updating application service
CN108920153B (en) * 2018-05-29 2022-04-22 华南理工大学 Docker container dynamic scheduling method based on load prediction
CN110618821A (en) * 2018-06-19 2019-12-27 普天信息技术有限公司 Container cluster system based on Docker and rapid building method
CN108874549B (en) * 2018-07-19 2021-02-02 北京百度网讯科技有限公司 Resource multiplexing method, device, terminal and computer readable storage medium
CN110912953A (en) * 2018-09-17 2020-03-24 深圳市优必选科技有限公司 File storage system and method
CN109120481B (en) * 2018-09-27 2021-06-04 上海新炬网络信息技术股份有限公司 Method for monitoring DCOS container and internal middleware based on Zabbix open source component
CN109343963B (en) * 2018-10-30 2021-12-07 杭州数梦工场科技有限公司 Application access method and device for container cluster and related equipment
CN109451065B (en) * 2018-12-26 2021-06-01 中电福富信息科技有限公司 Soft load balancing and shunting automation system and operation method thereof
CN110134455A (en) * 2019-04-12 2019-08-16 平安医疗健康管理股份有限公司 A kind of application management system and method
CN110087107B (en) * 2019-04-25 2022-01-14 视联动力信息技术股份有限公司 Method for improving system self-adaptive capacity and video networking system
CN110224860B (en) * 2019-05-17 2023-05-26 平安科技(深圳)有限公司 Load balancing application creation method and device, computer equipment and storage medium
CN110750592B (en) * 2019-09-06 2023-10-20 中国平安财产保险股份有限公司 Data synchronization method, device and terminal equipment
CN110569056B (en) * 2019-09-11 2023-05-05 北京奇艺世纪科技有限公司 Rule service information updating method and device
CN110830289B (en) * 2019-10-21 2021-06-11 华中科技大学 Container abnormity monitoring method and monitoring system
CN110764875A (en) * 2019-10-25 2020-02-07 北京威晟艾德尔科技有限公司 Docker container creating method based on competition mechanism
CN110830574B (en) * 2019-11-05 2023-01-20 浪潮云信息技术股份公司 Method for realizing intranet load balance based on docker container
CN111163122A (en) * 2019-11-21 2020-05-15 江苏艾佳家居用品有限公司 TCP configuration method based on Nginx self-research extension module and for automatically pulling service registration center
CN113127145B (en) * 2020-01-15 2022-12-13 中移(苏州)软件技术有限公司 Information processing method, device and storage medium
CN112099915B (en) * 2020-09-07 2022-10-25 紫光云(南京)数字技术有限公司 Soft load balancing dynamic issuing configuration method and system
CN112527319A (en) * 2020-12-16 2021-03-19 浙江大学德清先进技术与产业研究院 Management method of Docker-based remote sensing intelligent processing algorithm
CN112764825B (en) * 2020-12-30 2023-12-29 望海康信(北京)科技股份公司 Service integration system, corresponding device and storage medium
CN113127435A (en) * 2021-03-30 2021-07-16 杭州当虹科技股份有限公司 Intelligent synchronization method and system for files of main and standby systems
CN113778613B (en) * 2021-07-15 2024-04-26 上海浦东发展银行股份有限公司 Unified management method for dual-stack container cloud platform of multiple data centers
CN114640633B (en) * 2022-03-29 2024-04-05 京东科技信息技术有限公司 Load balancer, realization method thereof, load balancing method and gateway system
CN115190015A (en) * 2022-07-12 2022-10-14 中国工商银行股份有限公司 Soft load system configuration method and device, computer equipment and storage medium

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10432703B2 (en) * 2012-11-26 2019-10-01 Facebook, Inc. On-demand session upgrade in a coordination service
US9843533B2 (en) * 2014-03-06 2017-12-12 Trilio Data Inc. Elastic compute cloud based on underutilized server resources using a distributed container system
CN104503882B (en) * 2014-12-25 2018-10-19 北京京东尚科信息技术有限公司 container management method and device
CN105187499B (en) * 2015-08-07 2018-07-17 北京思特奇信息技术股份有限公司 A kind of distributed scheduling method and system based on zookeeper biplane data frameworks
CN105376303B (en) * 2015-10-23 2018-11-06 深圳前海达闼云端智能科技有限公司 Docker implementation system and communication method thereof
CN105389243B (en) * 2015-10-26 2018-06-05 华为技术有限公司 A kind of container monitors method and apparatus
CN105824614B (en) * 2015-12-15 2019-05-17 广东亿迅科技有限公司 The building method and device of distributed developing environment based on Docker
CN105610972B (en) * 2016-02-01 2019-04-09 中博信息技术研究院有限公司 The task of concentrating type sends system
CN105979009B (en) * 2016-07-06 2019-05-17 乾云数创(山东)信息技术研究院有限公司 A kind of increase load automatic balancing method for cloud application container

Also Published As

Publication number Publication date
CN106790595A (en) 2017-05-31

Similar Documents

Publication Publication Date Title
CN106790595B (en) Docker container active load balancing device and method
US10356214B2 (en) Composing monolithic applications based on multi-container applications
US8584081B2 (en) Server side application integration framework
US7937716B2 (en) Managing collections of appliances
AU2013397867B2 (en) Application upgrade method and device
Tiderko et al. The ROS multimaster extension for simplified deployment of multi-robot systems
WO2009098909A1 (en) Virtual appliance assignment system
US20090063650A1 (en) Managing Collections of Appliances
US20230060053A1 (en) Method and apparatus of deploying a cluster, and storage medium
US20100235493A1 (en) Extendable distributed network management system and method
CN111966465B (en) Method, system, equipment and medium for modifying host configuration parameters in real time
JP2019101866A (en) Application update method and program
CN105592139A (en) HA implementation method and device of distributed file system management platform
CN115190103A (en) Service grid-based service domain name resolution method, device and equipment
CN112994935A (en) prometheus management and control method, device, equipment and storage medium
CN112003728A (en) Kubernetes cluster-based application master and standby implementation method and device
CN112583630B (en) Device management method, device, system, device and storage medium
CN113079098B (en) Method, device, equipment and computer readable medium for updating route
US20190386886A1 (en) Method and system for virtual network service activation
CN109104333B (en) GIT-based distributed cluster synchronization method and device
CN114553867A (en) Cloud-native cross-cloud network monitoring method and device and storage medium
CN112351114B (en) Information processing method and device and storage medium
CN112787868A (en) Information synchronization method and device
CN112650537A (en) Server configuration method, device, equipment and computer readable storage medium
CN112714035A (en) Monitoring method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant