安裝具體解釋:http://blog.csdn.net/CleverCode/article/details/50586957。html
lvs有三種模式dr,nat,tun。這裏先介紹dr模式。nginx
#!/bin/sh # lvs-dr.sh # # lvs的dr模式LVS server腳本 # # # vip和rip必須在同一個網段。VS/DR經過改寫請求報文的MAC地址。將請求的包發送到realserver上。 # 不改變包的源和目標的IP地址。而後realserver直接回復client。再也不通過LVS調度器,這樣大大的減輕了LVS的負擔。web
# set the vip and port VIP=192.168.142.211 VPORT1=80 # set the rip and port # web RIP1=192.168.142.130 RIP2=192.168.142.131 # port RPORT1=80 Usage (){ echo "Usage:`basename $0` (start|stop|status) " exit 1 } if [ $# -ne 1 ];then Usage fi case $1 in start) echo "start LVS of DirectorServer" echo 1 > /proc/sys/net/ipv4/ip_forward # set the vip /sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev eth0:1 # clear ipvs table /sbin/ipvsadm -C # add lvs vip and port /sbin/ipvsadm -A -t $VIP:$VPORT1 -s rr # add rip and port /sbin/ipvsadm -a -t $VIP:$VPORT1 -r $RIP1:$RPORT1 -g -w 1 /sbin/ipvsadm -a -t $VIP:$VPORT1 -r $RIP2:$RPORT1 -g -w 1 /sbin/ipvsadm -L -n ;; stop) echo "close LVS DirectorServer" /sbin/ipvsadm -C /sbin/ifconfig eth0:1 down ;; status) /sbin/ipvsadm -L -n ;; *) Usage esac dom
# cd /usr/local/lvspost
# vi realServer.sh
this
#!/bin/sh # realServer.sh # # lvs的dr模式RIP server腳本 # VIP=192.168.142.211 #vip's broadcast BROADCAST=192.168.142.255 Usage () { echo "Usage:`basename $0` (start|stop)" exit 1 } if [ $# -ne 1 ];then Usage fi case $1 in start) echo "reparing for Real Server" echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce echo "1" >/proc/sys/net/ipv4/conf/eth0/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/eth0/arp_announce /sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $BROADCAST up /sbin/route add -host $VIP dev lo:0 ;; stop) /sbin/ifconfig lo:0 down echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce echo "0" >/proc/sys/net/ipv4/conf/eth0/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/eth0/arp_announce echo "stop Real Server" ;; *) Usage esac
5)刷新頁面將會看到不一樣的內同。spa