测试环境:
web1 : 192.168.12.160
web2 : 192.168.12.161
lvs或lvs+keepalived : 192.168.12.191
1,在没有使用keepalived情况下在脚本中加入-p 参数,默认时间300秒(/sbin/ipvsadm -A -t $VIP:8080 -s wrr -p 300)
2,在keepalived使用情况下,在配置文件虚拟服务下加入persistence_timeout 300 参数
3,测试访问页面 : http://192.168.12.100:8080/index2.jsp
 
测试过程: 1,没有加入参数情况下设置轮询机制,不停刷新和转变页面情况下,lvs会将访问转到不停的地方
2,加了参数后,不停刷新和转变页面情况下,会话会在一定时间内保持在一台机器上。
 
lvs操作流程
1.存在就根据该连接发包
2.不存在,是新连接,则开始调度

如果vs是普通服务器,则执行调度算法选择一个rs,然后创建连接,然后发送
如果vs是p服务器,则先看看是否有模板可用,如果有,则根据该模板创建连接,然后发包
如果没有模板可用,就执行调度器调度一个rs并创建模板,然后根据该模板创建连接,最后发包
 
以上是我从网上找的,我理解p服务器就是加了-P参数的设置机器,模板可以用ipvsdam -lcn来查看。在ipvsadm -L 查看连接已经断开的情况下,其实还有这个连接的模板,这样LVS在加了-p参数后时间失效情况下,还会按照模板来分配到以前访问那个地址,当模板失效不存在后,才会按照算法从新分配连接的机器。ipvsadm模板保持时间默认为15分钟,
 
 
---------------------------------------------------------------------------------------------------------------------------------------------------------------
ipvsdam会话保持参数man:
-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).