一:NAT模式工作流程
VS-NAT:Virtual Server via NAT 基于地址翻译的虚拟服务器
二:几个IP
CIP:client IP
VIP:virtual IP
CIP通过路由器来访问VIP,所以VIP为桥接模式IP
DIP:Director IP
RIP:Real IP
DIP与RIP为同一网段,所以都为仅主机模式IP
三:实验环境
①VS一台:
VIP: 172.17.252.226 DIP: 192.168.116.66
②RS两台:
RS1: 192.168.216.77 RIP
RS2: 192.168.216.55 RIP
注意:两台RS都已实现LNMP架构,搭建方法见博客地址:http://13172823.blog.51cto.com/13162823/1978924
③测试:
chrome浏览器
四:实验步骤
1.开启一个基于80端口的VS,调度算法为wrr(加权轮叫)
[iyunv@vs ~]# yum install ipvsadm [iyunv@vs ~]# service nginx/httpd start [iyunv@vs ~]# ipvsadm -A -t 172.17.252.226:80 -s wrr 2.配置RS1,并设置为NAT模式,权重为1
2.配置RS2,并设置为NAT模式,权重为1
3.开启VS路由转发功能
[iyunv@vs ~]# vim /etc/sysctl.conf net.ipv4.ip_forward = 1 4.配置两个RS的默认路由都为DIP
[iyunv@RS1 ~]# route add default gw 192.168.116.66
[iyunv@RS2 ~]# route add default gw 192.168.116.66
5.Director上查看部署结果
[iyunv@vs ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.17.252.226:80 wrr -> 192.168.116.55:80 Masq 1 0 0 -> 192.168.116.77:80 Masq 1 0 0 五:测试环节
1.浏览器重复访问 http://VIP/index.php ,并观察ActiveConn访问连接
2.分别在RS1、RS2创建同名test.html文件,写入不同内容,测试wrr算法效果
六:常见错误
配置完成后访问 http://VIP/index.php 失败,页面显示不出,可能是路由转发功能异常,解决方法如下:
RS1/2 设置默认路由后,要查看路由表,删除多余路由,确保最终结果如下
[iyunv@RS1 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.116.66 0.0.0.0 UG 0 0 0 eth1 192.168.116.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1 [iyunv@RS2 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.116.66 0.0.0.0 UG 0 0 0 eth1 192.168.116.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
|