集群――lvs实验篇

NAT模式实验:

CIP:192.168.100.101/24(vmnet5)

VIP:192.168.100.100/24(vmnet5)

DIP:172.16.100.1/16/eth0  (vmnet1)

RIP1:172.16.100.15/16/eth0(vmnet1)

RIP2:172.16.100.16/16/eth0(vmnet1)


RS上的操作:

    准备httpd服务,并且准备不同的页面。

    设定RS的网关指向DIP

Director上的操作:

    # vim /etc/sysctl.conf

        net.ipv4_forword = 1

    # sysctl -p

    # ipvsadm -A -t 192.168.100.100:80 -s rr

    # ipvsadm -a -t 192.168.100.100:80 -r 172.16.100.15 -m

    # ipvsadm -a -t 192.168.100.100:80 -r 172.16.100.16 -m

    # ipvsadm -Ln --stats

客户端的操作:

    # elinks http://192.168.100.100/index.html


DR模型:

(1)当VIP和DIP、RIP在同一个网段内时:(包括客户端均为VMNET1)

    Director:

        DIP:172.16.100.1/16/eth0 

        VIP:172.16.100.11/32/eth0:0

    RS1:

        RIP:172.16.100.15/16/eth0

        VIP:172.16.100.11/32/lo

    RS2:

        RIP:172.16.100.16/16/eth0

        VIP:172.16.100.11/32/lo

    CIP:172.16.100.101/16


RS1上的操作:

        # echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

        # echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

        # echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce 

        # echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce 

        # ifconfig lo:0 172.16.100.11 broadcast 172.16.100.11 netmask 255.255.255.255 up

        # route add -host 172.16.100.11 dev lo:0(使得数据报文无论从哪个网卡出去,IP地址都是VIP)

        RS2上的操作同上,而且准备不同的web页面。

Director上的操作:

    # ifconfig eth0:0 172.16.100.11 broadcast 172.16.100.11 netmask 255.255.255.255 up

    # ipvsadm -A -t 172.16.100.11:80 -s rr

    # ipvsadm -a -t 172.16.100.11:80 -r 172.16.100.15 -g

    # ipvsadm -a -t 172.16.100.11:80 -r 172.16.100.16 -g

客户端操作:

    # elinks http://172.16.100.11/index.html(此时Director上无法访问)

  

(2)当VIP和DIP、RIP不在同一个网段内时:(包括客户端均为VMNET1)

    Director:

        DIP:172.16.100.1/16/eth0

        VIP:192.168.100.11/32/eth0:0

    RS1:

        RIP:172.16.100.15/16/eth0

        VIP:192.168.100.11/32/lo

    RS2:

        RIP:172.16.100.16/16/eth0

        VIP:192.168.100.11/32/lo

    CIP:192.168.100.101/16


RS1上的操作:

        # echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

        # echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

        # echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce 

        # echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

        # ifconfig lo:0 192.168.100.11 broadcast 192.168.100.11 netmask 255.255.255.255 up

        # route add default gw 172.16.100.17

        # route add -host 192.168.100.11 dev lo:0

添加RS的网关设备:

        # ifconfig eth0 172.16.100.17

        # ifconfig eth0:0 192.168.100.17

        # vim /etc/sysctl.conf

            net.ipv4_forword = 1

        # sysctl -p

        #如果可能的话还可以给这个路由设备添加一个网关

        RS2相同的操作

Director上的操作:

        # ifconfig eth0:0 192.168.100.11

        # ipvsadm -A -t 192.168.100.11:80 -s wrr

        # ipvsadm -a -t 192.168.100.11:80 -r 172.16.100.15 -g

        # ipvsadm -a -t 192.168.100.11:80 -r 172.16.100.16 -g


LVS的持久连接:

    将http和https服务绑定为一个服务,使得客户端在这两个服务间切换时总是在一个服务器上。

    这里实用上面DR模型不在同一网段的网络环境:

RS上的操作:

    首先添加https服务:http://caduke.blog.51cto.com/3365689/1383604

    但是需要注意的是安装mod_ssl时会同时安装httpd服务,会覆盖掉编译安装的httpd在/etc/httpd中的配置文件。

    其他不需要变动

Director上的操作:

    # iptables -t mangle -A PREROUTING -d 192.168.100.11 -p tcp --d

port 80 -j MARK --set-mark 9

    # iptables -t mangle -A PREROUTING -d 192.168.100.11 -p tcp --dport 443 -j MARK --set-mark 9

    # ipvsadm -A -f 9 -s wrr -p 

    # ipvsadm -a -f 9 -r 172.16.100.15 -g -w 1

    # ipvsadm -a -f 9 -r 172.16.100.16 -g -w 2

    

    

        

        

        




            


 



  

    


    


    








你可能感兴趣的:(集群,LVS)