Embodiment
To make the target, technical scheme and advantage of the embodiment of the present invention clearer, below in conjunction with the embodiment of the present invention
In accompanying drawing, the technical scheme in the embodiment of the present invention is clearly and completely described, it is clear that described embodiment is
A part of embodiment of the present invention, rather than whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art
The every other embodiment obtained under the premise of creative work is not made, belongs to the scope of protection of the invention.
Fig. 1 is the schematic flow sheet for the double hot standby method that the embodiment of the present invention one is provided.It is shown in Figure 1, this hair
The double hot standby method that bright embodiment is provided includes:
Step 101:Main frame receives the service data of client, produces corresponding service response data, and will service
Link information between reply data and main frame and client is sent to standby host;The link information includes:The IP of client,
The sequence number that port numbers and main frame and the TCP of client are linked;
Step 102:Standby host is received after service response data and the link information transmitted by main frame, will be described
Service response data and link information backup, and the service response data are sent to client with the identity of main frame
End;
Step 103:When main frame breaks down, the IP address of itself is changed to the IP address of main frame by standby host;
Step 104:The sequence number that standby host is linked using the TCP of the main frame and client sends service response to client
Data.
The double hot standby method that the present invention is provided, compared to existing technologies, passes through all clothes for being sent main frame
Business reply data forwarding flows through standby host, standby host is kept the real-time synchronization with mainframe network data.Simultaneously also by main frame and client
Link information between end is also sent to standby host., should after standby host receives this service response data and link information
Link information of the answer according to this and between client and main frame is backed up, in link information, includes IP, the end of client
The sequence number that slogan and main frame and the TCP of client are linked, when standby host completes the standby of service response data and link information
After part, service response data are issued client by standby host with the identity of main frame, therefore client will be considered that its service received
Reply data comes from main frame.When main frame breaks down, standby host seizes the IP address of main frame, i.e., be changed to the IP of itself
Host ip, while after the service data transmitted by client is received, producing corresponding service response data, using master
The sequence number that machine and the TCP of client are linked sends service response data to client.Then client can think that it is received always
To service response data be to be sent by main frame, eliminate redialing for client, accomplish that the nothing of client is discovered, this causes
Many clients for not redialing mechanism also can normally be used after hot standby switch, it is ensured that linking between standby host and client
It will not be terminated.
In the present invention, main frame wants runtime server program, the clothes that service data is run by client to main frame
The request server that business device program is sent is provided for it in data of service, such as communication system, asks the number of request of call
According to etc., and server program(That is main frame)This request data according to transmitted by client, the reply data sent, as
Service response data.
Fig. 2 be in the double hot standby method that the embodiment of the present invention two is provided main frame by service response data and main frame with
Link information between client is sent to the schematic flow sheet of the detailed process of standby host.On the basis of embodiment one, it has
Body is:
Step 201:The service response data are formed corresponding service response bag by main frame;
Step 202:The Target IP of the service response bag is revised as the IP of standby host by main frame, and source IP is revised as into client
IP, destination port number is revised as to the port numbers of standby host, source port number is revised as to the port numbers of client, constitute in the middle of take
Business response bag;
Step 203:The intermediary service response bag is sent to standby host by main frame.
In the double hot standby method provided in the present embodiment, the service response bag data produced by main frame, and formed
After corresponding service response bag, according to normal flow, the Target IP of the service response bag produced by the main frame, destination port number are equal
Should be IP, the port numbers of client;Source IP, source should be IP, the port numbers of main machine with port numbers and.However, in order that
Service response bag produced by obtaining main frame can smoothly reach standby host, and simultaneously by the link information between main frame and client
Standby host is sent to, therefore the source IP of modification service response bag is the IP of client, source port number is the port numbers of client, and repaiies
The Target IP for changing service response bag is the IP of standby host, and destination port number is the port numbers of standby host, constitutes intermediary service response bag, to
Standby host is sent.
In addition, main frame can also do the MAC Address of service response bag accordingly after corresponding service response bag is formed
Modification.For example, the MAC Address of service response bag is revised as the MAC Address of standby host by main frame, modification source MAC is client
MAC Address.If client is located at wide area network, and main frame and standby host are then located at same LAN, then make service response bag
Source MAC be local gateway MAC Address.In the present embodiment, the service response data produced by main frame are formed
In service response bag, source IP, source port number and source MAC that data are the service response bag, and the service are linked
During response bag formation, the sequence number that the TCP of the main frame carried automatically and client is linked.So, service response data and chain
Connecing information just can smoothly issue the follow-up backup and forwarding of standby host progress.
During Fig. 3 is the double hot standby method that the embodiment of the present invention three is provided, standby host is by the service response data with master
The identity of machine is sent to the specific flow chart of client, on the basis of above-described embodiment two, specifically includes:
Step 301:The Target IP of the intermediary service response bag is revised as client ip by standby host, source IP is changed based on
Machine IP, client end slogan is revised as by destination port number, and source port number is revised as into host side slogan, is reduced to the service
Response bag;
Step 302:The standby host sends the amended service response bag to client.
Because standby host is after the intermediary service response bag of reception, intermediary service response bag is parsed, and will be corresponding
Main frame be sent to the reply data of client, and the link information between client and main frame is backed up, and then again will
Service response bag originally is sent to client.In the former service response bag, its source IP, source port number for client IP,
Port numbers.Simultaneously because the process of this forwarding need not allow what client was known, but client is allowed to think, it is received
Service response bag should be that it is sent to by main frame, therefore when service response bag is sent to client by standby host
Wait, the source IP of intermediary service response bag is revised as to the IP of main frame, source port number is revised as the port numbers of main frame.Meanwhile, it is standby
The Target IP of intermediary service response bag is revised as the IP of client by machine in order to which service response bag is issued into client,
Destination port number is revised as the port numbers of client, and intermediary service response bag is reduced to original service response bag, so, when
Client have received after service response bag, just will be considered that its service response bag received is sent by main frame.Here in
Between service response be data for being used to back up transmitted by from main frame to standby host, include the service response data produced by main frame with
And the link information between main frame and client.
For example:The conversion process of main frame response bag:
Host ip:192.168.1.10 port numbers 10000
Standby host IP:192.168.1.20 port numbers 20000
Client ip:192.168.1.30 port numbers 30000
Main frame is received after the service request from client, sends a service response bag, and its Target IP is
192.168.1.30, destination port number 30000, source IP is 192.168.1.10, source port number 10000;Main frame is revised as
Target IP 192.168.1.20, destination port number 20000, source IP is 192.168.1.30, source port number 30000;
Standby host is received after the bag and Backup Data, recovers bag, reverts to its Target IP for 192.168.1.30, target port
Numbers 30000, source IP is 192.168.1.10, source port number 10000.It is sent to client.
This design framework that standby machine is cascaded proposed in the present invention, can make full use of Transmission Control Protocol
The reliability mechanisms of itself ensure the reliable synchronization of hot standby network data, but add certain network burden.Any one
Moment, if client sends request and do not receive response, then it can repeat requests.When client have received response, then
Represent that backed up in synchronization crosses the TCP bag datas to standby host.Therefore, theoretically, data are that overall safety is reliable.
In addition, it is necessary to explanation, if the route system provided using operating system, then MAC Address is repaiied
Changing to be automatically performed, it is only necessary to change IP and port numbers.
Fig. 4 be in the double hot standby method that the embodiment of the present invention four is provided main frame by service response data and main frame with
Link information between client is sent to the schematic flow sheet of the another way of standby host.It is specially:
Step 401:The service response data are formed corresponding service response bag by main frame;The service response bag includes
Head and data segment;
Step 402:Main frame preserves the link information in the data segment of service response bag;
Step 403:The Target IP of the service response bag is revised as the IP of standby host by main frame, is standby host by destination port number
Port numbers, formed intermediary service response bag;
Step 404:Main frame sends the intermediary service response bag to standby host.
Service response data are sent to by another main frame provided in the present embodiment four different from embodiment two
The method of standby host, in the present embodiment four, main frame does not change the source IP of service response bag, source port number, only need to be by service response
The Target IP of bag, destination port number are revised as the IP of standby host, port numbers, and by the IP of client, port numbers, main frame and standby host
The sequence number of TCP links is maintained in the data segment of current service response bag, new intermediary service response bag is formed, when standby host connects
Receive after the intermediary service response bag, directly by the information such as the IP of client, port numbers from take business response bag data segment solution
Separate out, then backed up.
Shown in Figure 5 on the basis of the present embodiment four, the embodiment of the present invention five additionally provides a kind of standby host and will serviced
Reply data is sent to client approach with the identity of main frame, specifically includes:
Step 501:Standby host deletes the link information being stored in the intermediary service response bag data segment;
Step 502:The Target IP of the intermediary service response bag is revised as the IP of client by standby host, by destination port number
The port numbers of client are revised as, the service response bag is reduced to;
Step 503:Standby host sends the service response bag to client.
Standby host is after the intermediary service response bag transmitted by main frame is received, by corresponding service response data and link
Information parses backup from middle service response bag, simultaneously as link information is stored in intermediary service response bag
Data segment, and this link information will not issue client, therefore, standby host will be stored in the intermediary service response bag data
Link information in section is deleted, simultaneously as when intermediary service response bag is sent to standby host by main frame, service originally
The source IP of response bag, source port number are the IP of main frame, port numbers, and the Target IP of former response bag, destination port number are standby host
The IP of client, port numbers, therefore the Target IP of intermediary service response bag is revised as to the IP of client, target port should be repaiied
The port of client is changed to, so that intermediary service response bag to be reduced to original service response bag, is sent to client.
In addition, in addition it is also necessary to which the MAC Address of intermediary service response bag is revised as to the MAC Address of client.
Main frame can also can not also change the source IP of service response bag, source port number, source MAC, it is only necessary to change
Its Target IP, destination port number and destination-mac address, while service response bag directly is issued into standby host, directly by visitor
The information such as IP, port numbers and the MAC Address at family end are sent to standby host by extra communication.
Fig. 6 be in the double hot standby method that the embodiment of the present invention six is provided main frame by service response data and main frame with
Link information between client is sent to the schematic flow sheet of the another way of standby host.It is specifically included:
Step 601:The service response data are formed corresponding service response bag by main frame;The service response bag includes
Head and data segment;Source IP, source port number and the source MAC of the service response bag are preserved in the head, also protect
There are Target IP, destination port number and the destination-mac address of the service response bag;
Step 602:The service response bag is being increased into one layer of head in addition, new service response bag is formed;It is described another
The source IP address that outer increased one layer of head is preserved is the IP of main frame, and Target IP is the IP of standby host, and source port number is main frame
Port numbers, destination port number is the port numbers of standby host;Source MAC is the MAC Address of main frame, and destination-mac address is standby host
MAC Address;
Step 603:Main frame sends the new service response bag to standby host.
In the present embodiment, the service response bag that main frame forms service response data, the response bag is TCP data bag,
Include head and data segment, in TCP data bag, preserve the source IP of service response bag, source port number, source MAC,
The information such as Target IP, target port destination-mac address, the source IP of what main frame was formed will the issue service response bag of client,
Source port and source MAC are IP, port and the MAC Address of main frame, and its Target IP, target port and target
MAC Address should be IP, port and the MAC Address of client, and this service response bag will issue standby host and be backed up, this
Sending is sent with the delivery of IP mechanism actually, and its destination address should be IP, port numbers and the MAC Address of standby host.Therefore
In order to which service response bag smoothly is sent into standby host, the service response formed in standby host, which is wrapped, is further added by one layer of head
Portion, forms new service response bag.The source IP address preserved in the head is the IP of main frame, and Target IP is the IP of standby host, source
Port numbers are the port numbers of main frame, and destination port number is the port numbers of standby host;Source MAC is the MAC Address of main frame, target
MAC Address is the MAC Address of standby host.So, service response bag can be issued standby host.
Meanwhile, referring to Fig. 7, reply data is sent to the side of client by another standby host that the embodiment of the present invention seven is provided
In method,
Step 701:Standby host is by the new service response bag received by it, and increased one layer of head is deleted in addition, also
It is former into not increasing the service response bag on head;
Step 702:Standby host sends the service response bag to client.
On the basis of above-described embodiment six, standby host is after the new service response bag is received, by service response data
Peer link information is parsed from new service response bag, after being backed up, and will in addition be increased in the new service response bag
Plus one layer of head delete, being reduced into does not increase the service response bag on head, then again by this for increase head service response
Bag is sent to client.The service response bag for not increasing head is to be sent to the service response of client produced by main frame
Bag.
During Fig. 8 is the double hot standby method that the embodiment of the present invention eight is provided, standby host uses the main frame and client
The sequence number of TCP links sends the flow chart of service response data to client, specifically includes:
Step 801:Standby host constructs TCP handshake request bags, the source IP address of the TCP handshake request bags for client IP
Location, source port number is the port numbers of client;
Step 802:Standby host sends the TCP handshake requests bag constructed to itself, and standby host and client are set up at itself
Between TCP link;
Step 803:Standby host is after the TCP links are set up, in the kernel of itself operating system, by the TCP chains
The sequence number connect is revised as the sequence number that the TCP of the main frame and client is linked;
Step 804:Standby host is linked using the TCP, and service response data are sent to client.
In the present embodiment eight, main frame sends service response data to standby host, and by standby host that the service response data are standby
After part, it is during being forwarded to client, between standby host and client and does not set up TCP and link, but entered with IP mechanism
Row is directly delivered and sent.It is this it is direct deliver when sending need not the side of being delivered fed back.Thus when the IP address of standby host
Be changed to after the IP address of main frame, the service data that client is sent can all be sent to standby host, if not standby host with
If TCP links are set up between client, standby host makes feedback also without to this service data.Thus, in order to protect
Card is gone wrong in main frame, and the IP of standby host is changed to after the IP of main frame, and standby host can replace main frame, be provided normally for client
Service links it is necessary to set up corresponding TCP between standby host and client.But meanwhile, standby host does not allow client to know, is that it is carried
Changed for the main frame of service, thus standby host construction TCP handshake request bags, and by the TCP handshake requests bag of construction to itself
Send.Because the former IP of the TCP handshake request bags is client ip, source port number is the port numbers of client, therefore, and its institute is complete
Into TCP links be to be set up at itself actually, client is not aware that.The sequence number and host-client of this TCP links
TCP links sequence number it is different.
In order that obtaining two link docking, i.e. standby host be able to can not be discovered in client provides the main frame of service for it
It is replaced with the requirement of standby host, standby host is after the TCP links are set up, in the kernel of itself operating system, by the TCP
The sequence number of link is revised as the sequence number that the TCP of the main frame and client is linked;Then standby host is linked using the TCP,
Service response data are sent to client.
In addition, during Fig. 9 is the double hot standby method that the embodiment of the present invention nine is provided, another standby host uses the main frame
The sequence number linked with the TCP of client sends the flow chart of service response data to client, specifically includes:
Step 901:Standby host constructs TCP handshake request bags, the source IP address of the TCP handshake request bags for client IP
Location, source port number is the port numbers of client;
Step 902:Standby host sends the TCP handshake requests bag constructed to itself, and standby host and client are set up at itself
Between TCP link;
Step 903:Standby host to client sending service response bag and receives service request bag transmitted by client
When, the TCP sequence number to service response bag and service request bag is changed;
Wherein, the service of being preserved in service response data, the service request bag is preserved in the service response bag please
Seek data;
The TCP sequence number includes SEQ sequence numbers and ACK sequence numbers.
In order that obtaining two link docking, i.e. standby host be able to can not be discovered in client provides the main frame of service for it
Be replaced with the requirement of standby host, standby host after TCP link is set up, standby host to client send service response bag and
When receiving the service request bag transmitted by client, the TCP sequence number to service response bag and service request bag is changed;
Wherein, preserved in the service response bag in service response data, the service request bag and preserve service data;Institute
Stating TCP sequence number includes SEQ sequence numbers and ACK sequence numbers.
Referring to Figure 10, the embodiment of the present invention ten provides a kind of standby host and is sending service response bag and receiving to client
During service request bag transmitted by client, the tool that the TCP sequence number to service response bag and service request bag is changed
Body method, including:
Step 1001:Standby host receives first service request bag of the client using the TCP chain sending and receiving of main frame and client
When, the TCP of its TCP sequence number and standby host and client is linked into sequence number and made the difference, the difference is designated as deviant;
Step 1002:Network bottom layer capture client links the service for issuing standby host using the TCP of original host and client
Request bag, deviant is subtracted by its sequence number;
Step 1003:The standby host and the TCP of client that network bottom layer capture standby host is set up using standby host end, which are linked, to be sent out
To the service response bag of client, its sequence number is added into deviant.
During TCP links are set up, even the link between same server and client side, different chains
Connect, its sequence number is also different.Therefore, linked even establishing the TCP between standby host and client at standby host end, its
Sequence number between TCP of the sequence number also between original host and client is linked is different, therefore, if not to standby host and visitor
Between the end of family TCP link sequence number be corrected, that is, cause rebuild standby host-client TCP link sequence number with
The sequence number docking of the TCP links of original host-client, if making its sequence number between original host-client identical, visitor
Family end still will recognise that the client communicated with has been changed.
For example:When outside service request bag(Connect using old chain)Come in, his Serial No. SEQ=1000, ACK=
1000;The service request packet number that last time is received inside standby host(Use new url)For SEQ=100, ACK=100;So
When external service request bag enters fashionable, deviant is calculated first, be SEQ_OFFSET=1000-100=900, ACK_OFFSET=
1000-100=900;The sequence number of service request bag is converted again, i.e. SEQ=1000-900=100, ACK of service request bag=
1000-900=100;Thus become internal sequence order.When service response bag is sent, such as SEQ=110, ACK=
110, now plus deviant, it is changed into SEQ=1010, ACK=1010, as external sequence order.Data all afterwards please
Bag is sought, enters fashionable, deviant can be all subtracted, service response bag sends Shi Douhui plus deviant.
Backed up in realtime from existing unlike whole host TCP protocol stack method, this sequence number calibration method is to institute
Need the data of backup considerably less, greatly reduce the load of main frame and network.
In various embodiments of the present invention, after hot standby switch can by calibrate TCP sequence number by it is new and old link be docked at one
Rise.The method of two kinds of calibration TCP sequence numbers all without synchronous TCP protocol stack internal state, such as retransmission state, timer state,
Window size etc., but this relatively simple method is enough for conventional application.For the applied field of some specific demands
Close, can be with real-time synchronization kernel TCP protocol stack related data, by related data after standby host switching is reached the standard grade according to real needs
Kernel relevant position is covered, such as:tcp_sock、inet_connection_sock、inet_sock、sock、sock_
Common, request_sock, listen_sock and/or request_sock_queue etc..But synchrodata amount is larger,
Bear larger in heavy traffic condition lower network.
In addition, when main frame breaks down, the IP address that the IP address of itself is changed to main frame is specially by standby host:
Whether standby host breaks down every preset time detection main frame, surpasses if the heartbeat between such as main frame and standby host is linked
When, and the multiple ping main frames failure of standby host, then show that severely subnormal has occurred in host operating system, main frame event should be determined as
Barrier;
When certain detection of standby host, it is found that main frame breaks down, standby host will call what linux operating systems were provided
Local IP address is changed to the IP address of main frame by ifconfig interfaces, notification gateway, and now original host will be forced down by gateway
Line;
Host application program maintains the data of a current operating conditions information, including existing customer number, each client
The important information such as information state, the data will be by backed up in synchronization to standby host(I.e. above-mentioned data message), work as hostdown, it is standby
Machine is reached the standard grade and set up after all TCP links, and standby host will cover the running state information of current application program using the data message
Data, make application program realize redirecting for running status.
Monitor hot standby example
Two computers are configured first, wherein one is main frame, another is standby host.Main frame is different with MAC with standby host IP,
Same general switch is connected to, without using ARP(Address Resolution Protocol)Binding.Standby machine loading heat
Standby kernel module, for supervision network state.Standby machine runs identical server program, only exists some small differences, is used for
Distinguish standby machine and auxiliary hot standby switch.Standby host also needs to run hot standby main program, and the program mainly completes detection main frame and heat
The work of standby switching.
Two monitoring servers configure good related setting by above-mentioned requirements, and main frame opens normal service.Host detection is to standby
Machine, this aft engine is received after the request bag of client, and the bag that service port number is sent is issued standby host backup end by kernel module
Original bag is issued into client after slogan, standby host backup related data.When client initiates primary video request after the meeting, main frame should
Answer, and video data is forwarded directly to by client by UDP, it is not necessary to pass through standby host;TCP response bags will flow through standby host.
Work as machine when main frame breaks down, standby host will seize the IP address of main frame, standby host turns into new main frame.New main frame is internally
Quick to rebuild TCP links, calibrating sequence number makes client TCP normally run, and nothing is discovered.Meanwhile, Backup Data will also be notified should
Work as machine moment state with program host, because main frame is transmitting UDP video datas when machine, therefore standby host turns into new main frame
Afterwards, it will continue to send UDP video datas toward client.In this way, client is in standby machine hot standby switch, several seconds interim cards are only existed
Time, it will recover normal afterwards, all TCP/UDP communications of client need not be rebuild.
Finally it should be noted that:The above embodiments are merely illustrative of the technical solutions of the present invention, rather than its limitations;Although
The present invention is described in detail with reference to the foregoing embodiments, it will be understood by those within the art that:It still may be used
To be modified to the technical scheme described in foregoing embodiments, or equivalent substitution is carried out to which part technical characteristic;
And these modification or replace, do not make appropriate technical solution essence depart from various embodiments of the present invention technical scheme spirit and
Scope.