lvs+keepalived

安装lvs+keepalived

a.       下载源码包  

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

wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz  

b.       建立软链接  

ln -s /usr/src/kernels/2.6.* /usr/src/linux  

c.       安装ipvsadm  

tar xzvf ipvsadm-1.24.tar.gz  

make 

make install  

或者 yum -y install ipvsadm(简单)

 

d.       安装keepalived

tar -xzvf keepalived-1.2.7.tar.gz

./configure

make

make install  

e.       配置keepalived  

cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/   

cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/   

mkdir -p /etc/keepalived   

cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/  

cp /usr/local/sbin/keepalived /usr/sbin/  

 

vi /etc/keepalived/keepalived.conf

 

! Configuration File for keepalived

 

global_defs {

   router_id LVS_MASTER

}

 

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.41.173  #VIP

    }

}

 

virtual_server 192.168.41.173 80 {

    delay_loop 6

    lb_algo rr

    lb_kind NAT

#   persistence_timeout 5

    protocol TCP

 

    real_server 192.168.41.183 80 {

        weight 3

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

    }

   

    real_server 192.168.41.186 80 {

        weight 3

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

    }

}

f.        开启路由转发

[root@CentOS-LVS_MASTER ~]# vi /etc/sysctl.conf 
net.ipv4.ip_forward = 1
[root@CentOS-LVS_MASTER ~]# sysctl –p

 

g.       创建 realserver.sh

cd /etc/init.d/

vi realserver.sh

 

#add for chkconfig

#chkconfig: 2345 70 30

#description: RealServer's script

#processname: realserver.sh      

#!/bin/bash

VIP=192.168.41.173

source /etc/rc.d/init.d/functions

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

       echo "RealServer Start OK"

       ;;

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"

       ;;

       *)

       echo "Usage: $0 {start|stop}"

       exit 1

esac

exit 0

 

7、启动keepalived

/etc/init.d/keepalived start

执行 realserver.sh

./ realserver.sh

 

查看vip落点情况

cd /etc/keepalived/

ipvsadm –ln

 


你可能感兴趣的:(lvs+keepalived)