01 Mei
2010

Load Balancing 3 ISP

Asumsi:

ISP A bandwidth = 2 Mbps
ISP B bandwidth = 1 Mbps
ISP C bandwidth = 512 Kbps

Setup:

Buka dan edit file: /etc/iproute2/rt_tables

Buat isinya sebagai berikut:

#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
1   ispA
2   ispB
3   ispC

Buat file: /etc/rc.d/rc.loadbalancing

dengan isi sebagai berikut:

#!/bin/sh
#
TBL1=ispA
TBL2=ispB
TBL3=ispB
# Data Internal Network
INT_IF="eth0"
INT_IP="192.168.100.1"
INT_NET="192.168.100.0/24"
# Data External Network untuk ISP A
EXT_IF1="eth1"
EXT_IP1="192.168.101.21"
EXT_GW1="192.168..101.17"
EXT_NET1="192.168..101.16/28"
EXT_WEIGHT1="4"
# Data External Network untuk ISP B
EXT_IF2="eth2"
EXT_IP2="192.168..183.51"
EXT_GW2="192.168..183.49"
EXT_NET2="192.168..183.48/28"
EXT_WEIGHT2="2"
# Data External Network untuk ISP C
EXT_IF3="eth3"
EXT_IP3="192.168..149.188"
EXT_GW3="192.168..149.177"
NET_EXT3="192.168..149.176/28"
EXT_WEIGHT3="1"
IP="/sbin/ip"
# Tambahkan network routing table untuk ketiga ISP
$IP route append $EXT_NET1 dev $EXT_IF1 src $EXT_IP1 table $TBL1
$IP route append $EXT_NET2 dev $EXT_IF2 src $EXT_IP2 table $TBL2
$IP route append $EXT_NET3 dev $EXT_IF3 src $EXT_IP3 table $TBL3
# Tambahkan default gateway routing table untuk ketiga ISP
$IP route append default via $EXT_GW1 table $TBL1
$IP route append default via $EXT_GW2 table $TBL2
$IP route append default via $EXT_GW3 table $TBL3
# Tambahkan table rule untuk IP dari ketiga ISP
$IP rule add from $EXT_IP1 table $TBL1
$IP rule add from $EXT_IP2 table $TBL2
$IP rule add from $EXT_IP3 table $TBL3
# Buat load balancing untuk ketiga ISP
$IP route append default scope global \
      nexthop via $EXT_GW1 dev $EXT_IF1 weight $EXT_WEIGHT1 \
      nexthop via $EXT_GW2 dev $EXT_IF2 weight $EXT_WEIGHT2 \
      nexthop via $EXT_GW3 dev $EXT_IF3 weight $EXT_WEIGHT3
# Eksekusi file /etc/rc.d/rc.chkgateway
      /usr/bin/nohup /etc/rc.d/rc.chkgateway

End of /etc/rc.d/rc.loadbalancing

Buat File: /etc/rc.d/rc.chkgateway

dengan isi sebagai berikut:

