1. 程式人生 > >lvs keepalived做DNS集群負載

lvs keepalived做DNS集群負載

prior .py IT route 集群負載 $? efs ipvs null

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 {
        [email protected]
    }

    notification_email_from [email protected]
    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 {
        [email protected]
    }

    notification_email_from [email protected]
    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
        }
    }
}

lvs keepalived做DNS集群負載