码迷,mamicode.com
首页 > 其他好文 > 详细

快速搭建keepalived(DR)+lvs脚本

时间:2018-06-22 11:01:14      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:system   sysctl   delay   nat   The   read   tcp   persist   emctl   

#!/bin/bash #write:blacksnow echo "Welcome use keepalived+LVS(DR) script!!" read -p "Keepalived_master_地址: " KL_master read -p "Keepalived_backup地址: " KL_backup read -p "报警邮件名(eg:root@localhost): " EM_to read -p "邮件的发送名(eg:Elson@keepalive): " EM_from read -p "监测网络的接口(eg:eth0): " interface read -p "虚拟VIP地址: " vir_VIP read -p "虚拟访问端口(default 80): " port port=${port:-80} read -p "负载调度算法(rr/wrr): " lb_algo #read -p "负载均衡的机制(NAT/TUN/DR): " lb_kind lb_kind=‘DR‘ read -p "后端web-1地址: " real1_IP read -p "后端web-2地址: " real2_IP NULL="/dev/null" real1_weight=1 real2_weight=1 #################################################### #调度器Keepalived+lvs(DR) #################################################### # #ssh ${KL_master} yum -y install keepalived ipvsadm >${NULL} #ssh ${KL_backup} yum -y install keepalived ipvsadm >${NULL} # #################################################### #Keepalived+lvs(DR)MASTER配置 #################################################### cat <<EOE | ssh ${KL_master} "cat -> /etc/keepalived/keepalived.conf" ! Configuration File for keepalived global_defs { notification_email { ${EM_to} } notification_email_from ${EM_from} smtp_server 127.0.0.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 ${interface} virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { ${vir_VIP} } } virtual_server ${vir_VIP} ${port} { delay_loop 6 lb_algo ${lb_algo} lb_kind ${lb_kind} persistence_timeout 50 protocol TCP real_server ${real1_IP} ${port} { weight ${real1_weight} TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server ${real2_IP} ${port} { weight ${real2_weight} TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } EOE #################################################### #Keepalived+lvs(DR)BACKUP配置 #################################################### cat <<EOE | ssh ${KL_backup} "cat -> /etc/keepalived/keepalived.conf" ! Configuration File for keepalived global_defs { notification_email { ${EM_to} } notification_email_from ${EM_from} smtp_server 127.0.0.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 ${interface} virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { ${vir_VIP} } } virtual_server ${vir_VIP} ${port} { delay_loop 6 lb_algo ${lb_algo} lb_kind ${lb_kind} persistence_timeout 50 protocol TCP real_server ${real1_IP} ${port} { weight ${real1_weight} TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server ${real2_IP} ${port} { weight ${real2_weight} TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } EOE #################################################### #Realserver 修改ARP内核参数和绑定VIP地址 #################################################### for IP in ${real1_IP} ${real2_IP} do cat <<EOE |ssh ${IP} "cat - > /etc/sysconfig/network-scripts/ifcfg-lo:0" DEVICE=lo:0 IPADDR=${vir_VIP} NETMASK=255.255.255.255 NETWORK=${vir_VIP} BROADCAST=${vir_VIP} ONBOOT=yes NAME=lo:0 EOE ssh ${IP} ifup lo:0 cat <<EOE |ssh ${IP} "cat - > /etc/sysctl.conf" net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.lo.arp_announce = 2 EOE ssh ${IP} sysctl -p > ${NULL} done #################################################### #开启keepalived #################################################### ssh ${KL_master} "systemctl restart keepalived" ssh ${KL_master} "systemctl enable keepalived" ssh ${KL_backup} "systemctl restart keepalived" ssh ${KL_backup} "systemctl enable keepalived" echo -e "\033[36mSuccessful configure!!\033[0m"

快速搭建keepalived(DR)+lvs脚本

标签:system   sysctl   delay   nat   The   read   tcp   persist   emctl   

原文地址:http://blog.51cto.com/13762620/2131606

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!