WO2017121063A1 - 一种无丢包零停机重启网络服务的方法和系统 - Google Patents

一种无丢包零停机重启网络服务的方法和系统 Download PDF

Info

Publication number
WO2017121063A1
WO2017121063A1 PCT/CN2016/083903 CN2016083903W WO2017121063A1 WO 2017121063 A1 WO2017121063 A1 WO 2017121063A1 CN 2016083903 W CN2016083903 W CN 2016083903W WO 2017121063 A1 WO2017121063 A1 WO 2017121063A1
Authority
WO
WIPO (PCT)
Prior art keywords
port
connection
network service
new
old
Prior art date
Application number
PCT/CN2016/083903
Other languages
English (en)
French (fr)
Inventor
陈迅
Original Assignee
网宿科技股份有限公司
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 网宿科技股份有限公司 filed Critical 网宿科技股份有限公司
Priority to EP16884622.8A priority Critical patent/EP3310026B1/en
Priority to US15/552,216 priority patent/US10348558B2/en
Publication of WO2017121063A1 publication Critical patent/WO2017121063A1/zh

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/2866Architectures; Arrangements
    • H04L67/30Profiles
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/08Configuration management of networks or network elements
    • H04L41/0803Configuration setting
    • H04L41/0813Configuration setting characterised by the conditions triggering a change of settings
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/50Network service management, e.g. ensuring proper service fulfilment according to agreements
    • H04L41/5041Network service management, e.g. ensuring proper service fulfilment according to agreements characterised by the time relationship between creation and deployment of a service
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/50Network service management, e.g. ensuring proper service fulfilment according to agreements
    • H04L41/5077Network service management, e.g. ensuring proper service fulfilment according to agreements wherein the managed service relates to simple transport services, i.e. providing only network infrastructure
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • 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/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • H04L67/025Protocols based on web technology, e.g. hypertext transfer protocol [HTTP] for remote control or remote monitoring of applications
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/30Definitions, standards or architectural aspects of layered protocol stacks

