lvs-master 192.168.1.211
lvs-backup 192.168.1.212
vip     192.168.1.213
lnmp    192.168.1.117
lnmp2    192.168.1.118

lvs-master lvs-backup
--------------------------
mkdir /soft
cd /soft
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz
ln -s /usr/src/kernels/2.6.18-238.el5-i686/ /usr/src/linux/
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
cd ../
tar -zxvf keepalived-1.1.17.tar.gz
cd keepalived-1.1.17
./configure && make && make install
cd ../
cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived/
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
service keepalived start


vi /etc/keepalived/keepalived.conf
-----------------------------
global_defs {
notification_email {
amwytai@163.com
}
notification_email_from amwytai@163.com 

smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER -- backup
interface eth0
virtual_router_id 51
priority 100 -- 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.213
}
}
virtual_server 192.168.1.213 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 1192.168.1.117 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.118 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}

vi /root/lvs_real.sh
--------------------------------------
#!/bin/bash

SNS_VIP=192.168.1.213
/etc/rc.d/init.d/functions
case "$1" in
start)
       /sbin/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)
       /sbin/ifconfig lo:0 down
       /sbin/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 1
esac
exit 0
----------------------------------
chmod +x /roo/lvs_real.sh
/root/lvs_real.sh start
echo “/root/lvs_real.sh start” >> /etc/rc.local