一、调度控制器启动脚本(DR模式)

vi /etc/init.d/lvsdsdr

#!/bin/bash

#descriptions:start LVS of Diectorserver DR

VIP=172.16.23.172

RIP1=172.16.23.173

RIP2=172.16.23.175

. /etc/rc.d/init.d/functions

case "$1" in

start)

echo "start LVS of DirectorServer DR"

/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up

/sbin/route add -host $VIP dev eth0:0

echo "1" >/proc/sys/net/ipv4/ip_forward

/sbin/ipvsadm -C

/sbin/ipvsadm -A -t $VIP:80 -s rr

/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g

/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g

/sbin/ipvsadm

;;

stop)

echo "stop LVS of DirectorServer DR"

echo "0" >/proc/sys/net/ipv4/ip_forward

/sbin/ipvsadm -C

/sbin/ifconfig eth0:0 down

;;

*)

echo "Usage:$0 {start|stop}"

ext 1

esac

脚本可执行模式

chmod +x /etc/init.d/lvsdsdr

启动脚本(以服务方式启动)

service lvsdsdr start

image

二、realserver真实节点服务器配置

vi /etc/init.d/lvsrsdr

#!/bin/bash

#description : start realserver DR

VIP=172.16.23.172

. /etc/rc.d/init.d/functions

case "$1" in

start)

echo "start LVS of RealServer DR"

/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

/sbin/route add -host $VIP 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

;;

Stop)

/sbin/ifconfig lo:0 down

echo "close LVS of RealServer DR"

echo "0" >proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore

echo "0">/proc/sys/net/ipv4/conf/all/arp_announce

;;

*)

echo "Usage:$0 {start|stop}"

exit 1

esac

脚本可执行模式

chmod +x /etc/init.d/lvsrsdr

启动脚本(以服务方式启动)

service lvsrsdr start

image

Ifconfig

image

三、测试功能

访问http://172.16.23.172

查看调度服务器策略

ipvsadm

image

 

注意事项:

1、VIP和真实应用服务器在同一网段。

2、负载调度器和真实应用服务器使用该VIP地址。

3、VIP绑定在调度器接口 eth0:0。

4、VIP绑定在真实服务器回环接口上 lo:0。