1.2. DR模型:
如下图所,外网用户直接访问Director上的VIP地址,Director将请求分派给real server 进行处理,当realserver处理后不再经过Director,而是直接送至客户端,绕开了Director,使Director不再成为瓶颈。可以有大量的节点,最多可以有100个节点
1.3. LVS调度算法:
当Director收到请求后,需要将请求发送给Real server 进行处理,但是发送哪一台服务器就要按照算法进行分派。
共有十总调度算法:
DIP=10.109.134.201
RIP1=10.109.134.202
RIP2=10.109.134.203
PORT=80
RSWEIGHT1=2
RSWEIGHT2=5
#
case "$1" in
start)
/sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/routeadd -host $VIP dev eth0:0
# Since this is the Director we must be able toforward packets
echo 1 >/proc/sys/net/ipv4/ip_forward
# Clear all iptables rules.
/sbin/iptables -F
# Reset iptables counters.
/sbin/iptables -Z
# Clear all ipvsadm rules/services.
/sbin/ipvsadm-C
# Add an IP virtual service for VIP 192.168.0.219port 80
# In this recipe, we will use the round-robinscheduling method.
# In production, however, you should use a weighted,dynamic scheduling method.
/sbin/ipvsadm-A -t $VIP:80 -s wlc
# Now direct packets for this VIP to
# the real server IP (RIP) inside the cluster
/sbin/ipvsadm-a -t $VIP:80 -r $RIP1 -g -w $RSWEIGHT1
/sbin/ipvsadm-a -t $VIP:80 -r $RIP2 -g -w $RSWEIGHT2
/bin/touch/var/lock/subsys/ipvsadm &> /dev/null
;;
stop)
# Stop forwarding packets
echo 0 >/proc/sys/net/ipv4/ip_forward
# Reset ipvsadm
/sbin/ipvsadm-C
# Bring down the VIP interface
/sbin/ifconfig eth0:0 down
/sbin/routedel $VIP
/bin/rm -f/var/lock/subsys/ipvsadm
echo"ipvs is stopped..."
;;
status)
if [ ! -e/var/lock/subsys/ipvsadm ]; then
echo"ipvsadm is stopped ..."
else
echo"ipvs is running ..."
ipvsadm -L-n
fi
;;
*)
echo"Usage: $0 {start|stop|status}"
;;
esac
3.2.RealServer的配置脚本:
#!/bin/bash
# lvsDR_rs_Change.sh
# Script to start LVS DR real server.
# chkconfig: - 90 10
# description: LVS DR real server
#
. /etc/rc.d/init.d/functions
VIP=10.109.134.210
host=`/bin/hostname`
case "$1" in
start)
# Start LVS-DR real server on this machine.
/sbin/ifconfig lo down
/sbin/ifconfig lo up
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
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
;;
stop)
# StopLVS-DR real server loopback device(s).
/sbin/ifconfig lo:0 down
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
;;
status)
#Status of LVS-DR real server.
islothere=`/sbin/ifconfig lo:0 | grep $VIP`
isrothere=`netstat -rn | grep "lo:0" | grep $VIP`
if [ !"$islothere" -o ! "isrothere" ];then
# Either the route or the lo:0 device
#not found.
echo "LVS-DR real server Stopped."
else
echo "LVS-DR real server Running."
fi
;;
}; do
if ipvsadm -L -n |grep "$I:$RPORT" && > /dev/null; then
RSTATUS[$COUNT]=1
else
RSTATUS[$COUNT]=0
fi
if curl --connect-timeout 1 http://$I &>/dev/null; then
if [ ${RSTATUS[$COUNT]} -eq 0 ]; then
add $I ${RW[$COUNT]}
[ $? -eq 0 ] && RSTATUS[$COUNT]=1
fi
else
if [ ${RSTATUS[$COUNT]} -eq 1 ]; then
del $I
[ $? -eq 0 ] && RSTATUS[$COUNT]=0
fi
fi
let COUNT++
done