zoukankan      html  css  js  c++  java
  • centos7 lvs keepalived做DNS集群负载

    2LVS + keepalived

    5 bind dns源站

    yum -y install  ipvsadm keepalived

    lvs增加并发

    echo "options ip_vs conn_tab_bits=22" > /etc/modprobe.d/ip_vs.conf  然后重启服务器

    cat check_dns_resolve.sh   # 该文件加执行权限

    #!/bin/bash
    # check dns resolve
    
    a_check="check.healthcheck.check"
    nslookup_bin="/usr/bin/nslookup"
    
    ns_ip=$1
    port=53
    timeout=2
    
    
    function EchoHelp(){
        echo "use: ./check_dns_resolve.sh [ip] {port}"
        exit 1
    }
    
    if [ $2 ]; then
        port=$2
    fi
    
    
    if [ $ns_ip -a $a_check ]; then
        $nslookup_bin -timeout=${timeout} -port=$port $a_check $ns_ip > /dev/null
    else
        EchoHelp
    
    fi
    
    
    exit $?

    keepalived_notify.py 参照 https://www.cnblogs.com/linkenpark/p/7416998.html

    lvs1 keepalived配置:

    cat /etc/keepalived/keepalived.conf 

    global_defs {
        notification_email {
            keepalived@qq.com
        }
    
        notification_email_from keepalived@qq.com
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id lvs_canlu
    }
    
    
    vrrp_instance VI_1 {
        state BACKUP
        interface ens160
        virtual_router_id 162
        mcast_src_ip 172.16.12.26
        priority 100
        advert_int 2
    
        authentication {
            auth_type PASS
            auth_pass sPkdd98m
        }
    
        virtual_ipaddress {
            172.16.12.30
        }
    
        notify_master "/bin/python /tuandai/script/keepalived_notify.py master 172.16.12.26 172.16.12.30"
        notify_backup "/bin/python /tuandai/script/keepalived_notify.py backup 172.16.12.26 172.16.12.30"
    
    }
    
    ## dns_bind
    virtual_server 172.16.12.30 53 {
        delay_loop 6
        lb_algo lc
        lb_kind DR
        #persistence_timeout 1
        protocol UDP
    
        real_server 172.16.7.14 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.14"
                misc_timeout 5
            }
        }
        real_server 172.16.7.15 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.15"
                misc_timeout 5
            }
        }
        real_server 172.16.7.16 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.16"
                misc_timeout 5
            }
        }
        real_server 172.16.7.17 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.17"
                misc_timeout 5
            }
        }
        real_server 172.16.7.18 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.18"
                misc_timeout 5
            }
        }
    }

    lvs2 keepalived配置:

    global_defs {
        notification_email {
            keepalived@qq.com
        }
    
        notification_email_from keepalived@qq.com
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id lvs_canlu
    }
    
    
    vrrp_instance VI_1 {
        state BACKUP
        interface ens160
        virtual_router_id 162
        mcast_src_ip 172.16.12.27
        priority 99
        advert_int 2
    
        authentication {
            auth_type PASS
            auth_pass sPkdd98m
        }
    
        virtual_ipaddress {
            172.16.12.30
        }
    
        notify_master "/bin/python /tuandai/script/keepalived_notify.py master 172.16.12.27 172.16.12.30"
        notify_backup "/bin/python /tuandai/script/keepalived_notify.py backup 172.16.12.27 172.16.12.30"
    
    }
    
    ## dns_bind
    virtual_server 172.16.12.30 53 {
        delay_loop 6
        lb_algo lc
        lb_kind DR
        #persistence_timeout 1
        protocol UDP
    
        real_server 172.16.7.14 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.14"
                misc_timeout 5
            }
        }
        real_server 172.16.7.15 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.15"
                misc_timeout 5
            }
        }
        real_server 172.16.7.16 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.16"
                misc_timeout 5
            }
        }
        real_server 172.16.7.17 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.17"
                misc_timeout 5
            }
        }
        real_server 172.16.7.18 53 {
            weight 10
            MISC_CHECK {
                misc_path "/usr/bin/sh /etc/keepalived/check_dns_resolve.sh 172.16.7.18"
                misc_timeout 5
            }
        }
    }

    keepalived进程检测:

    cat /script/check_keepalived.sh

    #!/bin/bash
    
    servicename="keepalived"
    showname="keepalived"
    pid="keepalived"
    status="${showname}_failed"
    success_status="${showname}_success"
    
    function CheckPs(){
        local ret=`pidof $pid | wc -l`
        echo $ret
    }
    
    if [ $(CheckPs) == 0 ]; then
        service $servicename restart
        sleep 1
        if [ $(CheckPs) != 0 ]; then
            status=$success_status
        fi
    
    else
        status=$success_status
    fi
    
    echo $status

    添加定时任务

    cat /etc/crontab

    ## check keepalived
    * * * * *               root    sh /script/check_keepalived.sh > /dev/null;
  • 相关阅读:
    关于发布版本号管理
    WWF
    C#编码规范和命名规则
    使用正则表达式更改编译版本号
    .net2005登录控件
    读取web.config自定义配置节
    在SQL SERVER 2005 中使用XML
    CVSNT用户权限配置
    共享鼠标
    《Ajax基础教程》
  • 原文地址:https://www.cnblogs.com/linkenpark/p/8799137.html
Copyright © 2011-2022 走看看