• 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

  • 相关阅读:
    51nod 1284:2 3 5 7的倍数 容斥原理
    POJ 2006:Litmus Test 化学公式
    POJ 2039:To and Fro
    POJ 2014:Flow Layout 模拟水题
    南阳722--数独(Dfs)
    Poj2377--Bad Cowtractors(最大生成树)
    并查集知识点总结
    Poj1861--Network(最小生成树)
    杭电2824--The Euler function(欧拉函数)
    杭电1284--钱币兑换问题(有趣)
  • 原文地址:https://www.cnblogs.com/wanglan/p/8042294.html
Copyright © 2020-2023  润新知