zoukankan      html  css  js  c++  java
  • 快速搭建lvs + keepalived + nginx

     
    环境:
     
    VIP         192.168.2.224
    LVS        192.168.2.217     centos7
    nginx1    192.168.2.231     centos6
    nginx2    192.168.2.194     centos6
     
    LVS原理:
    国内的看得懂,哈哈  http://www.linuxvirtualserver.org/zh/lvs1.html
     
    一、LVS节点需做的
     
    1、安装ipvsadm,keepalived
    yum -y install keepalived ipvsadm
    yum install net-tools
     
    2、修改配置keepalived的配置文件
    global_defs {
       router_id LVS_DEVEL
    }
    
    vrrp_instance VI_1 {
        state MASTER
        interface eno16777736
        virtual_router_id 51
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.2.224
        }
    }
    
    virtual_server 192.168.2.231 80 {
        delay_loop 6
        lb_algo rr
        lb_kind NAT
        protocol TCP
    
        real_server 192.168.2.194 80 {
            weight 1
            SSL_GET {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
        
        real_server 192.168.2.231 80 {
            weight 1
            SSL_GET {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
    }
     
    3、启动keepalived
     
    systemctl start keepalived
     
    4、执行下面这个脚本
    #!/bin/bash
    VIP=192.168.2.224
    RIP1=192.168.2.231
    RIP2=192.168.2.194
    case "$1" in
    start)
            ipvsadm --save > /etc/sysconfig/ipvsadm
            systemctl start ipvsadm
            ifconfig eno16777736:0 $VIP broadcast $VIP netmask 255.255.255.255 broadcast $VIP up
            route add -host $VIP dev eno16777736:0
            ipvsadm -A -t $VIP:80 -s rr
            ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
            ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
            echo "ipvsadm starting --------------------[ok]"
            ;;
    stop)
            ipvsadm -C
            systemctl stop ipvsadm
            ifconfig eno16777736:0 down
            route del $VIP
            echo "ipvsamd stoped----------------------[ok]"
             ;;
    status)
            if [ ! -e /var/lock/subsys/ipvsadm ];then
            echo "ipvsadm stoped---------------"
            exit 1
                    else
                    echo "ipvsamd Runing ---------[ok]"
            fi
            ;;
    *)
    
    echo "Usage: $0 {start|stop|status}"
    exit 1
    esac
    exit 0
     
    二、web节点需做的
     
    1、先在两台nginx上把nginx装好,通过本机IP访问能区别两台机器,方便后面的测试,我这的nginx直接用的yum安装
     
     
     
     
    2、分别在两台机器上执行如下脚本
     
     
    #!/bin/bash
    VIP=192.168.2.224
    
    case "$1" in
        start)
            ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP 
            /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 >/dev/null 2>&1 
            echo "RealServer Start OK " 
            ;;
        stop)
            ifconfig lo:0 down
            route del $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 Stopd"
            ;;
        *)
            echo "Usage: $0 {start|stop}"
            exit 1
    esac
    
    exit 0
     
    三、测试
     
    这里的测试要在非lvs,nginx机器上测试,也就是与这些无关的机器上测试
     
     
    原文地址:https://www.cnblogs.com/lemon-le/p/9264581.html
  • 相关阅读:
    webMagic 处理get请求
    springCloud Stream
    获取印度时间
    java获取未来或者过去的时间
    List分批处理结果,并在每批中开启一个线程
    java中List集合分批处理
    Redis常用的数据类型
    ubuntu1604软件卸载
    Ubuntu清理无效包、废弃包、冗余包、rc包
    cuda各个版本官方下载地址
  • 原文地址:https://www.cnblogs.com/cpw6/p/9494105.html
Copyright © 2011-2022 走看看