作用我就不多解释,大家百度查,直接切入正题!

环境:
Centos 5.4

LVS-master: 172.16.17.134
LVS-backup: 172.16.17.135
VIP: 172.16.17.133
web1: 172.16.17.136
web2: 172.16.17.137
 

在LVS-master和LVS-backup上进行如下:
安装ipvsadm:
先要做一个连接文件: ln -s /usr/src/kernels/2.6.18-308.8.1.el5-i686/ /usr/src/linux/
注意:如果ll /usr/src/kernels/ 目录下没东西,则 yum -y install kernel-devel解决

wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
tar -zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24 
make
make install

安装keepalived:
wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
tar -zxvf keepalived-1.1.15.tar.gz
cd keepalived-1.1.15
./configure --prefix=/usr/local/keepalived
make
make install
 

设置开机启动,添加到服务
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/                   
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keeplived /etc/init.d/

mkdir /etc/keepalived
vim /etc/keepalived/keepalived.conf         --------------配置文件内容可复制已建好文档
vim /usr/local/keepalived/etc/keepalived/keepalived.conf   ---------这个是最初配置文件


后端服务器配置realserver(所有后端都同样配置):
vim lvs-realserver.sh            ------------内容可复制建好文档
chmod 755 lvs-realserver.sh



开启服务:
在LVS-master和LVS-backup上执行: service keepalived start
在web1和web2上执行 /root/lvs-realserver.sh start

停掉master上的keepalived,vip就已经绑定到backup上了
停掉任何一台web都能正常访问