#!/bin/sh
#
# Relative weights of routes. Keep this to a low integer value.
EXT_WEIGHT1=4
EXT_WEIGHT2=2
EXT_WEIGHT3=1
GWCMD="/sbin/ip route replace default scope global"
# Conventionally 0 indicates success in this script.
# Time between checks in seconds
SLEEPTIME=10
#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
# No of repeats of success or failure before changing status
# of connection
SUCCESSREPEATCOUNT=4
FAILUREREPEATCOUNT=1
# Do not change anything below this line
# Last link status indicates the macro status of the link we
# determined. This is down initially to force routing change
# upfront. Don't change these values.
LLS1=1
LLS2=1
LLS3=1
# Last ping status. Don't change these values.
LPS1=1
LPS2=1
LPS3=1
# Current ping status. Don't change these values.
CPS1=1
CPS2=1
CPS3=1
# Change link status indicates that the link needs to be changed.
# Don't change these values.
CLS1=1
CLS2=1
CLS3=1
# Count of repeated up status or down status.
# Don't change these values.
COUNT1=0
COUNT2=0
COUNT3=0
while : ; do
  /bin/ping -W $TIMEOUT -I $EXT_IP1 -c 1 $TESTIP > /dev/null 2>&1
  RETVAL=$?
  if [ $RETVAL -ne 0 ]; then
    echo $TBL1 Down
    CPS1=1
  else
    CPS1=0
  fi
  if [ $LPS1 -ne $CPS1 ]; then
    echo Ping status changed for $TBL1 from $LPS1 to $CPS1
    COUNT1=1
  else
    if [ $LPS1 -ne $LLS1 ]; then
      COUNT1=`expr $COUNT1 + 1`
    fi
  fi
  if [[ $COUNT1 -ge $SUCCESSREPEATCOUNT || \
       ($LLS1 -eq 0 && $COUNT1 -ge $FAILUREREPEATCOUNT) ]]; then
    echo Uptime status will be changed for $TBL1 from $LLS1
    CLS1=0
    COUNT1=0
    if [ $LLS1 -eq 1 ]; then
      LLS1=0
    else
      LLS1=1
    fi
  else
    CLS1=1
  fi
  LPS1=$CPS1
  /bin/ping -W $TIMEOUT -I $EXT_IP2 -c 1 $TESTIP > /dev/null 2>&1
  RETVAL=$?
  if [ $RETVAL -ne 0 ]; then
    echo $TBL2 Down
    CPS2=1
  else
    CPS2=0
  fi
  if [ $LPS2 -ne $CPS2 ]; then
    echo Ping status changed for $TBL2 from $LPS2 to $CPS2
    COUNT2=1
  else
    if [ $LPS2 -ne $LLS2 ]; then
      COUNT2=`expr $COUNT2 + 1`
    fi
  fi
  if [[ $COUNT2 -ge $SUCCESSREPEATCOUNT || \
       ($LLS2 -eq 0 && $COUNT2 -ge $FAILUREREPEATCOUNT) ]]; then
    echo Uptime status will be changed for $TBL2 from $LLS2
    CLS2=0
    COUNT2=0
    if [ $LLS2 -eq 1 ]; then
      LLS2=0
    else
      LLS2=1
    fi
  else
    CLS2=1
  fi
  LPS2=$CPS2
  /bin/ping -W $TIMEOUT -I $EXT_IP3 -c 1 $TESTIP > /dev/null 2>&1
  RETVAL=$?
  if [ $RETVAL -ne 0 ]; then
    echo $TBL3 Down
    CPS3=1
  else
    CPS3=0
  fi
  if [ $LPS3 -ne $CPS3 ]; then
    echo Ping status changed for $TBL3 from $LPS3 to $CPS3
    COUNT3=1
  else
    if [ $LPS3 -ne $LLS3 ]; then
      COUNT3=`expr $COUNT3 + 1`
    fi
  fi
  if [[ $COUNT3 -ge $SUCCESSREPEATCOUNT || \
       ($LLS3 -eq 0 && $COUNT3 -ge $FAILUREREPEATCOUNT) ]]; then
    echo Uptime status will be changed for $TBL3 from $LLS3
    CLS3=0
    COUNT3=0
    if [ $LLS3 -eq 1 ]; then
      LLS3=0
    else
      LLS3=1
    fi
  else
    CLS3=1
  fi
  LPS3=$CPS3
  # Changeover Logic here
  if [[ $CLS1 -eq 0 || $CLS2 -eq 0 || $CLS3 -eq 0 ]]; then
    if [ $LLS1 -eq 0 ]; then
      echo Adding $TBL1
      GWCMD="$GWCMD nexthop via $EXT_GW1 dev $EXT_IF1 weight $EXT_WEIGHT1"
    fi
    if [ $LLS2 -eq 0 ]; then
      echo Adding $TBL2
      GWCMD="$GWCMD nexthop via $EXT_GW2 dev $EXT_IF2 weight $EXT_WEIGHT2"
    fi
    if [ $LLS3 -eq 0 ]; then
      echo Adding $TBL3
      GWCMD="$GWCMD nexthop via $EXT_GW3 dev $EXT_IF3 weight $EXT_WEIGHT3"
    fi
    echo "Change execute now \n $GWCMD"
    $GWCMD
    GWCMD="/sbin/ip route replace default scope global"
  fi
  sleep $SLEEPTIME
done &

End of file /etc/rc.d/rc.chkgateway

Load Balancing MX Record

Bila Mail Server di hosting di LAN maka perlu dibuat pengaturan Load Balancing untuk MX Record seperti berikut:

Record FQDN		Record_Type	Priority	Record Value
yourdomain.com		MX		10		mail.yourdomain.com
yourdomain.com		MX		10		mail.yourdomain.com
yourdomain.com		MX		10		mail.yourdomain.com
...
...
Record FQDN		Record_Type	Record Value
mail.yourdomain.com	A		10.0.0.1
			A		10.0.0.2
			A		10.0.0.3

Finish

Di Terbitkan Oleh Winston Sahusilawane Pada Rubrik Linux : 01 Mei, 2010 |