Definitions

  • the present invention relates to a network service technology for restarting, and more particularly to a method and system for restarting a network service with zero downtime, so that not only can all new connections be processed normally when the network service is restarted, but the connection is not interrupted.
  • some network services must restart the process to complete the restart or reload the configuration file.
  • a typical example is the HAProxy web service provided on many heavily loaded web sites.
  • This network service uses the SO_REUSEPORT option to bind the new process to the same IP address and port as the old process to start listening for new connections, and then signals the old process to close the socket of the listening port.
  • new connections may come in the short time gap when both the old and new processes are bound to the same IP and port, and the old process's listening socket is not closed.
  • the first message (SYN message) of the new connection may be assigned to any of the new and old processes.
  • the server sends a TCP RST message to the client to reset the connection.
  • This will cause a normal connection to be reset unconditionally.
  • the client can re-initiate the connection, it undoubtedly increases the time required for the entire data transmission and adds an unnecessary burden to the network connection between the client and the server.
  • HAProxy network service there is a problem that the process must be restarted to complete the restart or reload the configuration file.
  • the waiting time is usually very long, for example, more than 1 second, but the process reloading time usually takes only tens of milliseconds, which causes the new process that has completed the reload to wait for about 1 second. Received a resent SYN packet. Therefore, Although the new connection in this scenario will not be reset, it will result in a longer delay.
  • tc Linux's flow control tool
  • tc Linux's flow control tool
  • the delay caused by this scheme is relatively short.
  • the tc tool can only control the outgoing traffic, the usage scenario is limited. For example, when the service process listens as the listening process and accepts the client connection, since the SYN message is the incoming traffic at this time, the solution using the tc tool cannot be used to solve the above problem.
  • the present invention provides a new method and system for restarting network services without packet loss and zero downtime. Compared with other existing methods, it has no delay, is effective for outgoing incoming connections, and has unlimited advantages in use scenarios.
  • a method of restarting a network service comprising:
  • a system for restarting a network service characterized in that the system comprises:
  • the server is a web site that provides various network services
  • the client proposes to restart the network service to the server
  • the server is configured to perform the following steps to implement a restart of the network service:
  • FIG. 1 illustrates an example environment in which embodiments in accordance with the present invention may be implemented.
  • FIG. 2 shows a flow chart of a method of restarting a network service with zero downtime, in accordance with an embodiment of the present invention.
  • FIG. 1 An example environment 100 implementing an embodiment in accordance with the present invention is shown in FIG.
  • a network environment 110 is included
  • the network environment in which the client and server are located can be a local area network, the Internet, or other wide area network.
  • the server 130 can be a web site that provides various network services, such as an HAProxy network service, where the network service must restart the process to complete the reboot or reload the configuration file.
  • the client 120 requests the server 130 for the network service through the Internet 110.
  • Netfilter is a network-related subsystem in the Linux kernel. As a general, abstract framework, it provides functions such as packet filtering, packet modification, and Network Address Translation (NAT).
  • NAT Network Address Translation
  • connection tracking is an important function in the Netfilter framework, and it is also the basis of packet filtering and address translation. Its basic function is to track and record the connection status. It runs as a standalone module.
  • the connection tracking technology intercepts the data packet at the lower layer of the protocol stack, compares the current data packet and its status information with the historical data packet and its status information, thereby obtaining control information of the current data packet, and determining the network data packet according to the information. Operation to achieve the purpose of protecting the network.
  • Linux's Netfilter framework generates a new connection record for each packet that passes through the network stack. Thereafter, all packets belonging to this connection are uniquely assigned to this connection and identify the status of the connection.
  • Connection tracking is the basis for Netfilter's stateful inspection and is a prerequisite for implementing Network Address Translation (NAT).
  • NAT Network Address Translation
  • the packet When the underlying network receives the Initial Synchronize (SYN) packet, the packet will be checked by the netfilter rule base. The packet will be compared sequentially in the rule chain. If the packet should be discarded, send a Reset (RST) packet to the remote host, otherwise the connection is received. The information of this connection will be saved in the connection tracking information table and indicate the status of the data packet.
  • the connection tracking information table is located in the kernel mode, and the subsequent network data packet is compared with the content in the connection tracking information table, and the operation of the data packet is determined according to the information in the information table. Because the data packet is first compared with the connection tracking information table, only the SYN packet is compared with the rule base, and the comparison between the data packet and the connection tracking information table is performed in the kernel mode, so the processing speed is fast.
  • the present invention is a clever use of the characteristics of the Netfilter connection tracking mechanism: according to the implementation of the connection tracking mechanism, the relevant rules only match the first message of each connection, and the subsequent messages are automatically processed by the connection tracking mechanism. . Thus, we can take advantage of this to distinguish between new and old connections, and to direct all new connections to the new process without affecting the old connections to the old processes.
  • connection tracking mechanism In the detailed steps of Figure 2 below, it is assumed that the connection tracking mechanism is turned off when the server is running.
  • FIG. 2 there is shown a zero downtime restart network in accordance with an embodiment of the present invention.
  • step 210 it is assumed that the old process of the network service is listening on the A port.
  • the A port is just a port name for convenience of explanation, and is not intended to limit the process to a specific port.
  • step 220 the transition process is configured and started. Modify the configuration file of the network service, configure the transition process to listen on the different port from the old process, and start the transition process. This assumes that the transition process is listening on the B port.
  • the B port is merely for convenience of explaining a port different from the A port, and it is not intended to limit the process to a specific port.
  • step 230 the connection tracking module is loaded and kept running so that the subsequently added iptables DNAT rules can work properly. Note that if the connection tracking mechanism is already enabled when the server is running, that is, the connection tracking mechanism is run by default, this step can be omitted and the next step can be directly processed.
  • the iptables rule is configured by the connection tracking module to redirect the connection originally directed to the A port to the B port.
  • a redirect iptables rule can be added by entering the following command:
  • step 250 after waiting for all existing connections on the old process to be processed, the old process can be exited.
  • step 260 a new configuration file is used to initiate a new process listening to the A port.
  • the new process will not receive a new connection for the time being because the new connection is redirected to the transition process listening on the B port.
  • the iptables rule is reconfigured to cancel port redirection from port A to port B. For example, you can enter the following command to cancel the previously set redirect iptables rule:
  • step 280 the transition process is exited after waiting for all processing of the existing connection on the transition process to complete.
  • connection tracking module can be uninstalled at step 290 to save system resources. If the server has been running the connection tracking mechanism by default, you can omit this step and let the connection tracking module continue to run.
  • the present invention provides the following main advantages by providing a transition process to handle new connections received by the old and new process switching gaps:
  • 3.iptables is the application layer rule configuration tool of Netfilter.
  • the invention uses a series
  • the iptables command can be implemented without modifying the source code of the kernel or network service program.

