Mikrotik | Forum Mikrotik Indonesia   Mikrotik Manual Mikrotik iSPY Mikrotik RSS Feed
This Logo is a Courtesy from RumahDowty

Go Back   Mikrotik | Forum Mikrotik Indonesia > Diskusi Mikrotik RouterOS > Scripting @ Mikrotik
iSpy My iTrade Register FAQ Members List Calendar Mark Forums Read

Diskusi Load Balance + Fail Over dengan script pada Scripting @ Mikrotik | Mikrotik | Forum Mikrotik Indonesia : Aku baru saja membuat script Fail Over untuk load balance pada http://www.forummikrotik.com/...




 
Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 22-02-2008, 23:16
yosanpro's Avatar
yosanpro yosanpro is offline
VIP Member
 
Join Date: Nov 2007
Location: Bantul, Bantul, Yogyakarta
Posts: 757
iTrader: (1)
Thanks: 23
Thanked 160 Times in 107 Posts
yosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to all
Send a message via Yahoo to yosanpro
Load Balance + Fail Over dengan script




Aku baru saja membuat script Fail Over untuk load balance pada Another Load Balancing Tutorial, dengan merubah-rubah parameter nth dan disable mangle secara otomatis (tentu saja dengan memanfaatkan netwatch). Script sudah bisa jalan, cuman belum dicoba di lapangan. Ntar kalo udah aku coba jalankan dan ternyata sukses, akan aku masukkan pada thread ini.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 23-02-2008, 11:51
yosanpro's Avatar
yosanpro yosanpro is offline
VIP Member
 
Join Date: Nov 2007
Location: Bantul, Bantul, Yogyakarta
Posts: 757
iTrader: (1)
Thanks: 23
Thanked 160 Times in 107 Posts
yosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to all
Send a message via Yahoo to yosanpro
Contoh Topologi yang dipakai pada script


ISP1-512kbps--------````````````interface WARNET1
```````````````````!`````````````!
SPEEDY1-384kbps--SWITCH HUB--->MIKROTIK----interface WARNET2
```````````````````!`````````````!
SPEEDY2-384kbps-----````````````interface WARNET3


ket:
  • Masing-masing warnet menggunakan satu interface
  • Modem ADSL speedy diset ke mode ROUTER/NAT
  • Interface Input digabung menggunakan SWITCH/HUB untuk menghemat port ethernet

Oleh karena terdapat perbedaan kecepatan ISP, maka mangle aku set 4:3:3. Untuk penggunaan konfigurasi berbeda, silahkan disesuaikan pada scriptnya, ntar aku kasih tanda deh parameter yang harusnya disesuaikan.

--- To Be Continued --- Next Chapter : Konfigurasi Mangle dan Routing

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 24-02-2008, 01:33
yosanpro's Avatar
yosanpro yosanpro is offline
VIP Member
 
Join Date: Nov 2007
Location: Bantul, Bantul, Yogyakarta
Posts: 757
iTrader: (1)
Thanks: 23
Thanked 160 Times in 107 Posts
yosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to all
Send a message via Yahoo to yosanpro
Baiklah, kita teruskan ke pembahasan berikutnya. Ini adalah contoh dari interface yang ada sesuai topologi di atas, namun dengan sedikit perubahan, dikarenakan kalau jalur ISP1 dan Speedy digabung, bandwidth akan dengan mudah dicuri maka yang digabung hanya dua Speedy dan ISP1 menggunakan interface sendiri

Code:
/interface print
Flags: X - disabled, D - dynamic, R - running 
 #    NAME                                 TYPE             RX-RATE    TX-RATE    MTU  
 0  R warnet1                                ether            0          0          1500 
 1  R warnet2                               ether            0          0          1500 
 2  R warnet3                                ether            0          0          1500 
 3  R ISP1                                 ether            0          0          1500 
 4  R Speedy                                 ether            0          0          1500
Untuk membuat mangle yang demikian banyak (parameter dapat diubah/disesuaikan) memakan banyak waktu, karena itu bisa disederhanakan dengan script berikut ini:

