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原理:
     
    一、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机器上测试,也就是与这些无关的机器上测试
     
     
     
     注:参考网上各路大哥的,但是还是有很多问题,我这个绝对的可以。
     
  • 相关阅读:
    B01-java学习-阶段2-面向对象
    A11-java学习-二维数组-面向对象概念-类的编写-测试类的编写-创建对象-使用对象-递归
    09-java学习-数组-冒泡排序-选择排序-数组工具类编写-查找-扩容
    08-java学习-数组-增强for循环-数组与方法-main函数参数
    07-java学习-方法重载-idea集成开发工具学习-项目-模块-包
    执行SQL语句---SELECT
    执行SQL语句---INSERT/UPDATE/DELETE
    undefined reference to `mysql_init'解决办法
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    网络编程(三)---数据报套接字
  • 原文地址:https://www.cnblogs.com/lemon-le/p/9264581.html
Copyright © 2011-2022 走看看