Abstract

本发明涉及一种无丢包零停机重启网络服务的方法和系统,包括:a)所述网络服务的旧进程在一端口上进行监听;b)配置并启动过渡进程,所述配置包括使得所述过渡进程在与旧进程不同的另一端口上进行监听;c)在连接跟踪模块运行的同时,添加iptables规则来将定向到所述一端口的连接重定向到所述另一端口;d)一直等待直到所述旧进程上的已有连接全部处理完毕后,才退出所述旧进程;e)使用新的配置文件在所述一端口上启动新进程;f)重新配置iptables规则以取消端口的重定向;以及g)一直等待直到所述过渡进程上的已有连接全部处理完毕后,退出过渡进程。

Description

一种无丢包零停机重启网络服务的方法和系统 技术领域
本发明涉及一种重启网络服务技术,更具体而言,涉及一种零停机重启网络服务的方法和系统,使得在重启网络服务时不仅能正常处理所有的新连接,而且不会造成连接中断。
背景技术
在现有的各种网络服务中,某些网络服务必须重新启动进程才能完成重启或者重新载入配置文件。典型的例子是在很多负载特别大的web站点中所提供的HAProxy网络服务。此网络服务通过使用SO_REUSEPORT选项,将新进程绑定到与旧进程完全相同的IP地址和端口开始监听新的连接,再发送信号通知老进程关闭监听端口的套接字(socket)。但是,当新老两个进程都绑定到同一个IP和端口,并且老进程的监听套接字还未关闭的短暂时间间隙中新的连接可能会到来。根据Linux内核中SO_REUSEPORT的实现,新连接的第一个报文(SYN报文)可能会被分配给新老进程中的任意一个。如果这个SYN报文被分配给老进程,而紧接着老进程的监听套接字又被关闭,根据TCP协议,服务端会发送一个TCP RST报文给客户端重置这条连接。这会造成一条正常的连接被无条件重置。虽然客户端可以重新发起连接,但这无疑增加了整个数据传输所需要的时间,也给连接客户端与服务器的网络线路增加了不必要的负担。除了在上述HAProxy网络服务中存在必须重新启动进程才能完成重启或者重新载入配置文件的问题之外,还有许多网络服务存在同样的问题,例如:nginx网络服务等。
针对所述网络服务中存在的这一问题,目前已经提供了一些解决方案。一种简单的做法是在进程重载期间配置iptables规则来丢弃掉新收到的SYN报文。根据TCP协议,客户端在没有收到SYN/ACK报文一段时间后就会重新发送SYN报文,这样,重新发送的SYN报文就能被已经完成重载的新进程顺利接收,从而解决了所述问题。但是,这一方案的不足之处在于,客户端必须等待一段时间直到超时以重新发送SYN报文。而这段等待时间通常都很长,例如在1秒种以上,但进程重载的时间往往只需要几十毫秒,这就导致已经完成重载的新进程必须多等待例如1秒左右的时间才能接收到重新发送的SYN报文。因此, 尽管在这一方案中的新连接不会被重置,但却带来了较长时间的延时。
另一个可行的现有解决方案是利用Linux的流量控制工具(tc)。先使用iptables来标记新流入的SYN报文,再用tc工具暂时缓存这些报文。在进程完成重载之后,再释放这些SYN报文。相比于上一解决方案,这一方案所引起的延时相对较短。但是,由于tc工具只能控制流出的流量,因而使用场景受到了一定的限制。例如,在服务进程作为监听进程监听并接受客户端连接时,由于此时SYN报文为流入流量,所述的使用tc工具的方案就无法被用于解决上述问题。
因此,存在一种对能够提供一种具有没有延时、对传出传入的连接都有效且使用场景不受限制等优点的重启网络服务的技术的需求。
发明内容
为了解决现有技术中的所述缺陷,本发明提供了一种新的无丢包零停机重启网络服务的方法和系统。相比于现有的其它方法,其具有无延时,对传出传入的连接都有效且使用场景不受限制等优点。
在本发明的一个方面,提供了一种重启网络服务的方法,所述方法包括:
a)所述网络服务的旧进程在一端口上进行监听;
b)配置并启动过渡进程,所述配置包括使得所述过渡进程在与旧进程不同的另一端口上进行监听;
c)在连接跟踪模块运行的同时,添加iptables规则来将定向到所述一端口的连接重定向到所述另一端口,使得原本应连接到所述一端口上的后续连接被全部重定向到在所述另一端口上监听的所述过渡进程;d)一直等待直到所述旧进程上的已有连接全部处理完毕后,才退出所述旧进程;
e)使用新的配置文件在所述一端口上启动新进程;
f)重新配置iptables规则以取消端口的重定向,这样,原本应连接到所述一端口上的后续新连接不再被重定向,还是连向在所述一端口上监听的新进程;以及
g)一直等待直到所述过渡进程上的已有连接全部处理完毕后,退出过渡进程。
根据本发明的另一方面,提供了一种重启网络服务的系统,其特征在于,所述系统包括:
服务端,所述服务端是提供各种网络服务的web站点;
客户端,所述客户端向所述服务器端提出重启网络服务的请求;
网络环境,通过所述网络环境,所述服务端和所述客户端可以进行数据通 信;
其中,所述服务端被配置为执行下述步骤以实现网络服务的重启:
a)所述网络服务的旧进程在一端口上进行监听;
b)配置并启动过渡进程,所述配置包括使得所述过渡进程在与旧进程不同的另一端口上进行监听;
c)在连接跟踪模块运行的同时,添加iptables规则来将定向到所述一端口的连接重定向到所述另一端口,使得原本应连接到所述一端口上的后续连接被全部重定向到在所述另一端口上监听的所述过渡进程;d)一直等待直到所述旧进程上的已有连接全部处理完毕后,才退出所述旧进程;
e)使用新的配置文件在所述一端口上启动新进程;
f)重新配置iptables规则以取消端口的重定向,这样,原本应连接到所述一端口上的后续新连接不再被重定向,还是连向在所述一端口上监听的新进程;以及
g)一直等待直到所述过渡进程上的已有连接全部处理完毕后,退出过渡进程。
提供本概述是为了以简化的形式介绍将在以下详细描述中进一步描述的一些概念。本概述不旨在标识出所要求保护的主题的关键特征或必要特征,也不旨在用于帮助确定所要求保护的主题的范围。
附图说明
为了描述可获得本发明的上述和其它优点和特征的方式,将通过参考附图中示出的本发明的具体实施例来呈现以上简要描述的本发明的更具体描述。可以理解,这些附图只描绘了本发明的各典型实施例,并且因此不被认为是对其范围的限制,将通过使用附图并利用附加特征和细节来描述和解释本发明,在附图中:
图1示出了在其中可以实现根据本发明的实施例的示例环境。
图2示出了根据本发明的实施例的一种零停机重启网络服务的方法的流程图。
具体实施方式
下面结合附图和实施例对本发明作进一步的描述。
首先,描述下实现本发明的实施例的系统环境。在图1中示出了实现根据本发明的实施例的示例环境100。在所述示例环境100中,包括网络环境110 进行通信的客户端(客户机)120和服务端(服务器)130。客户端和服务器所处的网络环境可以是局域网、因特网或其它广域网。所述服务端130可以是提供各种网络服务的web站点,例如,HAProxy网络服务,其中所述网络服务必须重新启动进程才能完成重启或者重新载入配置文件。而所述客户端120则通过因特网110来向服务端130请求网络服务。
在介绍完本发明的示例环境之后,现在就本发明的原理加以说明。
首先,Netfilter是Linux内核中的一个与网络功能相关的子系统。它作为一个通用的、抽象的框架,提供了数据包过滤、数据包修改、网络地址转换(Network Address Translation,NAT)等功能。
连接跟踪(conntrack)机制是Netfilter框架中的一个重要功能,也是包过滤、地址转换的基础。其基本功能是跟踪并且记录连接状态。它作为一个独立的模块运行。采用连线跟踪技术在协议栈低层截取数据包,将当前数据包及其状态信息与历史数据包及其状态信息进行比较,从而得到当前数据包的控制信息,根据这些信息决定对网络数据包的操作,达到保护网络的目的。具体而言,Linux的Netfilter框架为每一个经过网络栈的数据包,生成一个新的连接记录项。此后,所有属于此连接的数据包都被唯一地分配给这个连接,并标识连接的状态。连接跟踪是Netfilter的状态检测的基础,同时也是实现网络地址转换(NAT)功能的前提。
当下层网络接收到初始化连接同步(Synchronize,SYN)数据包后,该数据包将由netfilter规则库进行检查。该数据包将在规则链中依次序进行比较。如果该包应被丢弃,发送一个复位(Reset,RST)数据包到远端主机,否则连接被接收。这次连接的信息将被保存在连线跟踪信息表中,并表明该数据包所应有的状态。这个连线跟踪信息表位于内核模式下,其后的网络数据包就将与此连线跟踪信息表中的内容进行比较,根据信息表中的信息来决定该数据包的操作。因为数据包首先是与连线跟踪信息表进行比较,只有SYN包才与规则库进行比较,并且数据包与连线跟踪信息表的比较都是在内核模式下进行的,所以处理速度很快。
而本发明正是巧妙利用了Netfilter的连接跟踪机制的所述特点:根据连接跟踪机制的实现,相关规则只匹配每条连接的第一个报文,后续的报文则由连接跟踪机制自动处理。从而,我们可以利用这一点,区分新连接和老连接,并将新连接全部引导给新进程,同时不影响与老进程上的旧连接。
不过,许多线上机器出于性能方面的考虑,关闭了连接跟踪机制。因此,本发明需要在网络服务重载,进行进程切换时,临时开启连接跟踪机制来实现所述方案。在下述图2的详细步骤中,假设服务器运行时关闭了连接跟踪机制。
现在参考图2,在图2中示出了根据本发明的实施例的一种零停机重启网 络服务的方法200的流程图。
首先,在步骤210,假设网络服务的旧进程在A端口监听。注意所述A端口仅仅是为了方便说明而起的端口名,并不是要将所述进程局限于某个特定端口。
当网络服务重载而需要进行进程切换时,在步骤220,配置并启动过渡进程。修改网络服务的配置文件,配置过渡进程在与旧进程不同的端口上监听,并启动该过渡进程。此处假设过渡进程在B端口上监听。如上所述,所述B端口仅仅是为了方便说明不同于A端口的一个端口,并不是要将所述进程局限于某个特定端口。
随后,由于假设服务器运行时关闭了连接跟踪机制以提高性能,因此,在步骤230,加载连接跟踪模块并使其保持运行,以便后续添加的iptables DNAT规则能正常工作。注意,如果服务器在运行时原本已经开启了连接跟踪机制,也即默认运行连接跟踪机制,则可以省略该步骤,而直接进行下一步骤的处理。
接着,在步骤240,通过连接跟踪模块配置iptables规则,以将原本定向到A端口的连接重定向到B端口,例如可以通过输入下述指令来添加一条重定向iptables规则:
iptables-A PREROUTING-i eth0-t nat-p tcp--dport$A--syn-j DNAT--to 1.2.3.4:$B
上述指令中各参数的具体含义如下:
-A PREROUTING:规则添加到PREROUTING链
-i eth0:指定网络设备为eth0
-t nat:规则添加到nat表
-p tcp:指定协议为TCP
--dport$A:目的端口为$A端口
--syn:匹配SYN报文
-j DNAT--to 1.2.3.4:$B:报文重定向到IP 1.2.3.4,端口$B
在配置此重定向iptables规则后,本来将连入到A端口上的新连接将全部被重定向到在B端口上监听的过渡进程。而由于连接跟踪机制的特性,旧进程上的已有连接则不受此规则的影响继续其处理。
此时,由于所有新连接都被重定向到在B端口上监听的过渡进程,旧进程就不会再收到新连接。这样,在步骤250,等待旧进程上的已有的连接全部处理完毕后,就可退出旧进程。
在退出旧进程后,此时A端口就不再被占用。因此,在步骤260,使用新的配置文件来启动新进程监听A端口。但是,由于iptables规则的影响,该 新进程暂时不会收到新连接,因为所述新连接都被重定向到在B端口上监听的过渡进程。
随后,在启动了新进程之后,在步骤270,重新配置iptables规则,来取消端口A到端口B的端口重定向。例如可以输入下述指令来取消先前设定的重定向iptables规则:
iptables-D PREROUTING-i eth0-t nat-p tcp--dport$A--syn-j DNAT--to 1.2.3.4:$B
上述指令中各参数的具体含义如下:
-A PREROUTING:从PREROUTING链中删除规则
-i eth0:指定网络设备为eth0
-t nat:规则添加到nat表
-p tcp:指定协议为TCP
--dport$A:目的端口为$A端口
--syn:匹配SYN报文
-j DNAT--to 1.2.3.4:$B:报文重定向到IP 1.2.3.4,端口$B
需要指出的是,上述指令和其参数仅仅是出于说明目的,而非对本发明的方案的具体限定。本领域的技术人员可以很容易地根据实际情况和自身需要来调整所述参数以实现期望的重定向和取消重定向。
在执行了该指令之后,后续新连接将全部连向到新进程所监听的A端口,也即在此之后的所有新连接将由监听A端口的新进程来处理,而过渡进程的已有连接则不受影响地被继续处理。
此时,由于所有新连接都被重定向到在A端口上监听的新进程,过渡进程就不会再收到新连接。这样,在步骤280,在等待过渡进程上的已有连接全部处理完成后,就退出该过渡进程。
到此,由于连接跟踪模块的使命已经完成,因此,为了不影响服务器运行的性能,可以在步骤290卸载该连接跟踪模块以节省系统资源。而如果服务器原本默认就一直运行连接跟踪机制,则可以省略该步骤,让连接跟踪模块继续运行。
至此,新旧进程切换过程结束。在整个网络服务重载过程中,由于提供了过渡进程来处理新旧进程切换间隙所接收到的新连接,因此,本发明提供了下述主要优点:
1.重启网络服务时,新到来连接的建立不会产生延时。
2.对传出传入的连接都有效。
3.iptables是Netfilter的应用层规则配置工具。本发明使用一系列 iptables命令即可实现,无需修改内核或者网络服务程序的源代码。
上述过程中的各步骤已经在Haproxy网络服务的重载时使用并验证。实践表明,使用了本发明中所述方法后,Haproxy网络服务在重载时不会重置新连接,新连接的建立也无延时。尽管在Haproxy网络服务中已经证明本发明的方案的良好作用,但这并不意味着本发明的方案仅仅局限于Haproxy网络服务。对于存在必须重新启动进程才能完成重启或者重新载入配置文件的问题的其它网络服务来说,本发明也能很好地实现类似的网络服务的零停机重载。为了节省篇幅,在此不再详细描述。
尽管,上述实施例中是在Linux的环境中实现,但其它与基于Linux的操作系统环境也可适用本发明的技术方案,例如Android操作系统,Openwrt操作系统等。
上述实施例是提供给本领域普通技术人员来实现和使用本发明的,本领域普通技术人员可在不脱离本发明的发明思想的情况下,对上述实施例做出种种修改或变化,因而本发明的保护范围并不被上述实施例所限,而应该是符合权利要求书所提到的创新性特征的最大范围。