Code:
:for t from=1 to=10 do={
:local e "ISP1","ISP1","ISP1","ISP1","Spd1","Spd1","Spd1","Spd2","Spd2","Spd2"
/ip fire mangle add chain=prerouting in-interface="warnet1" \ 
connection-state=new nth=("9,1," . (($t)-1)) action=mark-connection \ 
new-connection-mark=("Net" . ($t)) passthrough=yes \
comment=("paketa" . ($t))
/ip fire mangle add chain=prerouting in-interface="warnet2" \ 
connection-state=new nth=("9,2," . (($t)-1)) action=mark-connection \ 
new-connection-mark=("Net" . ($t)) passthrough=yes \
comment=("paketb" . ($t))
/ip fire mangle add chain=prerouting in-interface="warnet3" \ 
connection-state=new nth=("9,3," . (($t)-1)) action=mark-connection \ 
new-connection-mark=("Net" . ($t)) passthrough=yes \
comment=("paketc" . ($t))
/ip firewall mangle add chain=prerouting in-interface="warnet1" \
connection-mark=("Net" . ($t)) action=mark-routing \
new-routing-mark=([:pick $e (($t)-1)]) comment=("routing" . ($t))
/ip firewall mangle add chain=prerouting in-interface="warnet2" \
connection-mark=("Net" . ($t)) action=mark-routing \
new-routing-mark=([:pick $e (($t)-1)]) comment=("routing" . ($t))
/ip firewall mangle add chain=prerouting in-interface="warnet3" \
connection-mark=("Net" . ($t)) action=mark-routing \
new-routing-mark=([:pick $e (($t)-1)]) comment=("routing" . ($t))
}
Parameter yang berwarna biru dapat diubah sesuai kebutuhan perbandingan bandwidth. Disini nth menggunakan counter yang berbeda untuk interface yang berbeda, sekedar untuk menjelaskan penggunaan counter. Dengan counter berbeda-beda tersebut maka tiap paket dari masing2 warnet akan menghitung sendiri-sendiri nth-nya. Apabila diinginkan topologi ke lokal hanya menggunakan 1 jalur, maka mangle connection cukup diberi satu saja, mis. paketa* (untuk paketb* dan paketc* bisa dihapus).

Untuk Routing bisa menggunakan sbb:

Code:
/ip route add dst-address=0.0.0.0/0 gateway=[IP ISP1] \
scope=255 target-scope=10 routing-mark="ISP1" disabled=no
/ip route add dst-address=0.0.0.0/0 gateway=[IP Speedy1] \
scope=255 target-scope=10 routing-mark="Spd1" disabled=no
/ip route add dst-address=0.0.0.0/0 gateway=[IP Speedy 2] \
scope=255 target-scope=10 routing-mark="Spd2" disabled=no
untuk NAT-nya bisa pake NAT masquerade biasa

Next Chapter ----- Fail Over Script


Last edited by yosanpro : 29-02-2008 at 21:07.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 24-02-2008, 01:57
yosanpro's Avatar
yosanpro yosanpro is offline
VIP Member
 
Join Date: Nov 2007
Location: Bantul, Bantul, Yogyakarta
Posts: 757
iTrader: (1)
Thanks: 23
Thanked 160 Times in 107 Posts
yosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to all
Send a message via Yahoo to yosanpro
Pertama kita buat script, misalnya dengan nama "failover" dengan kode sbb:

