• LVS-DR集群搭建


    安装LVS

    下载源码包,安装时需要根据自己的内核,下载 ipvsadm-1.26.tar.gz的源码包,在进行编译安装以后,我们需要检查必需包是否安装:

    1.对内核文件做链接

    # uname -r
    2.6.32-504.el6.x86_64
    # ll /usr/src/linux 
    lrwxrwxrwx 1 root root 38 9月  18 18:17 /usr/src/linux -> /usr/src/kernels/2.6.32-504.el6.x86_64
    

    2.启动内核支持Lvs

    modprobe ip_vs 
    # lsmod |grep ip_vs
    ip_vs_wrr               2179  1
    ip_vs                 125694  3 ip_vs_wrr
    libcrc32c               1246  1 ip_vs
    ipv6                  334932  292 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
    

    3.安装一些必须软件

    openssl,openssl-devel,popt,上述软件包都可以使用yum安装。

    配置DR,将下列脚本cp到服务器上的一个文件下
    DR配置启动脚本

    #!/bin/bash 
    # description: start LVS of DirectorServer
    #Written by :NetSeek
    GW=192.168.1.1
    
    # website director vip.
    WEB_VIP=192.168.1.111
    WEB_RIP1=192.168.1.201
    WEB_RIP2=192.168.1.33
    . /etc/rc.d/init.d/functions
    
    logger $0 called with $1
    
    case "$1" in
    
    start)
            /sbin/ipvsadm --set 30 5 60
            /sbin/ifconfig eth0:0 $WEB_VIP broadcast $WEB_VIP netmask 255.255.255.255 up
            /sbin/route add -host $WEB_VIP dev eth0:0
            /sbin/ipvsadm -A -t $WEB_VIP:80 -s wrr -p 3
            /sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP1:80 -g -w 1
            /sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP2:80 -g -w 1
            touch /var/lock/subsys/ipvsadm >/dev/null 2>&1
    
            # set Arp
            /sbin/arping -I eth0 -c 5 -s $WEB_VIP $GW >/dev/null 2>&1
           ;;
    stop)
            /sbin/ipvsadm -C
            /sbin/ipvsadm -Z
            ifconfig eth0:0 down
            route del $WEB_VIP  >/dev/null 2>&1
            rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
            /sbin/arping -I eth0 -c 5 -s $WEB_VIP $GW
            echo "ipvsadm stoped"
           ;;
    status)
    
            if [ ! -e /var/lock/subsys/ipvsadm ];then
                    echo "ipvsadm is stoped"
                    exit 1
            else
                    ipvsadm -ln
                    echo "..........ipvsadm is OK."
            fi
          ;;
    
    *)
            echo "Usage: $0 {start|stop|status}"
            exit 1
    esac
    exit 0
    

    配置Realserver脚本:

    !/bin/bash
    # Written by NetSeek
    # description: Config realserver lo and apply noarp
    WEB_VIP=192.168.1.111
    . /etc/rc.d/init.d/functions
    case "$1" in
    start)
           ifconfig lo:0 $WEB_VIP netmask 255.255.255.255 broadcast $WEB_VIP
           /sbin/route add -host $WEB_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 >/dev/null 2>&1
           echo "RealServer Start OK"
           ;;
    stop)
           ifconfig lo:0 down
           route del $WEB_VIP >/dev/null 2>&1
           echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
           echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
           echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
           echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
           echo "RealServer Stoped"
           ;;
    status)
            # Status of LVS-DR real server.
            islothere=`/sbin/ifconfig lo:0 | grep $WEB_VIP`
            isrothere=`netstat -rn | grep "lo:0" | grep $web_VIP`
            if [ ! "$islothere" -o ! "isrothere" ];then
                # Either the route or the lo:0 device
                # not found.
                echo "LVS-DR real server Stopped."
            else
                echo "LVS-DR Running."
            fi
    ;;
    *)
            # Invalid entry.
            echo "$0: Usage: $0 {start|status|stop}"
            exit 1
    ;;
    esac
    exit 0
    

    在Realserver主机上,记得开启ip转发的功能

    net.ipv4.ip_forward = 1
    

    分别启动上面的脚本

    # watch ipvsadm -ln
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  192.168.1.111:80 wrr persistent 3
      -> 192.168.1.33:80              Route   1      0          0        
      -> 192.168.1.201:80            Route   1      0          0 
    

    看到路由了,基本上也就成功了!

  • 相关阅读:
    L2私有专用网 L3私有专用网 互通
    VPLS知识点
    Lab L2tpv3
    L2TP version 3(Layer 2 Tunnel Protocol)
    L2私有专用网 Interworking [IW] 的两种类型
    L2私有专用网 伪线缝补
    Option 2:End-to-End PW between Provider Edge Routers
    Option 1:专用电路互联伪线的 Inter-AS 实现
    ATOM实验
    100、拥塞控制原理听说过吗?101、如何区分流量控制和拥塞控制?
  • 原文地址:https://www.cnblogs.com/GXLo/p/7512562.html
Copyright © 2020-2023  润新知