负载均衡LVS之DR模式IP包调度过程及WRR算法实现的详细步骤

负载均衡LVS之DR模式IP包调度过程及WRR算法实现的详细步骤

 

1、DR模式IP包调度过程


 

2、数据流程图


 

3、环境说明

    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地址。

 

4、具体步骤

 

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 "

`hostname`

" > /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     

转载于:https://blog.51cto.com/13560168/2400840

你可能感兴趣的:(负载均衡LVS之DR模式IP包调度过程及WRR算法实现的详细步骤)