首先准备三台Linux服务器,一台做主(Director),两台副(RealServer)

在D上配置网络ech0和ech0:0,其中,ech0:0作为vip(用户访问使用),两个R为ech0,三个ech0均为公网IP

例子:director(eth0192.168.31.166, vip eth0:0: 192.168.31.110)
real server1(eth0 rip: 192.168. 31.100, vip lo:0: 192.168.31.110)
real server2(eth0 rip: 192.168.31.101, vip lo:0: 192.168.31.110)
Director 上 vim /usr/local/sbin/lvs_dr.sh //增加

#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/sbin/ipvsadm
vip=192.168.31.110
rs1=192.168.31.100
rs2=192.168.31.101

ifconfig ech0:0 down
ifconfig eth0:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev eth0:0
$ipv -C
$ipv -A -t $vip:80 -s rr 
$ipv -a -t $vip:80 -r $rs1:80 -g -w 1
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1


两台rs上:vim /usr/local/sbin/lvs_dr_rs.sh
#! /bin/bash
vip=192.168.31.110
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up 
route add -host $vip 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


然后director上执行: bash /usr/local/sbin/lvs_dr.sh
两台rs上执行: bash /usr/local/sbin/lvs_dr_rs.sh


浏览器访问VIP(查看结果可在nginx目录中index.html定义,可能存在缓存,有时没法查看区别),也可使用第四台虚拟机用curl  VIP测试(切记)