About Keepalive of those things

Many students, including their own server without clear understanding of the keepalive, often confused, TCP also keepalive, HTTP also keepalive, availability also called keepalive, often confuse these concepts. Description of these concepts do next, although the name is basically the same, but the meaning and scope of representation is very different.

Availability Keepalived

Service availability is a program implemented based Keepalived VRRP protocol, which may be utilized to avoid IP single point of failure. Its role is to detect the state of the server, if a server is down, or fails, Keepalived detected, the other server instead of the server's operation, when the server work Keepalived server automatically added to the server farm.
Keepalived generally not alone, but with other load balancing technology (such as lvs, haproxy, nginx) work together to achieve high availability cluster.

A simple example of the use of the DNS to a load balancing machine, then load balancing reverse proxy machine to the WEB. Middle load balancing only one, can not achieve high availability, need to do at least two, arranged that after the two machines, Keepalived you can ensure that the service is only one external virtual IP, if MASTER load balancing failed time, automatically switch to BACKUP load balancing services are not affected. Keepalived to ensure these.

We previously had a slightly more complex service configuration, Keepalived HAProxy to provide high availability, then HAProxy to Twemproxy provide high availability and load balancing, Twemproxy Redis cluster to provide high availability and load balancing. Provide basic load-balancing services will guarantee high availability, we use the most Nginx as a reverse proxy server when we can guarantee high availability web services.

nginx + keepalived build highly available services there are many tutorials. You can try to build their own interest.

TCP 的keepalive

TCP keepalive main objective is the timely release of server resources.
After the connection is established via TCP protocol client and server, if the client has not sent data, or across a very long time before sending the data to determine how the other side is also connected to a long line when there is no data transmission, in the end is dropped, or indeed no data transmission connection is maintained or closed, or how long the connection should be shut down to release resources under what mechanism. The TCP keepalive is to solve this problem was introduced.
The three main TCP keepalive parameter to control

tcp_keepalive_time 7200
心跳周期
tcp_keepalive_intvl 75
侦测包发送间隔
tcp_keepalive_probes 9
侦测包重试次数

The process parameters and interpretation.
After the client establishes a connection with the server, if the two sides after tcp_keepalive_time (7200S), does not transmit any data, the server will tcp_keepalive_intvl (75S) every client sends a probe packet, determining a connection state of the client, presumably including client crashes , forced to close the application, host unreachable such an abnormal state. If, after detecting packet sent tcp_keepalive_probes (9) times still have not received a reply to the client (that is, ack packets), the server will think that this connection is not available, you can discard or closed.

Nginx 的keepalive

TCP layer has keepalive, Why Nginx application layer needed keepalive?
I understand that the availability using TCP keepalive guarantees transport layer connection, the default configuration is detection period of 2 hours. Nginx of keepalive connection is available to ensure the application layer. Ensure the availability of a transport layer on the fourth layer, an application layer protocol to ensure availability of an application layer in the seventh layer.
There is a book which mentioned:
Why can not replace the application layer TCP keepalive heartbeat? In addition to describing the application heartbeat was still alive (still in the process, smooth network), is more important it is that the application can work properly. The TCP keepalive by the operating system is responsible for exploration, even if the process deadlock or obstruction, the operating system will also send and receive TCP keepalive information as usual, the other party can not know the exceptions.

nginx keepalive TCP configuration with basically the same, but the name is not the same as nothing. Configuration as follows

so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt] 

so_keepalive = 30m :: 10 open tcp represents detected after 30 minutes no packet data transceiver sends the detection time interval using the system default, to detect packets transmitted 10 times.

HTTP的keepalive

The HTTP keepalive more common, is to become a long link short link. Each short connection request response, the client and server must create a new connection is disconnected immediately after the completion; keepalive when using long connection, client-to-server connection is established, the connection is not complete after the response, the next request direct taking the original connection, thus avoiding the overhead of repeated establish a connection and disconnection.

Then the client and server side is how to use the agreed long or short connection communication communications connection.
Main Connection head

客户端请求长连接头部:Connection: keep-alive
服务端同意使用长连接的响应头部:Connection: keep-alive
两者缺一不可,如果服务器端不支持长连接:Connection: Close
如果是HTTP/1.1默认使用长连接,无论头部是不是 Connection: keep-alive

Note the point:
Connection two sides only valid for the current connection, and do not pass Connection head backwards, only to identify their connection status.
If the agent is a multi-stage process is what?
Here Insert Picture Description
1 built even when a client and the proxy server with a Connection: keep-alive, but the proxy server 1 does not support long connection, replied Connection: Close, so the two are connected by a short
2 1 proxy server and the proxy server 2 build even when using the connection: Close short connection, the proxy server 2 replied connection: Close, so the two using a short connection
time 3 web proxy server 2 and even built the machine using the connection: keep-alive, web machine supports long connection, or reply to the connection: keep-alive, so long connection using both

HTTP is the developer of the keepalive longest encountered, so be extra careful. Not a server connection is required to use long long connection, both sides agree is the need to use long connection communication. Previously encountered Ali cloud SLB does not support long connection, WEB server or proxy server connection with SLB are short connection.

Guess you like

Origin www.cnblogs.com/feixiangmanon/p/11182494.html