首页 > 编程语言 > 详细

负载均衡LVS之DR模式WRR算法实现的详细步骤

时间:2019-05-28 11:21:27      阅读:415      评论:0      收藏:0      [点我收藏+]
负载均衡LVS之DR模式WRR算法实现的详细步骤

?

1、数据流程图

技术分享图片
?

2、环境说明

    1) 五台主机,时间同步,关闭防火墙和selinux
    2) 各主机角色
        1] 客户端:
            192.168.110.27 仅主机(vmnet1)  网关:192.168.110.34
        2] ROUTE服务器:
            192.168.110.34  仅主机(vmnet1) 网关:无
            192.168.136.34  仅主机(vmnet6) 网关:无
        3] RS服务器:
            192.168.136.36  仅主机(vmnet6) 网关:192.168.136.34
            192.168.136.37  仅主机(vmnet6) 网关:192.168.136.34
        4] VS服务器:
            192.168.136.35  仅主机(vmnet6) 网关:192.168.136.34 
    3) VIP地址:10.0.0.100
    4) 清空ipvsadm规则和相应的IP地址。

?

3、具体步骤

?

1) ROUTE服务器:

        1]开启路由功能
            echo 1 >/proc/sys/net/ipv4/ip_forward
        2]绑定与VIP相同网段的IP:10.0.0.200
            ifconfig eth1:1 10.0.0.200/24

?

2) VS服务器:

        运行:sh lvs_dr_vs.sh start
        脚本如下:
        #!/bin/bash
        #Author:fanfubin
        vip=‘10.0.0.100‘
        iface=‘lo:1‘
        mask=‘255.255.255.255‘
        port=‘80‘
        rs1=‘192.168.136.36‘
        rs2=‘192.168.136.37‘
        scheduler=‘wrr‘
        type=‘-g‘
        rpm -q ipvsadm &> /dev/null || yum -y install ipvsadm &> /dev/null

        case $1 in
        start)
            ifconfig $iface $vip netmask $mask #broadcast $vip up
            iptables -F

            ipvsadm -A -t ${vip}:${port} -s $scheduler
            ipvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1
            ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1
            echo "The VS Server is Ready!"
            ;;
        stop)
            ipvsadm -C
            ifconfig $iface down
            echo "The VS Server is Canceled!"
            ;;
        *)
            echo "Usage: $(basename $0) start|stop"
            exit 1
            ;;
        esac

?

3) RS服务器:

        运行:sh lvs_dr_rs.sh start            
        #!/bin/bash
        #Author:fanfubin
        vip=‘10.0.0.100‘
        mask=‘255.255.255.255‘
        dev=lo:1
        rpm -q httpd &> /dev/null || yum -y install httpd &>/dev/null
        service httpd start &> /dev/null && echo "The httpd Server is Ready!"
        echo "<h1>`hostname`</h1>" > /var/www/html/index.html

        case $1 in
        start)
            echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
            echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
            echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
            echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
            ifconfig $dev $vip netmask $mask #broadcast $vip up
            echo "The RS Server is Ready!"
            ;;
        stop)
            ifconfig $dev down
            echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
            echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
            echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
            echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
            echo "The RS Server is Canceled!"
            ;;
        *) 
            echo "Usage: $(basename $0) start|stop"
            exit 1
            ;;
        esac

?

4) 客户端测试:

        while true; do curl 10.0.0.100;sleep 1;done     

负载均衡LVS之DR模式WRR算法实现的详细步骤

原文:https://blog.51cto.com/13560168/2400840

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