Claims (9)

  1. 一种重启网络服务的方法,其特征在于,包括:
    a)所述网络服务的旧进程在一端口上进行监听;
    b)配置并启动过渡进程,所述配置包括使得所述过渡进程在与旧进程不同的另一端口上进行监听;
    c)在连接跟踪模块运行的同时,添加iptables规则来将定向到所述一端口的连接重定向到所述另一端口,使得原本应连接到所述一端口上的后续连接被全部重定向到在所述另一端口上监听的所述过渡进程;d)一直等待直到所述旧进程上的已有连接全部处理完毕后,才退出所述旧进程;
    e)使用新的配置文件在所述一端口上启动新进程;
    f)重新配置iptables规则以取消端口的重定向,这样,原本应连接到所述一端口上的后续新连接不再被重定向,还是连向在所述一端口上监听的新进程;以及
    g)一直等待直到所述过渡进程上的已有连接全部处理完毕后,退出过渡进程。
  2. 如权利要求1所述的方法,其特征在于,还包括:
    如果所述网络服务的服务器在重启网络服务之前已经关闭了连接跟踪机制,则在执行步骤c之前,加载所述连接跟踪模块来启动所述连接跟踪机制,使得iptables规则能正常工作。
  3. 如权利要求2所述的方法,其特征在于,还包括:
    在执行完步骤g之后,卸载所述连接跟踪模块以提高服务器的性能。
  4. 如权利要求1所述的方法,其特征在于,其中,所述连接跟踪模块是Netfilter框架中的一个功能模块,其被配置为:为每一个经过网络栈的数据包,生成一个新的连接记录项,此后,所有属于此连接的数据包都被唯一地分配给这个连接,并标识连接的状态。
  5. 如权利要求1所述的方法,其特征在于,其中所述一端口是A端口,而所述另一端口是B端口,则添加所述iptables规则来进行重定向可通过下述指令来实现:
    iptables -A PREROUTING -i eth0 -t nat -p tcp --dport $A --syn -j DNAT --to 1.2.3.4:$B;
    并且,通过下述指令来重新配置所述iptables规则以取消所述重定向:
    iptables -D PREROUTING -i eth0 -t nat -p tcp --dport $A --syn -j  DNAT --to 1.2.3.4:$B。
  6. 如权利要求4所述的方法,其特征在于,所述Netfilter框架是Linux内核中的一个与网络功能相关的子系统,它提供了数据包过滤、数据包修改、网络地址转换等功能。
  7. 如权利要求1所述的方法,其特征在于,所述网络服务是HAProxy网络服务或者nginx网络服务。
  8. 一种重启网络服务的系统,其特征在于,所述系统包括:
    服务端,所述服务端是提供各种网络服务的web站点;
    客户端,所述客户端向所述服务器端提出重启网络服务的请求;
    网络环境,通过所述网络环境,所述服务端和所述客户端可以进行数据通信;
    其中,所述服务端被配置为执行下述步骤以实现网络服务的重启:
    a)所述网络服务的旧进程在一端口上进行监听;
    b)配置并启动过渡进程,所述配置包括使得所述过渡进程在与旧进程不同的另一端口上进行监听;
    c)在连接跟踪模块运行的同时,添加iptables规则来将定向到所述一端口的连接重定向到所述另一端口,使得原本应连接到所述一端口上的后续连接被全部重定向到在所述另一端口上监听的所述过渡进程;d)一直等待直到所述旧进程上的已有连接全部处理完毕后,才退出所述旧进程;
    e)使用新的配置文件在所述一端口上启动新进程;
    f)重新配置iptables规则以取消端口的重定向,这样,原本应连接到所述一端口上的后续新连接不再被重定向,还是连向在所述一端口上监听的新进程;以及
    g)一直等待直到所述过渡进程上的已有连接全部处理完毕后,退出过渡进程。
  9. 如权利要求8所述的系统,其特征在于,所述网络环境是局域网、因特网或其它广域网。