Code:
:set route1 [/tool netwatch get [/tool netwatch find comment="ISP1"] status]
:set route2 [/tool netwatch get [/tool netwatch find comment="Spd1"] status]
:set route3 [/tool netwatch get [/tool netwatch find comment="Spd2"] status]
:if ($route1="up") \
# Untuk baris berikut ini silahkan diganti angka-angka sesuai dengan rasio
# v1/v2/v3 sesuaikan angka rasionya kecuali yang angka 0 tetap 0
# w1/w2/w3 diberi angka 1 atau 0 sesuai dengan rasionya
do={:global v1 4; :global w1 1,1,1,1} \
else {:global v1 0; :global w1 0,0,0,0}
:if ($route2="up") \
do={:global v2 3; :global w2 1,1,1} \
else {:global v2 0; :global w2 0,0,0}
:if ($route3="up") \
do={:global v3 3; :global w3 1,1,1} \
else {:global v3 0; :global w3 0,0,0}
:global v ($v1 + $v2 + $v3 - 1)
:global w ($w1 . $w2 . $w3)
:local M 0
# untuk to disesuaikan penjumlahan semua rasionya
:for Z from=1 to=10 do={
:if ([:pick ($w) (($Z)-1)]="1") do={
/ip fire mangle enable [/ip fire mangle find \
comment=("paketa" . $Z)]
/ip fire mangle enable [/ip fire mangle find \
comment=("paketb" . $Z)]
/ip fire mangle enable [/ip fire mangle find \
comment=("paketc" . $Z)]
/ip fire mangle enable [/ip fire mangle find \
comment=("routing" . $Z)]
/ip fire mangle set [/ip fire mangle find \
comment=("paketa" . $Z)] nth=($v . ",1," . $M)
/ip fire mangle set [/ip fire mangle find \
comment=("paketb" . $Z)] nth=($v . ",2," . $M)
/ip fire mangle set [/ip fire mangle find \
comment=("paketc" . $Z)] nth=($v . ",3," . $M)
:set M ($M+1)
} else={
/ip fire mangle disable [/ip fire mangle find \
comment=("paketa" . $Z)]
/ip fire mangle disable [/ip fire mangle find \
comment=("paketb" . $Z)]
/ip fire mangle disable [/ip fire mangle find \
comment=("paketc" . $Z)]
/ip fire mangle disable [/ip fire mangle find \
comment=("routing" . $Z)]
}
}
Kode diatas akan mendeteksi netwatch masing2 ISP/Speedy dan secara otomatis mengubah nilai nth sesuai dengan ISP yang sedang aktif. Misalnya Speedy 1 tidak aktif maka routing & paket*5,6,7 akan di disable dan akan dihitung paket total yang aktif untuk mengisi nilai nth.

Langkah terakhir adalah membuat netwatch untuk masing2 ISP/Speedy, kemudian pada masing2 trigger (semua baik up maupun down) diberi pemanggil ke script ini

Code:
/tool netwatch
add host=[IP ISP1] disabled=no interval=20s comment="ISP1" \
up-script="failover" down-script="failover"
add host=[IP Speedy1] disabled=no interval=20s comment="Spd1" \
up-script="failover" down-script="failover"
add host=[IP Speedy2] disabled=no interval=20s comment="Spd2" \
up-script="failover" down-script="failover"
Demikian sedikit sharing dari saya. Jikalau ada kesalahan mohon dikoreksi.

Yah, walaupun sudah banyak yang membahas tentang Load Balance + Fail Over, tetapi kelihatannya belum ada yang dengan pendekatan script seperti ini, jadi walaupun tidak ada yang respons tetap aku uploadkan ke forum ini, semoga bisa menambah ilmu kita semua.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to yosanpro For This Useful Post:
  #5 (permalink)  
Old 17-03-2008, 09:32
aryOI's Avatar
aryOI aryOI is offline
Baru Gabung
 
Join Date: Oct 2007
Posts: 17
iTrader: (0)
Thanks: 3
Thanked 1 Time in 1 Post
aryOI is on a distinguished road
Tararengkyuu bro untuk sharingnyaa....

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 31-03-2008, 21:24
febry_AMZ's Avatar
febry_AMZ febry_AMZ is offline
Baru Gabung
 
Join Date: Mar 2008
Location: surabaya...malang...mojokerto
Posts: 4
iTrader: (0)
Thanks: 0
Thanked 0 Times in 0 Posts
febry_AMZ is on a distinguished road
Send a message via MSN to febry_AMZ Send a message via Yahoo to febry_AMZ Send a message via Skype™ to febry_AMZ
kayaknya keren tuh, ntar aku coba ke jaringan aku deh bro. Soalnya aku butuh ama nich script. Tp di tempat aku outputnya cuman satu interface sedangkan inputnya 3 interface. Kira-kira script itu perlu di modifikasi di bagian mananya yach, sori ya masih pemula nich.

mohon pencerahannya bro

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 31-03-2008, 23:13
d3v4's Avatar
d3v4 d3v4 is offline
VIP Member
 
