RedHat下直接路由模式的负载均衡

首先:直接路由模式的负载均衡的工作原理:客户机访问director机,director机将客户端的请求发送到真实服务器,然后真实服务器将请求应回应的结果直接回应给客户机。这种方式减轻director机的压力,效率高,一般适用于大中型企业。

实验环境: 两台主机服务器:192.168.0.11   和  192.168.0.12
                     中转机: 192.168.0.13  和  192.168.0.19
                     客户机:192.168.0.10
            (主机名要跟IP保存一致。)

实验步骤:
A.服务器:
    1。192.168.0.11
        # yum install -y httpd
        # service httpd start
        # echo "192.168.0.11" >/var/www/html/index.html
        # route add default gw 192.168.0.13
        # vim /bin/shutarp
            -------------------------------
            #!/bin/bash
            VIP=192.168.0.19
            /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
            /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
            -------------------------------
        # shutarp
    2。192.168.0.12
        # yum install -y httpd
        # service httpd start
        # echo "192.168.0.12" >/var/www/html/index.html
        # route add default gw 192.168.0.13
        # vim /bin/shutarp
            -------------------------------
            #!/bin/bash
            VIP=192.168.0.19
            /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
            /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
            -------------------------------
        # shutarp
B.中转机:
    1。安装 ipvs服务:
        # yum clean all
        # yum install -y ipvsadm
    2。打开ip转发功能,关闭其他服务,设置中转
        # vim /etc/init.d/lvsDR
                ---------------------------------
                #/bin/bash
                VIP=192.168.0.19
                RIP1=192.168.0.11
                RIP2=192.168.0.12
                GW=192.168.0.254

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyddwd.html