PCT/CN2016/083903 2016-01-15 2016-05-30 一种无丢包零停机重启网络服务的方法和系统 WO2017121063A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP16884622.8A EP3310026B1 (en) 2016-01-15 2016-05-30 Method and system for use in restarting network service without packet loss and downtime
US15/552,216 US10348558B2 (en) 2016-01-15 2016-05-30 Method and system for restarting network service without packet loss and with zero downtime

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610028287.8A CN105450782B (zh) 2016-01-15 2016-01-15 一种无丢包零停机重启网络服务的方法和系统
CN201610028287.8 2016-01-15

Publications (1)

Publication Number Publication Date
WO2017121063A1 true WO2017121063A1 (zh) 2017-07-20

Family

ID=55560548

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/083903 WO2017121063A1 (zh) 2016-01-15 2016-05-30 一种无丢包零停机重启网络服务的方法和系统

Country Status (4)

Country Link
US (1) US10348558B2 (zh)
EP (1) EP3310026B1 (zh)
CN (1) CN105450782B (zh)
WO (1) WO2017121063A1 (zh)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105450782B (zh) * 2016-01-15 2018-11-06 网宿科技股份有限公司 一种无丢包零停机重启网络服务的方法和系统
CN108243196B (zh) * 2018-01-22 2020-09-25 北京启明星辰信息安全技术有限公司 Netfilter架构下引入TCP协议栈的方法及系统、中间设备、介质
CN110134453B (zh) * 2018-02-09 2022-07-08 网宿科技股份有限公司 服务器配置重载方法及服务器
CN109669817A (zh) * 2018-12-19 2019-04-23 深圳市活力天汇科技股份有限公司 一种基于PM2的Node.js服务器重启方法
CN109981365B (zh) * 2019-03-26 2022-03-25 深圳市科力锐科技有限公司 数据监听方法、装置、用户设备及存储介质
CN111158776B (zh) * 2019-12-12 2023-12-26 杭州安恒信息技术股份有限公司 一种Web应用防护系统平滑重启方法
CN114915669A (zh) * 2021-02-08 2022-08-16 北京金山云网络技术有限公司 一种基于quic协议的服务升级方法、装置及电子设备
CN115426325A (zh) * 2022-09-16 2022-12-02 杭州云合智网技术有限公司 堆叠环境中单台Leaf设备重启的单播零丢包方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6634025B1 (en) * 1996-05-06 2003-10-14 Koninklijke Philips Electronics N. V. System for exchanging software processes during execution using threads
CN104461628A (zh) * 2014-12-09 2015-03-25 珠海迈科智能科技股份有限公司 一种控制服务器程序更新的方法和装置
CN105100232A (zh) * 2015-07-14 2015-11-25 焦点科技股份有限公司 一种不中断服务的服务端程序平滑升级的方法
CN105450782A (zh) * 2016-01-15 2016-03-30 网宿科技股份有限公司 一种无丢包零停机重启网络服务的方法和系统

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7437606B2 (en) 2004-08-23 2008-10-14 Hewlett-Packard Development Company, L.P. Method of checkpointing parallel processes in execution within plurality of process domains
US7930733B1 (en) * 2006-04-10 2011-04-19 At&T Intellectual Property Ii, L.P. Method and system for execution monitor-based trusted computing
US20150156183A1 (en) * 2013-12-03 2015-06-04 GateSecure S.A. System and method for filtering network communications
US9794139B2 (en) * 2014-03-07 2017-10-17 International Business Machines Corporation Allocating operators of a streaming application to virtual machines based on monitored performance
CN104702534B (zh) * 2015-03-30 2018-02-06 无锡天脉聚源传媒科技有限公司 一种实现多进程共享端口的数据处理的方法及装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6634025B1 (en) * 1996-05-06 2003-10-14 Koninklijke Philips Electronics N. V. System for exchanging software processes during execution using threads
CN104461628A (zh) * 2014-12-09 2015-03-25 珠海迈科智能科技股份有限公司 一种控制服务器程序更新的方法和装置
CN105100232A (zh) * 2015-07-14 2015-11-25 焦点科技股份有限公司 一种不中断服务的服务端程序平滑升级的方法
CN105450782A (zh) * 2016-01-15 2016-03-30 网宿科技股份有限公司 一种无丢包零停机重启网络服务的方法和系统

