linux 负载均衡(4层)
拓扑
++++++++++++
+ Client + eth0 192.168.1.1/24
++++++++++++
|
|
++++++++++++ up eth0:192.168.1.254/24
+ GW +
++++++++++++ down eth1:1.1.1.254/24
|
|
++++++++++++ VIP eth0:1.1.1.1/24
+ Director +
++++++++++++ DIP eth1:172.16.1.254/24
|
___________|____________
| |
| |
++++++++++++ ++++++++++++
+ Real Server A + + Real Server B +
++++++++++++ ++++++++++++
eth0:172.16.1.1/24 eth0:172.16.1.2/24
配置LVS VS/NAT模式
=================================
Client:
[root@localhost ~]# route add default gw 192.168.1.254 dev eth0
设置Client 的网关
GW:
[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
在网关服务器设置开启转发
Real Server A & Real Server B:
[root@localhost ~]# yum install httpd
在两台网站服务器装httpd
A /var/www/html/index.html A的网页zhangyunming1
A /var/www/html/index.html B的网页zhangyunming2
[root@localhost ~]# route add default gw 172.16.1.254 dev eth0
为eth0设置网关
Director:
[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@localhost ~]# route add default gw 1.1.1.254 dev eth0
[root@localhost ~]# yum install ipvsadm
用yum装ipvsadm包
[root@localhost ~]# ipvsadm -A -t 1.1.1.1:80 -s rr
[root@localhost ~]# ipvsadm -a -t 1.1.1.1:80 -r 172.16.1.1:80 -m
[root@localhost ~]# ipvsadm -a -t 1.1.1.1:80 -r 172.16.1.2:80 -m
[root@localhost ~]# ipvsadm -Ln
[root@localhost ~]# ipvsadm -Ln --stat
备注数据包走向
====================================
1.Client---------->GW
sip:CIP dip:VIP
smac:Client_mac dmac:GW_up_mac
2.GW-------------->Director
sip:CIP dip:VIP
smac:GW_down_mac dmac:VIP_mac
3.Director-------->Real Server (DNAT)
sip:CIP dip:RIP
smac:DIP_mac dmac:RealServer_mac
4.Real Server----->Director
sip:RIP dip:CIP
smac:RealServer_mac dmac:DIP_mac
5.Director-------->GW
sip:VIP dip:CIP
smac:VIP_mac dmac:GW_down_mac
6.GW-------------->Client
sip:VIP dip:CIP
smac:GW_up_mac dmac:Client_mac
本文出自 “cisco” 博客,请务必保留此出处http://1585654.blog.51cto.com/1575654/1381068
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。