LVS-DR

1、实验环境


    1)

        硬件:lenovo-T410S

        软件:VMWARE-Workstation-10

    2)

        虚拟出四台虚拟机

            OS:centos6.6

            网卡:NAT


2、实验拓扑

    DR(director server 前端调度服务器,负责转发客户端的请求报文)

    RS(real server 后端真实服务器,负责处理客户端的请求报文)

    VIP(虚拟IP,负责接收用户请求报文)

    DIP(director的IP,负责和后端RS通信)

    RIP(后端服务器的IP)   

 

    DR

        VIP

            eth0:0  192.168.133.124

        DIP

            eth0    192.168.133.128


    RS

        RIP

            eth0    192.168.133.129

            eth0    192.168.133.130

            eth0    192.168.133.132

        VIP

            lo:0    192.168.133.124


LVS-DR_第1张图片



3、开始实验

  

    1)配置NTP服务器

            [root@nn network-scripts]# vim /etc/ntp.conf

                1、restrict设置你所允许的到NTP服务器同步时间的主机或者网段

                格式:restrict 10.0.0.0 mask 255.255.255.0 nomodify

                2、server配置为远端公网上的NTP服务器的域名

                server s1a.time.edu.cn


        同步NTP服务器(必须在NTP服务器关闭的情况下)

            [root@nn network-scripts]# ntpdate s1a.time.edu.cn


        启动NTP服务器

            [root@nn network-scripts]# server ntpd start


        本地服务器到NTR服务器上同步时间


            ntpdate 10.0.0.1(过10分钟以后再在NTP服务器上进行时间同步)


    2)安装ipvsadm工具


        用来添加ipvsadm规则


        [root@nn network-scripts]# yum -y install ipvsadm


    3)关闭防火墙和SELINUX


        [root@nn network-scripts]# service iptables stop

        [root@nn network-scripts]# setenforce 0

        [root@nn network-scripts]# getenforce


    4)安装httpd


        [root@nn network-scripts]# yum -y install httpd

        [root@nn network-scripts]# service httpd start 



     5)配置IP

        VMWARE WORKSTATION 虚拟出四台主机,网卡都是NAT模式

            DR

                VIP

                    eth0:0  192.168.133.124

                DIP

                    eth0    192.168.133.128


            RS

                RIP

                    eth0    192.168.133.129

                    eth0    192.168.133.130

                    eth0    192.168.133.132

                VIP

                    lo:0    192.168.133.124


    

    6) 添加IPVSADM规则


    DR:配置


        1、确保路由转发开启


            [root@nn network-scripts]# cat /proc/sys/net/ipv4/ip_forward

            1


        2、添加ipvsadm规则

            [root@nn network-scripts]# ipvsadm -A -t 192.168.133.124:80 -s wlc

            [root@nn network-scripts]# ipvsadm -a -t 192.168.133.124:80 -r 192.168.133.129             -g -w 1

            [root@nn network-scripts]# ipvsadm -a -t 192.168.133.124:80 -r 192.168.133.130             -g -w 2

            [root@nn network-scripts]# ipvsadm -a -t 192.168.133.124:80 -r 192.168.133.132             -g -w 3


        3、添加VIP


            [root@nn network-scripts]# ifconfig eth0:0 192.168.133.124 broadcast                     192.168.133.124 netmask 255.255.255.255 up


        4、添加路由


            [root@nn network-scripts]# route add -host 192.168.133.124 dev eth0:0


    RS:配置


        1)在lo接口上配置VIP

            [root@dn1 ~]# ifconfig lo:0 192.168.133.124 netmask 255.255.255.255 broadcast             192.168.133.124 up


        2)开启内核参数

            [root@dn3 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

            [root@dn3 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

            [root@dn3 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

            [root@dn3 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce


        3)添加VIP


            [root@nn network-scripts]# ifconfig lo:0 192.168.133.124 netmask                         255.255.255.255 up


        4)添加路由(保证响应报文从lo:0的VIP接口发出)


            [root@nn network-scripts]# route add -host 192.168.133.124 dev lo:0


4、测试

    http://192.168.133.124

    ipvsadm -L -n