Join Date: Jul 2007
Posts: 930
iTrader: (0)
Thanks: 38
Thanked 199 Times in 111 Posts
d3v4 is a glorious beacon of lightd3v4 is a glorious beacon of lightd3v4 is a glorious beacon of lightd3v4 is a glorious beacon of lightd3v4 is a glorious beacon of lightd3v4 is a glorious beacon of lightd3v4 is a glorious beacon of light
kek nya cocok di taro di tutorial nih

bagus banget

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-04-2008, 01:42
yosanpro's Avatar
yosanpro yosanpro is offline
VIP Member
 
Join Date: Nov 2007
Location: Bantul, Bantul, Yogyakarta
Posts: 757
iTrader: (1)
Thanks: 23
Thanked 160 Times in 107 Posts
yosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to all
Send a message via Yahoo to yosanpro
Quote:
Originally Posted by febry_AMZ View Post
kayaknya keren tuh, ntar aku coba ke jaringan aku deh bro. Soalnya aku butuh ama nich script. Tp di tempat aku outputnya cuman satu interface sedangkan inputnya 3 interface. Kira-kira script itu perlu di modifikasi di bagian mananya yach, sori ya masih pemula nich.

mohon pencerahannya bro
Kalo mo pake 1 interface output, diilangin aja baris-baris buat ngatur yang in-interface nya lain, jadi kira2 seperti ini:

Code:
:for t from=1 to=10 do={
:local e "ISP1","ISP1","ISP1","ISP1","Spd1","Spd1","Spd1","Spd2","Spd2","Spd2"
/ip fire mangle add chain=prerouting in-interface="warnet1" \ 
connection-state=new nth=("9,1," . (($t)-1)) action=mark-connection \ 
new-connection-mark=("Net" . ($t)) passthrough=yes \
comment=("paketa" . ($t))
/ip firewall mangle add chain=prerouting in-interface="warnet1" \
connection-mark=("Net" . ($t)) action=mark-routing \
new-routing-mark=([:pick $e (($t)-1)]) comment=("routing" . ($t))
}
dan untuk script failover nya:

Code:
:set route1 [/tool netwatch get [/tool netwatch find comment="ISP1"] status]
:set route2 [/tool netwatch get [/tool netwatch find comment="Spd1"] status]
:set route3 [/tool netwatch get [/tool netwatch find comment="Spd2"] status]
:if ($route1="up") \
# Untuk baris berikut ini silahkan diganti angka-angka sesuai dengan rasio
# v1/v2/v3 sesuaikan angka rasionya kecuali yang angka 0 tetap 0
# w1/w2/w3 diberi angka 1 atau 0 sesuai dengan rasionya
do={:global v1 4; :global w1 1,1,1,1} \
else {:global v1 0; :global w1 0,0,0,0}
:if ($route2="up") \
do={:global v2 3; :global w2 1,1,1} \
else {:global v2 0; :global w2 0,0,0}
:if ($route3="up") \
do={:global v3 3; :global w3 1,1,1} \
else {:global v3 0; :global w3 0,0,0}
:global v ($v1 + $v2 + $v3 - 1)
:global w ($w1 . $w2 . $w3)
:local M 0
# untuk to disesuaikan penjumlahan semua rasionya
:for Z from=1 to=10 do={
:if ([:pick ($w) (($Z)-1)]="1") do={
/ip fire mangle enable [/ip fire mangle find \
comment=("paketa" . $Z)]
/ip fire mangle enable [/ip fire mangle find \
comment=("routing" . $Z)]
/ip fire mangle set [/ip fire mangle find \
comment=("paketa" . $Z)] nth=($v . ",1," . $M)
:set M ($M+1)
} else={
/ip fire mangle disable [/ip fire mangle find \
comment=("paketa" . $Z)]
/ip fire mangle disable [/ip fire mangle find \
comment=("routing" . $Z)]
}
}
jangan lupa perbandingannya disesuaikan yah...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 22-11-2008, 00:29
Holim Holim is offline
Baru Gabung
 
