نمایش نتایج: از شماره 1 تا 1 از مجموع 1
سپاس ها 4سپاس

موضوع: آموزش Failover سه خط اینترنت بصورتی که پشتیبان یک دیگر باشند.

  
  1. #1
    نام حقيقي: ali

    عضو عادی
    تاریخ عضویت
    Jun 2010
    محل سکونت
    mashhad
    نوشته
    605
    سپاسگزاری شده
    481
    سپاسگزاری کرده
    57

    آموزش Failover سه خط اینترنت بصورتی که پشتیبان یک دیگر باشند.

    درود خدمت دوستان.

    در آموزش دیگری نحوه Failover دو خط اینترنت را تشریح کردم :
    آموزش نحوه کانفیک سیستم Failover در روترهای میکروتیک

    در این تاپیک به روش مشابه می خواهم سه خط اینترنتی را پشتیبان یک دیگر قرار دهم، این روش قابل گسترش به هر تعداد خط جهت Failover می باشد.

    ترافیک اینترنت همواره از یک خط بصورت پیشفرض عبور داده می شود، اما درصورت قطع یکی از خطوط، خط دیگر به عنوان خط پیش فرض عبور ترافیک قرار خواهد گرفت.
    ترتیب اولویت خطوط اینترنت از خط با اولویت بالاتر فعال خواهد شد که مقدار Distance نشانگر آن است و به ترتیب خط یک بیشترین اولیت و خط سه کمترین اولیت را دارا می باشد، مثلا اگه خط دو و سه باهم فعال باشند، اینترنت شبکه از خط دوم برقرار می گردد.

    نحوه کار به این صورت است که ما شش عدد Netwatch می سازیم، سه عدد از آنها در دوره های زمانی دلخواه، هر یک از مودم ها را پینگ میکنند تا اطمینان داشته باشند کابل شبکه و یا برق آنها قطع نگردیده است.
    سه تای دیگر، سه آدرس در روی اینترنت را از مسیر هر یک از خطوط اینترنت ما، پینگ میکنند تا اطمینان داشته باشند اینترنت از روی تمام خطوط در دسترس است.

    اگر تغییری در وضعیت خطوط توسط هرکدام از Netwatch ها گزارش شود، یکی از اسکریپت های Down و یا UP اجرا خواهد شد و تعداد بیشتری پینگ از تمام خطوط و مودم ها گرفته می شود تا وضعیت خطوط کاملا روشن گردد و اطمینان پیدا شود که گزارش ارسالی به دلیل پکت لاست یا نوسان لحظه ای شبکه نبوده و روتر ما با وضعیت جدیدی در شبکه روبرو گشته است، سپس خطوط قطع شده را بصورت موقت از سرویس دهی خارج نموده و یا خطوطی که اینترنت از روی آنها مجدد برقرار گشته را در وضعیت سرویس دهی قرار داده و قابل استفاده باز می گرداند.

    رخ داد ها بطور دائم در لاگ روتر ثبت می گردد. همچنین تغییر وضعیت شبکه را به بصورت SMS و پیام تلگرام به اطلاع شما می رساند.
    همچنین این اسکریپت از ارسال پیام SMS بین ساعت یک نیم شب تا هفت صبح خودداری می کند و تنها به ارسال پیام در تلگرام و Log روتر اکتفا میکند.

    -نحوه کانفیگ اولیه جهت ارسال پیام اطلاع رسانی روتر، که پیش نیاز است را قبلا به دفعات بیان کردم، از تاپیک قبلی Failover می توانید پیگیر آن باشید، جهت جلوگیری از طولانی شدن این تاپیک، مجددا تکرار نمی کنم.

    اسکریپت Link_Down که می بایست در زمانی اجرا شود که هر یک از Netwatch ها تغییر وضعیت به حالت Down را گزارش می کنند:

    کد:
    #Script Name: #Link_Down #================================= #Need Settings: #/ip route add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=1 comment="Line1" #/ip route add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=2 comment="Line2" #/ip route add dst-address=0.0.0.0/0 gateway=192.168.3.1 distance=3 comment="line3" #/ip route add dst-address=104.160.141.3 gateway=192.168.1.1 comment="Netwatch Check Line1" #/ip route add dst-address=185.40.64.110 gateway=192.168.2.1 comment="Netwatch Check Line2" #/ip route add dst-address=185.13.230.22 gateway=192.168.3.1 comment="Netwatch Check Line3" #/tool netwatch add host=104.160.141.3 interval="00:00:35" comment="Line1 Internet Check" up-script="Link_UP" down-script="Link_Down" #/tool netwatch add host=185.40.64.110 interval="00:00:45" comment="Line2 Internet Check" up-script="Link_UP" down-script="Link_Down" #/tool netwatch add host=185.13.230.22 interval="00:00:55" comment="Line3 Internet Check" up-script="Link_UP" down-script="Link_Down" #/tool netwatch add host=192.168.1.1 interval="00:00:15" comment="modem1 Internet Check" up-script="Link_UP" down-script="Link_Down" #/tool netwatch add host=192.168.2.1 interval="00:00:20" comment="modem2 Internet Check" up-script="Link_UP" down-script="Link_Down" #/tool netwatch add host=192.168.3.1 interval="00:00:25" comment="modem3 Internet Check" up-script="Link_UP" down-script="Link_Down" #Send Msg To Telegram #/ip route add dst-address=149.154.167.220 gateway=l2tp-out1 comment="Send Telegram Msg To VPN" #/ip dns static add name="api.telegram.org" address=149.154.167.220 #================================= :local NetPing1 [:tonum [ping 104.160.141.3 count=20]] ; :local ModemPing1 [:tonum [ping 192.168.1.1 count=3]] ; :local NetPing2 [:tonum [ping 185.40.64.110 count=20]] ; :local ModemPing2 [:tonum [ping 192.168.2.1 count=3]] ; :local NetPing3 [:tonum [ping 185.13.230.22 count=20]] ; :local ModemPing3 [:tonum [ping 192.168.3.1 count=3]] ; :local dateM [system clock get date] ; :local timeM [system clock get time] ; :local TimeH [:tonum [:pick $timeM 0 2]] ; #SMS-Info :local SmsUsername "MyUser" :local SmsPassword "MyPass" :local SendMobileNum "5000XXXXXXXXXX" :local MyNum "0912XXXXXXX" :local SmsTextLine1 "Internet%20Line1%20Down%20:%0A$dateM%20-%20$timeM" :local SmsTextLine2 "Internet%20Line2%20Down%20:%0A$dateM%20-%20$timeM" :local SmsTextLine3 "Internet%20Line3%20Down%20:%0A$dateM%20-%20$timeM" #Telegram-Info :local BotToken "720638877:AAFwcEy5n5TN130XXXXXXXXXX-XXXXXXXX" :local MyID "13651XXXX" :local LOOPcontinue true; :local LOOPcounter 0; :local TelTextLine1 "Internet%20Line1%20Down%20:%0A$dateM%20-%20$timeM" :local TelTextLine2 "Internet%20Line2%20Down%20:%0A$dateM%20-%20$timeM" :local TelTextLine3 "Internet%20Line3%20Down%20:%0A$dateM%20-%20$timeM" :local PingMsgLine1 "The%20Line1%20Modem%20does%20not%20ping." :local PingMsgLine2 "The%20Line2%20Modem%20does%20not%20ping." :local PingMsgLine3 "The%20Line3%20Modem%20does%20not%20ping." log error message="DownRun-internet Line1 Ping alive Count= $NetPing1 of 20" ; log error message="DownRun-Modem Line1 Ping alive Count= $ModemPing1 of 3" ; log error message="DownRun-internet Line2 Ping alive Count= $NetPing2 of 20" ; log error message="DownRun-Modem Line2 Ping alive Count= $ModemPing2 of 3" ; log error message="DownRun-internet Line3 Ping alive Count= $NetPing3 of 20" ; log error message="DownRun-Modem Line3 Ping alive Count= $ModemPing3 of 3" ; :if ([:len [ip route find where comment="Line1" and !disabled]] > 0) do={ :if (( $NetPing1 < 5 ) || ( $ModemPing1 = 0 )) do={ ip route disable [find comment="Line1"] ; log error message="Line1 Down => $timeM - $dateM" ; #Send SMS IF Time 7AM To 1 AM :if (( $TimeH >= 07 ) || ( $TimeH <= 00 )) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=$SmsTextLine1&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Line1 SMS DC alert sended" ; } on-error={ log error "Line1 Down SMS was not sent to Your Mobile." ; } :if ( $ModemPing1 = 0 ) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=$PingMsgLine1&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Modem1 SMS DC alert sended" ; } on-error={ log error "Modem1 Down SMS was not sent to Your Mobile."; } } } ; # Loop For Wait VPN Connecting :set LOOPcontinue true; :set LOOPcounter 0; :while ($LOOPcontinue) do={ :set LOOPcounter ($LOOPcounter + 1); :if ([ping 149.154.167.220 count=5] = 5) do={ :set LOOPcontinue false; log info ((5*$LOOPcounter)." Sec Wait For VPN Connect. LOOP Counter=$LOOPcounter"); :set LOOPcounter 0; } } :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$TelTextLine1" mode=https keep-result=no ; log info "Line1 Telegram DC alert sended" ; } on-error={ log error "Line1 Down Telegram Message was not sent."; } :if ( $ModemPing1 = 0 ) do={ :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$PingMsgLine1" mode=https keep-result=no ; log info "Modem1 Telegram DC alert sended" ; } on-error={ log error "Modem1 Down Telegram Message was not sent."; } } } ; } ; :if ([:len [ip route find where comment="Line2" and !disabled]] > 0) do={ :if (( $NetPing2 < 5 ) || ( $ModemPing2 = 0 )) do={ ip route disable [find comment="Line2"] ; log error message="Line2 Down => $timeM - $dateM" ; #Send SMS IF Time 7AM To 1 AM :if (( $TimeH >= 07 ) || ( $TimeH <= 00 )) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=$SmsTextLine2&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Line2 SMS DC alert sended" ; } on-error={ log error "Line2 Down SMS was not sent to Your Mobile." ; } :if ( $ModemPing2 = 0 ) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=$PingMsgLine2&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Modem2 SMS DC alert sended" ; } on-error={ log error "Modem2 Down SMS was not sent to Your Mobile."; } } } ; # Loop For Wait VPN Connecting :set LOOPcontinue true; :set LOOPcounter 0; :while ($LOOPcontinue) do={ :set LOOPcounter ($LOOPcounter + 1); :if ([ping 149.154.167.220 count=5] = 5) do={ :set LOOPcontinue false; log info ((5*$LOOPcounter)." Sec Wait For VPN Connect. LOOP Counter=$LOOPcounter"); :set LOOPcounter 0; } } :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$TelTextLine2" mode=https keep-result=no ; log info "Line2 Telegram DC alert sended" ; } on-error={ log error "Line2 Down Telegram Message was not sent."; } :if ( $ModemPing2 = 0 ) do={ :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$PingMsgLine2" mode=https keep-result=no ; log info "Modem2 Telegram DC alert sended" ; } on-error={ log error "Modem2 Down Telegram Message was not sent."; } } } ; } ; :if ([:len [ip route find where comment="Line3" and !disabled]] > 0) do={ :if (( $NetPing3 < 5 ) || ( $ModemPing3 = 0 )) do={ ip route disable [find comment="Line3"] ; log error message="Line3 Down => $timeM - $dateM" ; #Send SMS IF Time 7AM To 1 AM :if (( $TimeH >= 07 ) || ( $TimeH <= 00 )) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=$SmsTextLine3&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Line3 SMS DC alert sended" ; } on-error={ log error "Line3 Down SMS was not sent to Your Mobile." ; } :if ( $ModemPing2 = 0 ) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=$PingMsgLine3&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Modem3 SMS DC alert sended" ; } on-error={ log error "Modem3 Down SMS was not sent to Your Mobile."; } } } ; # Loop For Wait VPN Connecting :set LOOPcontinue true; :set LOOPcounter 0; :while ($LOOPcontinue) do={ :set LOOPcounter ($LOOPcounter + 1); :if ([ping 149.154.167.220 count=5] = 5) do={ :set LOOPcontinue false; log info ((5*$LOOPcounter)." Sec Wait For VPN Connect. LOOP Counter=$LOOPcounter"); :set LOOPcounter 0; } } :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$TelTextLine3" mode=https keep-result=no ; log info "Line3 Telegram DC alert sended" ; } on-error={ log error "Line3 Down Telegram Message was not sent."; } :if ( $ModemPing3 = 0 ) do={ :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$PingMsgLine3" mode=https keep-result=no ; log info "Modem3 Telegram DC alert sended" ; } on-error={ log error "Modem3 Down Telegram Message was not sent."; } } } ; } ; :if ( ([:len [ip route find where comment="Line1" and disabled]] > 0) && ([:len [ip route find where comment="Line2" and disabled]] > 0) && ([:len [ip route find where comment="Line3" and disabled]] > 0) ) do={ ip route enable [find comment="Line1"] ; log info "3Line Disabled! Line1 Activated but no internet" ; }

    اسکریپت Link_Up که می بایست در زمانی اجرا شود که هر یک از Netwatch ها تغییر وضعیت به حالت UP را گزارش می کنند:

    کد:
    #Script Name: #Link_UP :local NetPing1 [:tonum [ping 104.160.141.3 count=10]] ; :local ModemPing1 [:tonum [ping 192.168.1.1 count=3]] ; :local NetPing2 [:tonum [ping 185.40.64.110 count=10]] ; :local ModemPing2 [:tonum [ping 192.168.2.1 count=3]] ; :local NetPing3 [:tonum [ping 185.13.230.22 count=10]] ; :local ModemPing3 [:tonum [ping 192.168.3.1 count=3]] ; :local dateM [system clock get date] ; :local timeM [system clock get time] ; :local TimeH [:tonum [:pick $timeM 0 2]] ; #SMS-Info :local SmsUsername "MyUser" ; :local SmsPassword "MyPass" ; :local SendMobileNum "5000XXXXXXXXXX" ; :local MyNum "0912XXXXXXX" ; :local SmsTextLine1 "Internet%20Line1%20UP%20:%0A$dateM%20-%20$timeM" :local SmsTextLine2 "Internet%20Line2%20UP%20:%0A$dateM%20-%20$timeM" :local SmsTextLine3 "Internet%20Line3%20UP%20:%0A$dateM%20-%20$timeM" #Telegram-Info :local BotToken "720638877:AAFwcEy5n5TN130XXXXXXXXXX-XXXXXXXXX" ; :local MyID "13651XXXX" ; :local LOOPcontinue true; :local LOOPcounter 0; :local TelTextLine1 "Internet%20Line1%20UP%20:%0A$dateM%20-%20$timeM" :local TelTextLine2 "Internet%20Line2%20UP%20:%0A$dateM%20-%20$timeM" :local TelTextLine3 "Internet%20Line3%20UP%20:%0A$dateM%20-%20$timeM" log error message="UpRun-internet Line1 Ping alive Count= $NetPing1 of 10" ; log error message="UpRun-Modem Line1 Ping alive Count= $ModemPing1 of 3" ; log error message="UpRun-internet Line2 Ping alive Count= $NetPing2 of 10" ; log error message="UpRun-Modem Line2 Ping alive Count= $ModemPing2 of 3" ; log error message="UpRun-internet Line3 Ping alive Count= $NetPing3 of 10" ; log error message="UpRun-Modem Line3 Ping alive Count= $ModemPing3 of 3" ; :if ([:len [ip route find where comment="Line1" and disabled]] > 0) do={ :if (($NetPing1 > 3) && ($ModemPing1 = 3)) do={ ip route enable [find comment="Line1"] ; log error message="Line1 UP => $timeM - $dateM" ; #Send SMS In the 7Am to 1Am time :if (( $TimeH >= 07 ) || ( $TimeH <= 00 )) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=SmsTextLine1&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Line1 SMS UP alert sended" ; } on-error={ log error "Line1 UP SMS was not sent to Your Mobile."; } } ; # Loop For Wait VPN Connecting :set LOOPcontinue true; :set LOOPcounter 0; :while ($LOOPcontinue) do={ :set LOOPcounter ($LOOPcounter + 1); :if ([ping 149.154.167.220 count=5] = 5) do={ :set LOOPcontinue false; log info ((5*$LOOPcounter)." Sec Wait For VPN Connect. LOOP Counter=$LOOPcounter"); :set LOOPcounter 0; } } #Send Telegram Msg :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$TelTextLine1" mode=https keep-result=no ; log info "Line1 Telegram UP alert sended" ; } on-error={ log error "Line1 UP Telegram Message was not sent."; } } ; } ; :if ([:len [ip route find where comment="Line2" and disabled]] > 0) do={ :if (($NetPing2 > 3) && ($ModemPing2 = 3)) do={ ip route enable [find comment="Line2"] ; log error message="Line2 UP => $timeM - $dateM" ; #Send SMS In the 7Am to 1Am time :if (( $TimeH >= 07 ) || ( $TimeH <= 00 )) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=SmsTextLine2&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Line2 SMS UP alert sended" ; } on-error={ log error "Line2 UP SMS was not sent to Your Mobile."; } } ; # Loop For Wait VPN Connecting :set LOOPcontinue true; :set LOOPcounter 0; :while ($LOOPcontinue) do={ :set LOOPcounter ($LOOPcounter + 1); :if ([ping 149.154.167.220 count=5] = 5) do={ :set LOOPcontinue false; log info ((5*$LOOPcounter)." Sec Wait For VPN Connect. LOOP Counter=$LOOPcounter"); :set LOOPcounter 0; } } #Send Telegram Msg :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$TelTextLine2" mode=https keep-result=no ; log info "Line2 Telegram UP alert sended" ; } on-error={ log error "Line2 UP Telegram Message was not sent."; } } ; } ; :if ([:len [ip route find where comment="Line3" and disabled]] > 0) do={ :if (($NetPing3 > 3) && ($ModemPing3 = 3)) do={ ip route enable [find comment="Line3"] ; log error message="Line3 UP => $timeM - $dateM" ; #Send SMS In the 7Am to 1Am time :if (( $TimeH >= 07 ) || ( $TimeH <= 00 )) do={ :do { tool fetch url="https://raygansms.com/SendMessageWithUrl.ashx?Username=$SmsUsername&Password=$SmsPassword&PhoneNumber=$SendMobileNum&MessageBody=SmsTextLine3&RecNumber=$MyNum&Smsclass=1" mode=https keep-result=no ; log info "Line3 SMS UP alert sended" ; } on-error={ log error "Line3 UP SMS was not sent to Your Mobile."; } } ; # Loop For Wait VPN Connecting :set LOOPcontinue true; :set LOOPcounter 0; :while ($LOOPcontinue) do={ :set LOOPcounter ($LOOPcounter + 1); :if ([ping 149.154.167.220 count=5] = 5) do={ :set LOOPcontinue false; log info ((5*$LOOPcounter)." Sec Wait For VPN Connect. LOOP Counter=$LOOPcounter"); :set LOOPcounter 0; } } #Send Telegram Msg :do { tool fetch url="https://api.telegram.org/bot$BotToken/sendmessage?chat_id=$MyID&text=$TelTextLine3" mode=https keep-result=no ; log info "Line3 Telegram UP alert sended" ; } on-error={ log error "Line3 UP Telegram Message was not sent."; } } ; } ;




    موضوعات مشابه:
    ویرایش توسط shahani : 2020-10-04 در ساعت 10:51 AM
    morteza-p، morteza-p، mehrzadmo و 1 نفر دیگر سپاسگزاری کرده‌اند.

کلمات کلیدی در جستجوها:

هیچ کلمه ای ثبت نشده است.

برچسب برای این موضوع

مجوز های ارسال و ویرایش

  • شما نمی توانید موضوع جدید ارسال کنید
  • شما نمی توانید به پست ها پاسخ دهید
  • شما نمی توانید فایل پیوست ضمیمه کنید
  • شما نمی توانید پست های خود را ویرایش کنید
  •