rianto isaac's Weblog

rianto utomo isaac sahala utomo

linux, Load Balancing & Failover With Multiple Connections

leave a comment »

Buat yang punya multiple connection baik itu di kantor, di warnet, di pos kamling, sampe di pos satpam dan di warteg-warteg.. (haaaalaaaahh..) Nah berikut cara buat load balancing dan failover untuk multiple connection di linux.

Setelah baca primbon Linux Advanced Routing & Traffic Control HOWTO akhirnya menemukan caranya. Trus langkah yang paling awal kita harus ngerti dulu jaringan yang kita punya. So mari kita cari informasinya

Link internet A ipnya 192.168.5.1 gatewaynya 192.168.5.254

Link internet B ipnya 10.10.10.6 gatewaynya 10.10.10.5

Untuk koneksi yang lebih cepet adalah koneksi internet B sehingga weight nya di set 4 supaya ga kusut katanya.

Okey.. informasi udah kumplit.. Sekarang kita rock n roll di linux ^^

Buat dua routing didalam routing table ( /etc/iproute2/rt_tables ). Lalu buka file dan lakukan penambahan sesuai dengan konksi internet kita:

1 ispa
2 ispb

Untuk mengatur load balancing route dengan multiple connection tambah file ini di rc.local:
## ispa
ip route add 192.168.5.0/24 dev eth1 src 192.168.5.1 table ispa
ip route add default via 192.168.5.254 table ispa
ip rule add from 192.168.5.254 table ispa
## ispb
ip route add 10.10.10.0/24 dev eth2 src 10.10.10.6 table ispb
ip route add default via 10.10.10.5 table ispb
ip rule add from 10.10.10.5 table ispb
ip route add default scope global nexthop via 192.168.5.254 dev eth1 weight 1 nexthop via 10.10.10.5 dev eth2 weight 4

Untuk Failover

Buat file namanya /usr/local/sbin/gwping isinya

#####
EMAILFROM=”root@myserver.example.com”
EMAILTO=”someone@example.com”

#IP Address or domain name to ping. The script relies on the domain being pingable and always available
TESTIP=www.yahoo.com

#Ping timeout in seconds
TIMEOUT=2

# External interfaces
EXTIF1=eth1
EXTIF2=eth2

#IP address of external interfaces. This is not the gateway address.
IP1=192.168.5.1
IP2=10.10.10.6

#Gateway IP addresses. This is the first (hop) gateway, could be your router IP
#address if it has been configured as the gateway
GW1=192.168.5.254
GW2=10.10.10.5

# Relative weights of routes. Keep this to a low integer value. I am using 4
# for TATA connection because it is 4 times faster
W1=1
W2=4

# Broadband providers name; use your own names here.
NAME1=ispa
NAME2=ispb

#No of repeats of success or failure before changing status of connection
SUCCESSREPEATCOUNT=4
FAILUREREPEATCOUNT=1
#####

if [[ $CLS1 -eq 0 || $CLS2 -eq 0 ]]; then
if [[ $LLS1 -eq 1 && $LLS2 -eq 0 ]]; then
echo Switching to $NAME2
ip route replace default scope global via $GW2 dev $EXTIF2
LSROUTE=$(ip route show)
echo “$LSROUTE” | mail -s “GWPING – Routing table changed. Line $NAME1 is down.” -r $EMAILFROM $EMAILTO
elif [[ $LLS1 -eq 0 && $LLS2 -eq 1 ]]; then
echo Switching to $NAME1
ip route replace default scope global via $GW1 dev $EXTIF1
LSROUTE=$(ip route show)
echo “$LSROUTE” | mail -s “GWPING – Routing table changed. Line $NAME2 is down.” -r $EMAILFROM $EMAILTO
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 ]]; then
echo Restoring default load balancing
#ip route replace default scope global via $GW1 dev $EXTIF1
ip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2
LSROUTE=$(ip route show)
echo “$LSROUTE” | mail -s “GWPING – Routing table changed. Both lines are up.” -r $EMAILFROM $EMAILTO
fi
fi
sleep $SLEEPTIME
done

Lalu buat file /etc/init.d/gwping isinya

#!/bin/sh
# Author: Viliam Kocinsky

### BEGIN INIT INFO
# 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).
# That is, it reguraly ping one IP address
# on internet through certain provider (but trying all) . If ping doesn’t come back, than it addjust kernel route table.
# 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/
#
### END INIT INFO

command=”$1″

case “$command” in
start)
echo “Starting gwping.”
/usr/local/sbin/gwping &
echo $! > /usr/local/share/gwping_pid
;;
stop)
echo “Stoping gwping.”
kill -9 $(cat /usr/local/share/gwping_pid) && rm /usr/local/share/gwping_pid
;;
*)
echo “Usage /etc/init.d/gwping start|stop”
;;
esac

rianto utomo bole nyontek dari http://henry.suhatman.com/blog/2008/06/load-balancing-failover-with-multiple-connections-on-linux/

Written by isaaconi

Januari 23, 2009 pada 6:20 am

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: