1)Ipvsadm编译安装方法如下

wget  -c  
http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
yum install  kernel-devel -y
yum install libnl* popt* -y
ln -s /usr/src/kernels/3.10.*  /usr/src/linux
tar xzvf ipvsadm-1.26.tar.gz 
cd ipvsadm-1.26 
make 
make install

2)Keepalived 安装配置

cd  /usr/src
wget  -c  http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
tar  -xzvf  keepalived-1.1.15.tar.gz 
cd  keepalived-1.1.15 
./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/3.10.0-957.10.1.el7.x86_64 --enable-lvs-syncd --enable-lvs
make && make install
DIR=/usr/local/keepalived
cp  $DIR/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp  $DIR/etc/sysconfig/keepalived  /etc/sysconfig/
mkdir  -p  /etc/keepalived
cp  $DIR/sbin/keepalived /usr/sbin/

3) Master上keepalived.conf配置代码:

! Configuration File for keepalived
global_defs {
   notification_email {
      wgkgood@163.com
   }
   notification_email_from wgkgood@163.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
    state  MASTER
    interface  ens33
    lvs_sync_daemon_inteface ens33
    virtual_router_id 51
    priority 100
    advert_int 5
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.0.188
    }
}
virtual_server 192.168.0.188 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
persistence_timeout  60
    protocol TCP
    real_server 192.168.0.112 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.0.113 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}

4)Backup上keepalived.conf配置代码

! Configuration File for keepalived
global_defs {
   notification_email {
      wgkgood@163.com
   }
   notification_email_from wgkgood@163.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
    state  BACKUP
    interface  ens33
    lvs_sync_daemon_inteface ens33
    virtual_router_id 51
    priority 90
    advert_int 5
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.0.188
    }
}
virtual_server 192.168.0.188 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
persistence_timeout  60
    protocol TCP
    real_server 192.168.0.112 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.0.113 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}

5)LVS DR客户端配置VIP

#LVS Client Server
VIP=192.168.0.188
case $1 in
start)
        ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
        /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
        sysctl -p>/dev/null 2>&1
        echo "RealServer start OK"
        exit 0
;;
stop)
    ifconfig lo:0 down
    route del $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 OK"
    exit 1
;;
*)
    echo "Usage: $0 {start|stop}"
;;
esac