Linux平台基于NAT模式的LVS搭建
一:NAT模式工作流程VS-NAT:Virtual Server via NAT 基于地址翻译的虚拟服务器
https://s1.运维网.com/oss/201711/10/b36c55cd463432955c35c771874bf339.png
https://s3.运维网.com/oss/201711/10/8a75196b35f97225496f5b2a6589011e.png
二:几个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.77RIP
RS2: 192.168.216.55RIP
注意:两台RS都已实现LNMP架构,搭建方法见博客地址:http://13172823.blog.运维网.com/13162823/1978924
③测试:
chrome浏览器
四:实验步骤
1.开启一个基于80端口的VS,调度算法为wrr(加权轮叫)
# yum install ipvsadm
# service nginx/httpd start
# ipvsadm -A -t 172.17.252.226:80 -s wrr
2.配置RS1,并设置为NAT模式,权重为1
# 2.配置RS2,并设置为NAT模式,权重为1
# 3.开启VS路由转发功能
# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
4.配置两个RS的默认路由都为DIP
# route add default gw 192.168.116.66
# route add default gw 192.168.116.66
5.Director上查看部署结果
# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP172.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访问连接
https://s3.运维网.com/oss/201711/10/4daba3e69fe7f925b29015f8a1343aef.png-wh_500x0-wm_3-wmp_4-s_4174106216.png
2.分别在RS1、RS2创建同名test.html文件,写入不同内容,测试wrr算法效果
https://s4.运维网.com/oss/201711/10/654bd9a3c6b34643d33e6eb26aebd2b0.png-wh_500x0-wm_3-wmp_4-s_798537616.png
六:常见错误
配置完成后访问http://VIP/index.php 失败,页面显示不出,可能是路由转发功能异常,解决方法如下:
RS1/2 设置默认路由后,要查看路由表,删除多余路由,确保最终结果如下
# 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
# 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
页:
[1]