客户在外网访问内网VIP上的web服务,Director将客户请求转发至后端RealServer从而实现负载均衡。
配置如下:
路由器 外网ip 10.10.10.1
内网网关 192.168.0.1
Director DIP 192.168.0.11
VIP 192.168.0.10
网关 192.168.0.1
RealServer1 RIP 192.168.0.12
VIP 192.168.0.10
网关 192.168.0.1
RealServer2 RIP 192.168.0.13
VIP 192.168.0.10
网关 192.168.0.1
使用一台带有双网卡的linux主机作为路由器,起用ip转发功能。
路由器:
eth0:IP 192.168.0.1
eth1: IP10.10.10.1
echo 1 > /proc/sys/net/ipv4/ip_forward 打开ip转发
Director配置
echo 1 > /proc/sys/net/ipv4/ip_forward打开ip转发功能,否则数据包到了Director后将无法转发出去。
ifconfig eth0 192.168.0.11 netmask 255.255.255.0
ifconfig eth0:1 192.168.0.10 netmask 255.255.255.255
route add default gw 192.168.0.1
route add –host 192.168.0.10 dev eth0:1 为VIP指定一条静态路由
ipvsadm -A -t 192.168.0.10 -s rr -
ipvsadm -a -t 192.168.0.10:80 -r 192.168.0.12:80 -g
ipvsadm -a -t192.168.0.10 -r 192.168.0.10 -g
RealSever1配置
ifconfig eth0 192.168.0.12 netmask 255.255.255.0
ifconfig lo:0 192.168.0.10 netmask 255.255.255.255
route add –host 192.168.0.10 dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
RealSever2配置
ifconfig eth0 192.168.0.13 netmask 255.255.255.0
ifconfig lo:0 192.168.0.10 netmask 255.255.255.255
route add –host 192.168.0.10 dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
客户机访问结果如下:
刷新后便可以实现简单的负载均衡
转载于:https://blog.51cto.com/lulucao2006/1538771