zoukankan      html  css  js  c++  java
  • lvs+keepalived 02

    LVS keepalived 高可用负载均衡

    1. 环境

    IP

    HOSTNAME

    Describe

    192.168.100.30

    lvs01

    主负载

    192.168.100.31

    lvs02

    备负载

    192.168.100.40

    VIP

    192.168.100.29

    node01

    节点

    192.168.100.28

    node02

    节点

    192.168.100.27

    node03

    节点

    1. 安装

    yum -y install ipvsadm keepalived

    1. 主负载配置

    ! Configuration File for keepalived

    global_defs {

       notification_email {

         acassen@firewall.loc

         failover@firewall.loc

         sysadmin@firewall.loc

       }

       notification_email_from Alexandre.Cassen@firewall.loc

       smtp_server 192.168.200.1

       smtp_connect_timeout 30

       router_id LVS_DEVEL

       vrrp_skip_check_adv_addr

       vrrp_strict

       vrrp_garp_interval 0

       vrrp_gna_interval 0

    }

    vrrp_instance VI_1 {

        state MASTER

        interface eth0

        virtual_router_id 51

        priority 150

        advert_int 1

        authentication {

            auth_type PASS

            auth_pass 1111

        }

        virtual_ipaddress {

            192.168.100.40/24 dev eth0 label eth0:0

        }

    }

    virtual_server 192.168.100.40 3306 {

        delay_loop 6

        lb_algo rr

        lb_kind DR

        persistence_timeout 50

        protocol TCP

        real_server 192.168.100.27 3306 {

            weight 1

             MISC_CHECK {

             misc_path "/etc/keepalived/check.sh 192.168.100.27"

             misc_dynamic

             }

        }

        real_server 192.168.100.28 3306 {

            weight 1

             MISC_CHECK {

             misc_path "/etc/keepalived/check.sh 192.168.100.28"

             misc_dynamic

             }

        }

        real_server 192.168.100.29 3306 {

            weight 1

             MISC_CHECK {

             misc_path "/etc/keepalived/check.sh 192.168.100.29"

             misc_dynamic

             }

        }

    }

    1. 备负载配置

    ! Configuration File for keepalived

    global_defs {

       notification_email {

         acassen@firewall.loc

         failover@firewall.loc

         sysadmin@firewall.loc

       }

       notification_email_from Alexandre.Cassen@firewall.loc

       smtp_server 192.168.200.1

       smtp_connect_timeout 30

       router_id LVS_DEVEL_BACKUP

       vrrp_skip_check_adv_addr

       vrrp_strict

       vrrp_garp_interval 0

       vrrp_gna_interval 0

    }

    vrrp_instance VI_1 {

        state BACKUP

        interface eth0

        virtual_router_id 51

        priority 50

        advert_int 1

        authentication {

            auth_type PASS

            auth_pass 1111

        }

        virtual_ipaddress {

            192.168.100.40/24 dev eth0 label eth0:0

        }

    }

    virtual_server 192.168.100.40 3306 {

        delay_loop 6

        lb_algo rr

        lb_kind DR

        persistence_timeout 50

    protocol TCP

        real_server 192.168.100.27 3306 {

            weight 1

             MISC_CHECK {

             misc_path "/etc/keepalived/check.sh 192.168.100.27"

             misc_dynamic

             }

        }

        real_server 192.168.100.28 3306 {

            weight 1

             MISC_CHECK {

             misc_path "/etc/keepalived/check.sh 192.168.100.28"

             misc_dynamic

             }

        }

        real_server 192.168.100.29 3306 {

            weight 1

             MISC_CHECK {

             misc_path "/etc/keepalived/check.sh 192.168.100.29"

             misc_dynamic

             }

        }

    }

    /etc/keepalived/check.sh

    #!/bin/bash

    mysql -uwsrep -p123456 -h$1 -e "select 1;" &>/dev/null

    ret=$?

    if [ $ret -eq 0 ];then

        exit 0

    else

        exit 1

    fi

    1. 启动服务

    /etc/init.d/keepalived start

    /etc/init.d/ipvsadm start

    1. 测试

    关闭主负载keepalived,VIP漂移到备负载

    /etc/init.d/keepalived stop

    启动主负载keepalived,VIP漂移回来

    /etc/init.d/keepalived start

  • 相关阅读:
    word2vec原理(一) CBOW与Skip-Gram模型基础
    条件随机场CRF(三) 模型学习与维特比算法解码
    条件随机场CRF(二) 前向后向算法评估标记序列概率
    linux下如何强制卸载设备?
    docker build时如何使用代理?
    如何配置docker使用代理?
    linux下tar解压时报"gzip: stdin: unexpected end of file"如何处理?
    ubuntu下如何安装valgrind?
    linux下如何睡眠1ms?
    linux用户空间如何控制gpio?
  • 原文地址:https://www.cnblogs.com/wanglan/p/8042294.html
Copyright © 2011-2022 走看看