首页 > 其他 > 详细

LVS+Keepalived

时间:2016-09-06 23:17:12      阅读:186      评论:0      收藏:0      [点我收藏+]

使用keepalived的情况下,就不需要在dir上执行/usr/local/sbin/lvs_dr.sh脚本了,只需在rs上执行/usr/local/sbin/lvs_rs.sh,与ipvsadm无关了


为了防止其中一台rs宕机而造成无法访问的情况,就需要有一个程序去监测,当一台宕机后,立马就可以把请求调度到其余机器上去,那就是keepalived,相当于是负载均衡和高可用的集合体,非常优秀;keepalived --> HA+LB

需要有4台机器,在dir上做一主一备用于高可用,也就是说有两台负载均衡机器


在dir上:

首先清空ipvsadm规则:ipvsadm -C

在dir上安装keepalived:但是yum安装前需要关闭虚拟IP:ifconfig eth0:0 down, 因为有一个虚拟ip存在

yum install -y keepalived

修改keepalived配置文件:

vim /etc/keepalived/keepalived.conf

主上:

vrrp_instance VI_1 {

    state MASTER

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.237.100

    }

}


virtual_server 192.168.237.100 80 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    persistence_timeout 0

    protocol TCP


    real_server 192.168.237.133 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        connect_port 80

        }

    }


    real_server 192.168.237.137 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        connect_port 80

        }

    }

}


从上:

vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    virtual_router_id 51

    priority 99

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.237.100

    }

}


virtual_server 192.168.237.100 80 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    persistence_timeout 0

    protocol TCP


    real_server 192.168.237.133 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        connect_port 80

        }

    }


    real_server 192.168.237.137 80 {

        weight 100

        TCP_CHECK {

        connect_timeout 10

        nb_get_retry 3

        delay_before_retry 3

        connect_port 80

        }

    }

}



启动前的执行命令

dir上:

ipvsadm -C

iptables -t nat -F

echo 1 > /proc/sys/net/ipv4/ip_forward

/etc/init.d/keepalived start


rs上:

sh /usr/local/sbin/lvs_rs.sh


启动后在dir上用ip addr看dir上的IP


本文出自 “模仿游戏” 博客,请务必保留此出处http://kevinjin117.blog.51cto.com/11655131/1846991

LVS+Keepalived

原文:http://kevinjin117.blog.51cto.com/11655131/1846991

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!