安装使用lvs
yum -y install gcc gcc-c++ kernel-devel libnl* popt* mkdir /usr/local/src/lvs cd /usr/local/src/lvs wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz ln -s /usr/src/kernels/2.6.32-358.11.1.el6.i686/ /usr/src/linux tar zxvf ipvsadm-1.26.tar.gz cd ipvsadm-1.26 make make install
lvs启动脚本 lvs.sh
#! /bin/bash SNS_VIP=192.168.1.11 SNS_RIP1=192.168.1.109 SNS_RIP2=192.168.1.110 . /etc/rc.d/init.d/functions logger $0 called with $1 case "$1" in start) /sbin/ipvsadm --set 30 5 60 /sbin/ifconfig eth0:0 $SNS_VIP broadcast $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP up /sbin/route add -host $SNS_VIP dev eth0:0 /sbin/ipvsadm -A -t $SNS_VIP:80 -s wlc -p 120 /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP1:80 -g -w 1 /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP2:80 -g -w 1 touch /var/lock/subsys/ipvsadm > /dev/null 2>&1 ;; stop) /sbin/ipvsadm -C /sbin/ipvsadm -Z ifconfig eth0:0 down route del $SNS_VIP rm -rf /var/lock/subsys/ipvsadm > /dev/null 2>&1 echo "ipvsadm stoped" ;; status) if [ ! -e /var/lock/subsys/ipvsadm ];then echo "ipvsadm stoped" exit 1 else echo "ipvsadm OK" fi ;; *) echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0
后端配置脚本real.sh
#!/bin/bash SNS_VIP=192.168.1.11 . /etc/init.d/functions case "$1" in start) ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP /sbin/route add -host $SNS_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 sysctl -p > /dev/null 2>&1 echo "RealServer Start OK" ;; stop) ifconfig lo:0 down route del $SNS_VIP > /dev/null 2>&1 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 "RealServer Stoped" ;; *) echo "Usage: $0 {start|stop}" exit 0 esac exit 0