Solutions for LVS Server Load balancer tcp persistent connection Distribution
Although the application keepalived solves the backend server Load balancer and high availability problems, you must pay attention to many problems in specific applications. Many applications use tcp or http persistent connections. Because the overhead of establishing a tcp connection or http connection is large, the application needs to communicate frequently with the server, at this time, it is undoubtedly very appropriate to maintain a persistent connection. After exploring the lvs & keepalived persistent connection configuration, the configuration is mainly in three places:
1. The SoTimeout of the client is set by the setSoTimeout method of java.net. Socket in java. setSoTimeout (0) indicates that the timeout time is infinite. This value sets timeout for read blocking.
Ii. lvs settings:
Check whether it is ipvsadm -- list -- timeout. For example, my machine will return the following results:
# Ipvsadm -- list -- timeout
Timeout (tcp tcpfin udp): 7200 5 60
This indicates that the timeout time of my tcp session is 7200 seconds.
Set timeout:
Ipvsadm -- set 7200 5 60
If this value is too small, your client will receive an error message such as connection reset by peer.
Iii. keepalived Configuration:
It is the persistence_timeout of virtual_server, which means that the route from the same user (determined by ip address) to the same real
Server. You must do this for persistent connection applications. The Configuration value is best consistent with the timeout configured by lvs.
4. Example:
Virtual_server 172.19.1.19 5222 {
Delay_loop 2
Lb_algo wrr
Lb_kind DR
Persistence_timeout 7200
Protocol TCP
Real_server 172.19.1.8 5222 {
Weight 1
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 172.19.1.9 5222 {
Weight 1
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
}
}
}