Load Balancing & Failover Script for Dual/ Multi WAN / ADSL / Cable Connections on Linux with Mail on failure负载平衡与容错移转脚本为双/多湾/ ADSL的/电缆连接在Linux上与邮件上的失败
Please read the original article -请阅读原始文章- How To: Load Balancing & Failover With Dual/ Multi WAN / ADSL / Cable Connections on Linux如何:负载平衡与容错移转与双/多湾/ ADSL的/电缆连接在Linux上 . 。 It contains detailed information with a sample script.它包含的详细资料与示例脚本。 Viliam Kočinský modified my script to send email when routing table changes. viliam kočinský修改我的脚本来发送电子邮件时,路由表的变化。 Also he is starting the script as a service from /etc/init.d.此外,他是开始的脚本作为一个服务从的/ etc / init.d 。 Read below for his enhancements:阅读下面的他的改进:
I’m using your gwping script.我使用您的gwping脚本。 Realy usefull.真的有用。 I added posibility to send email, when routing table change:我已将posibility发送电子邮件时,路由表的变化:# cat /usr/local/sbin/gwping #猫在/ usr / local / sbin / gwping
……. … … 。EMAILFROM="root@myserver.example.com" emailfrom = “ root@myserver.example.com ”
EMAILTO="someone@example.com" emailto = “ someone@example.com ”
….. … ..if [[ $CLS1 -eq 0 || $CLS2 -eq 0 ]]; then如果[元cls1 -情商0 | |元cls2 -情商0 ] ,然后
if [[ $LLS1 -eq 1 && $LLS2 -eq 0 ]]; then如果[元lls1 -情商1 & &元lls2 -情商0 ] ,然后
echo Switching to $NAME2回声切换至name2
ip route replace default scope global via $GW2 dev $EXTIF2 IP路由取代预设的范围,全球经元gw2开发元extif2
LSROUTE=$(ip route show) lsroute = $ ( IP路由查看)
echo "$LSROUTE" | mail -s "GWPING - Routing table changed. Line $NAME1 is down."回声“ $ lsroute ” |邮件- S的“ gwping -路由表的改变。线元n ame1是下来” 。 -r $EMAILFROM $EMAILTO - R的元emailfrom元emailto
elif [[ $LLS1 -eq 0 && $LLS2 -eq 1 ]]; then elif [元lls1 -情商0 & &元lls2均衡器一] ,然后
echo Switching to $NAME1回声切换至name1
ip route replace default scope global via $GW1 dev $EXTIF1 IP路由取代预设的范围,全球经元gw1开发元extif1
LSROUTE=$(ip route show) lsroute = $ ( IP路由查看)
echo "$LSROUTE" | mail -s "GWPING - Routing table changed. Line $NAME2 is down."回声“ $ lsroute ” |邮件- S的“ gwping -路由表的改变。线元n ame2是下来” 。 -r $EMAILFROM $EMAILTO - R的元emailfrom元emailto
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 ]]; then elif [元lls1 -情商0 & &元lls2 -情商0 ] ,然后
echo Restoring default load balancing回声恢复默认负载平衡
#ip route replace default scope global via $GW1 dev $EXTIF1 # IP路由取代预设的范围,全球经元gw1开发元extif1
ip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2 IP路由取代预设的范围,全球nexthop经元gw1开发元extif1重量元的W1 nexthop经元gw2开发元extif2重量元w2
LSROUTE=$(ip route show) lsroute = $ ( IP路由查看)
echo "$LSROUTE" | mail -s "GWPING - Routing table changed. Both lines are up."回声“ $ lsroute ” |邮件- S的“ gwping -路由表的改变。两种线了” 。 -r $EMAILFROM $EMAILTO - R的元emailfrom元emailto
fi Fi的
fi Fi的
sleep $SLEEPTIME睡眠元sleeptime
done做完Also I’m starting this script as service from /etc/init.d还我开始此脚本作为服务的/ etc / init.d
# cat /etc/init.d/gwping #猫的/ etc / init.d / gwping
#!/bin/sh # ! / bin / sh的
# Author: Viliam Kocinsky #作者: viliam kocinsky### BEGIN INIT INFO # # #开始的init信息
# Short-Description: Monitor Internet access connection links and modify kernel route if some link go down. #短期描述:监察互联网接入连接链接和修改内核的路线,如果某种联系下去。
# Description: This is startup script for gwping script, that manage internet connection failover (if you have at least 2 providers). #描述:这是启动脚本为gwping脚本,即管理的网际网路连线故障(如果您有至少2提供商) 。
# That is, it reguraly ping one IP address #是,它reguraly平一个IP地址
# on internet through certain provider (but trying all) . #在互联网上通过一定的提供商(但尝试所有) 。 If ping doesn’t come back, than it addjust kernel route table.如果ping不回来,比addjust内核路由表。
# See inside script for details. #看到里面的脚本的细节。 This script is from the website:此脚本是从网站:
# http://blog.taragana.com/index.php/archive/how-to-load-balancing-failover-with-dual-multi-wan-adsl-cable-connections-on-linux/ # http://blog.taragana.com/index.php/archive/how-to-load-balancing-failover-with-dual-multi-wan-adsl-cable-connections-on-linux/
# #
### END INIT INFO # # #结束的init信息command="$1"指挥= “ $ 1 ”
case "$command" in案“ ,元军司令部”在
start)开始)
echo "Starting gwping."回声“开始gwping ” 。
/usr/local/sbin/gwping &在/ usr / local / sbin / gwping &
echo $!回声元! > /usr/local/share/gwping_pid >在/ usr / local /共享/ gwping_pid
;; ; ;
stop)停止)
echo "Stoping gwping."回声“回采gwping ” 。
kill -9 $(cat /usr/local/share/gwping_pid) && rm /usr/local/share/gwping_pid杀死-9元(猫在/ usr / local /共享/ gwping_pid ) & &室在/ usr / local /共享/ gwping_pid
;; ; ;
*) * )
echo "Usage /etc/init.d/gwping start|stop"回声“用法的/ etc / init.d / gwping开始|一站式”
;; ; ;
esac
Filed under提起下 Enterprise Software企业软件 , , Fedora 7 Fedora的7 , , Fedora Core 6是Fedora Core 6 , , Headline News头条新闻 , , How To如何 , , Linux Linux的 , , Linux Migration Linux迁移 , , Open Source Software开放源码软件 , , Tech Note技术说明 , , Web网页 | |
| |
RSS 2.0 2.0 | |
Trackback Trackback跟踪 this Article |此文章|
Email this Article电子邮件此文章
You may also like to read您也可以想读 |