Join Date: Nov 2008
Posts: 15
iTrader: (0)
Thanks: 2
Thanked 0 Times in 0 Posts
Holim is on a distinguished road
thx udah kasih tutor...tapi saya masih ada yang bingung...
Code:
:for t from=1 to=10 do={
:local e "ISP1","ISP1","ISP1","ISP1","Spd1","Spd1","Spd1","Spd2","Spd2","Spd2"
maksudnya apa ya???apakah local e itu bisa di ubah2 gak??

Code:
:if ($route1="up") \
# Untuk baris berikut ini silahkan diganti angka-angka sesuai dengan rasio
# v1/v2/v3 sesuaikan angka rasionya kecuali yang angka 0 tetap 0
# w1/w2/w3 diberi angka 1 atau 0 sesuai dengan rasionya
do={:global v1 4; :global w1 1,1,1,1} \
else {:global v1 0; :global w1 0,0,0,0}
:if ($route2="up") \
do={:global v2 3; :global w2 1,1,1} \
else {:global v2 0; :global w2 0,0,0}
:if ($route3="up") \
do={:global v3 3; :global w3 1,1,1} \
else {:global v3 0; :global w3 0,0,0}
:global v ($v1 + $v2 + $v3 - 1)
:global w ($w1 . $w2 . $w3)
:local M 0
v dan w itu apa ya??maksud global itu paramater ya???kalau udah " :if " mau tambahin ":if " lagi gak perlu "else if " ya????

thanky you...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 23-11-2008, 08:18
yosanpro's Avatar
yosanpro yosanpro is offline
VIP Member
 
Join Date: Nov 2007
Location: Bantul, Bantul, Yogyakarta
Posts: 757
iTrader: (1)
Thanks: 23
Thanked 160 Times in 107 Posts
yosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to all
Send a message via Yahoo to yosanpro
Wew... nih thread masih ada juga yang baca ya... padahal itu script dibuat untuk Mikrotik versi 2.9.xx, trus itu aku buat menyesuaikan client. Untuk penggunaan versi 3.xx banyak banget yang musti dirombak.

thx udah kasih tutor...tapi saya masih ada yang bingung...

Quote:
Code:
:for t from=1 to=10 do={
:local e "ISP1","ISP1","ISP1","ISP1","Spd1","Spd1","Spd1"," Spd2","Spd2","Spd2"maksudnya apa ya???apakah local e itu bisa di ubah2 gak??
itu menunjukkan jumlah koneksi dan perbandingan koneksi. untuk kasus diatas perbandingan koneksi 4:3:3 sehingga for diisi 4+3+3=10, kalau koneksi cuman 3 dengan perbandingan sama, silahkan diubah menjadi 3, dan :local e diisi 3 koneksi itu saja.

To be edited...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 27-11-2008, 21:58
all21 all21 is offline
Newbie
 
Join Date: Apr 2008
Posts: 21
iTrader: (0)
Thanks: 14
Thanked 1 Time in 1 Post
all21 is on a distinguished road
mas ini udah di coba ke v 3.16 ?????
trus kalo aku make 4 speedy & interface mikrotik untuk in / out hanya satu gimana??? bisa???
thx bro...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 28-11-2008, 17:46
yosanpro's Avatar
yosanpro yosanpro is offline
VIP Member
 
Join Date: Nov 2007
Location: Bantul, Bantul, Yogyakarta
Posts: 757
iTrader: (1)
Thanks: 23
Thanked 160 Times in 107 Posts
yosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to allyosanpro is a name known to all
Send a message via Yahoo to yosanpro
Script ini tidak jalan di 3.xx, mohon maaf belum ada rencana mengkonversi ke v3.xx.

Untuk pemakaian 1 interface untuk in/out dan 4 speedy bisa tetapi sangat tidak disarankan, karena client bisa dengan mudah mem-bypass Mikrotik dan menggunakan gateway modem langsung, jadi minimal 2 interface, 1 ke LAN dan 1 ke Internet. Empat speedy bisa digabungkan menggunakan switch, akan tetapi usahakan menggunakan switch yang berkualitas karena traffic yang melalui switch ini lumayan congested, untuk pemakaian Switch managed + VLAN secara teori bisa mengurangi traffic congestion, tetapi aku sendiri belum pernah mencoba.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On