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您也可以想讀 |




