lvs群集在企业网中的应用(2)
一,持久连接尽管我们选择了LVS的分发方法,但是大多时候我们要保证返回给客户端的所有响应请求必须来自于同一台Real Server,这里我们就要用到LVS Persistence(持久性)。例如,我们都会有这样的经历当客户在电子商务网站上挑选商品时,所挑选的购物车被定向到R1上,当第二件商品的时候被定向到R2上,这个时候由于R1和R2会话信息没有同步,还有就是当客户在进行付账的时候,80端口的http服务会跳转到443端口的https服务。如何保持这一会话的持久连接呢?
当使用SSL会话的时候,我们常常期望只交换一次密钥就可以建立永久连接,因此,LVS持久性在SSL会话中经常被用到。
LVS为了实现持久性,Directory会在内部维护一个连接追踪记录(源IP、RS IP,计时器),每一个请求进来的时候,被分给那一个RS,每一个请求会有一个条目,而且连接过去的时间都会有记录,并且有一定的时间的持久性。
二,实验案例
http://jinxiang1988.blog.运维网.com/attachment/201210/13/4999286_1350140653zWcY.png
https 同一服务器 及证书 配置详情见本人其他博客内容
配置 realserver1
# cd /var/www/html/
# cd /var/www/html
# vim index.html
http://jinxiang1988.blog.运维网.com/attachment/201210/13/4999286_1350140653GYik.png
配置realserver2
# cd /var/www/html/
# cd /var/www/html
# vim index.html
http://jinxiang1988.blog.运维网.com/attachment/201210/13/4999286_1350140654pC0E.png
director:
# ipvsadm -C
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
# iptables -t mangle -A PREROUTING -p tcp --dport 80 -d 192.168.145.101 -j MARK --set-mark 10 访问控制打标签
# iptables -t mangle -A PREROUTING -p tcp --dport 443 -d 192.168.145.101 -j MARK --set-mark 10
# ipvsadm -A -f 10 -s rr -p 1800 -p参数实现持久连接时间
# ipvsadm -a -f 10 -r 192.168.145.200
# ipvsadm -a -f 10 -r 192.168.145.201
测试图
http://jinxiang1988.blog.运维网.com/attachment/201210/13/4999286_1350140655zFbP.png
http://jinxiang1988.blog.运维网.com/attachment/201210/13/4999286_13501406560Kal.png
再开一台server2003作为另一台客户机
http://jinxiang1988.blog.运维网.com/attachment/201210/13/4999286_13501406569OhK.png
http://jinxiang1988.blog.运维网.com/attachment/201210/13/4999286_1350140657GGjk.png
页:
[1]