lvs keepalived做DNS集群负载
Posted 林肯公园
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
以上是关于lvs keepalived做DNS集群负载的主要内容,如果未能解决你的问题,请参考以下文章
lvs+keepalived+bind实现负载均衡高可用智能dns