一:NAT模式工做流程php
VS-NAT:Virtual Server via NAT 基于地址翻译的虚拟服务器html
二:几个IPnginx
CIP:client IP算法
VIP:virtual IPchrome
CIP经过路由器来访问VIP,因此VIP为桥接模式IPvim
DIP:Director IP浏览器
RIP:Real IP服务器
DIP与RIP为同一网段,因此都为仅主机模式IP架构
三:实验环境ide
①VS一台:
VIP: 172.17.252.226 DIP: 192.168.116.66
②RS两台:
RS1: 192.168.216.77 RIP
RS2: 192.168.216.55 RIP
③测试:
chrome浏览器
四:实验步骤
1.开启一个基于80端口的VS,调度算法为wrr(加权轮叫)
[root@vs ~]#yum install ipvsadm
[root@vs ~]#service nginx/httpd start
[root@vs ~]#ipvsadm -A -t 172.17.252.226:80 -s wrr
2.配置RS1,并设置为NAT模式,权重为1
[root@vs ~]#
2.配置RS2,并设置为NAT模式,权重为1
[root@vs ~]#
3.开启VS路由转发功能
[root@vs ~]#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
4.配置两个RS的默认路由都为DIP
[root@RS1 ~]#route add default gw 192.168.116.66
[root@RS2 ~]#route add default gw 192.168.116.66
5.Director上查看部署结果
[root@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.分别在RS一、RS2建立同名test.html文件,写入不一样内容,测试wrr算法效果
六:常见错误
配置完成后访问 http://VIP/index.php 失败,页面显示不出,多是路由转发功能异常,解决方法以下:
RS1/2 设置默认路由后,要查看路由表,删除多余路由,确保最终结果以下
[root@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
[root@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