Also Published As

Publication number Publication date
US20180069755A1 (en) 2018-03-08
EP3310026A1 (en) 2018-04-18
CN105450782B (zh) 2018-11-06
CN105450782A (zh) 2016-03-30
EP3310026A4 (en) 2018-08-22
EP3310026B1 (en) 2020-04-08
US10348558B2 (en) 2019-07-09

Similar Documents

Publication Publication Date Title
WO2017121063A1 (zh) 一种无丢包零停机重启网络服务的方法和系统
US9762508B2 (en) Relay optimization using software defined networking
JP5648926B2 (ja) ネットワークシステム、コントローラ、ネットワーク制御方法
US11277341B2 (en) Resilient segment routing service hunting with TCP session stickiness
WO2017066359A1 (en) Determining direction of network sessions
US9264365B2 (en) Split transport control protocol (TCP) flow control management in a cellular broadband network
WO2015132630A1 (en) Methods and systems for forwarding data
US10958547B2 (en) Verify a network function by inquiring a model using a query language
EP2922263B1 (en) Processing method for network address translation technology, nat device and bng device
US9882813B2 (en) Apparatus and method for flow control
US11005813B2 (en) Systems and methods for modification of p0f signatures in network packets
US20130054817A1 (en) Disaggregated server load balancing
CN112769850B (zh) 网络报文过滤方法、电子设备及存储介质
JP6662136B2 (ja) 中継装置、通信システム、中継方法及び中継プログラム
US20170339219A1 (en) Transparent wide-area service migration with mptcp
CN111181985B (zh) 数据传输方法、数据传输系统、防火墙设备和存储介质
US10496415B2 (en) Method and system for restarting network service
US20190089675A1 (en) Network address translation device, setting requesting device, communication system, communication method and storage medium storing program
US9813295B2 (en) Wireless network optimization appliance
CN105208072A (zh) 虚拟交换机的远程控制方法及装置
US20240121187A1 (en) Deploying ipv6 routing
JP2019103118A (ja) 通信中継装置、通信中継プログラム、および通信中継方法
JP2017173995A (ja) サーバ装置、クラウドシステムおよびウェブアプリケーション切り替え方法
KR102082889B1 (ko) 프로토콜 분석 장치 및 방법
US20240007435A1 (en) Chassis system management through data paths

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 15552216

Country of ref document: US

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16884622

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE