LVS集群调度之持久连接问题
问题:
对于后台多个RS调度,可能页面刷新一次,又需要重新调度,session无法绑定。
解决方案
lvs sh算法(源地址哈希),基本不适用,因为很多客户端可能都是通过nat上网,使用同一个公网ip,使用sh调度算法,会导致流量分配不均衡
使用LVS persistence:实现无论使用任何调度算法,在默认时间内(360s),能够实现将来自同一个地址的请求始终发往同一个RS。
[root@lvs ~]# man ipvsadm
-p, --persistent [timeout]
Specify that a virtual service is persistent. If this option is specified, multiple requests from a client are redirected to the same real server selected for the first request. Optionally, the timeout of persistent sessions may be specified given in seconds, otherwise the default of 300 seconds will be
used. This option may be used in conjunction with protocols such as SSL or FTP where it is important that clients consistently connect with the same real server.
Note: If a virtual service is to handle FTP connections then persistence must be set for the virtual service if Direct Routing or Tunnelling is used as the forwarding mechanism. If Masquerading is used in conjunction with an FTP service than persistence is not necessary, but the ip_vs_ftp kernel module
must be used. This module may be manually inserted into the kernel using insmod(8).
ipvsadm -A|E -t|-u|-f service-address [-s scheduler] [-p (360)]