Linux Scripting
Linux Scripting
Hy all...I am new to scripting...i need a linux script that will do both Load Balancing and Fail over for my network....I am running CentOS on my server and i have two DSL modems....Please help...!!
Regards
Abdulrehman
Regards
Abdulrehman
Regards
Abdulrehman
Abdulrehman
-
- Site Admin
- Posts: 5132
- Joined: Fri May 02, 2003 10:24 am
- Location: Karachi
- Contact:
Re: Linux Scripting
Dear mejam,
Salam,
Best Regards.
Salam,
FYI, http://lnlb.sourceforge.net and http://blog.taragana.com/index.php/arch ... -on-linux/mejam wrote:Hy all...I am new to scripting...i need a linux script that will do both Load Balancing and Fail over for my network....I am running CentOS on my server and i have two DSL modems....Please help...!!
Best Regards.
Farrukh Ahmed
please share your script so that others can use it.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
This scrip it for load balancing only.....mentioned link will guide about fail over
http://blog.taragana.com/index.php/arch ... -on-linux/
======================================================================
#!/bin/bash
#
# bal_local Load-balance internet connection over two local links
#
# Author: Abdulrehman <arvagabond5@gmail.com>
#
# Set devices:
DEV1=${1-eth0} # default eth0
DEV2=${2-eth1} # default eth1
# Get IP addresses of our devices:
ip1=`ifconfig $DEV1 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`
ip2=`ifconfig $DEV2 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`
# Get default gateway for our devices:
gw1=`route -n | grep $DEV1 | grep '^0.0.0.0' | awk '{ print $2 }'`
gw2=`route -n | grep $DEV2 | grep '^0.0.0.0' | awk '{ print $2 }'`
echo "$DEV1: IP=$ip1 GW=$gw1"
echo "$DEV2: IP=$ip2 GW=$gw2"
### Definition of routes ###
# Check if tables exists, if not -> create them:
if [ -z "`cat /etc/iproute2/rt_tables | grep '^251'`" ] ; then
echo "251 rt_dev1" >> /etc/iproute2/rt_tables
fi
if [ -z "`cat /etc/iproute2/rt_tables | grep '^252'`" ] ; then
echo "252 rt_dev2" >> /etc/iproute2/rt_tables
fi
# Define routing tables:
ip route add default via $gw1 table rt_dev1
ip route add default via $gw2 table rt_dev2
# Create rules:
ip rule add from $ip1 table rt_dev1
ip rule add from $ip2 table rt_dev2
# If we already have a 'nexthop' route, delete it:
if [ ! -z "`ip route show table main | grep 'nexthop'`" ] ; then
ip route del default scope global
fi
# Balance links based on routes:
ip route add default scope global nexthop via $gw1 dev $DEV1 weight 1 nexthop via $gw2 dev $DEV2 weight 1
# Flush cache table:
ip route flush cache
# All done...
=======================================================================
http://blog.taragana.com/index.php/arch ... -on-linux/
======================================================================
#!/bin/bash
#
# bal_local Load-balance internet connection over two local links
#
# Author: Abdulrehman <arvagabond5@gmail.com>
#
# Set devices:
DEV1=${1-eth0} # default eth0
DEV2=${2-eth1} # default eth1
# Get IP addresses of our devices:
ip1=`ifconfig $DEV1 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`
ip2=`ifconfig $DEV2 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`
# Get default gateway for our devices:
gw1=`route -n | grep $DEV1 | grep '^0.0.0.0' | awk '{ print $2 }'`
gw2=`route -n | grep $DEV2 | grep '^0.0.0.0' | awk '{ print $2 }'`
echo "$DEV1: IP=$ip1 GW=$gw1"
echo "$DEV2: IP=$ip2 GW=$gw2"
### Definition of routes ###
# Check if tables exists, if not -> create them:
if [ -z "`cat /etc/iproute2/rt_tables | grep '^251'`" ] ; then
echo "251 rt_dev1" >> /etc/iproute2/rt_tables
fi
if [ -z "`cat /etc/iproute2/rt_tables | grep '^252'`" ] ; then
echo "252 rt_dev2" >> /etc/iproute2/rt_tables
fi
# Define routing tables:
ip route add default via $gw1 table rt_dev1
ip route add default via $gw2 table rt_dev2
# Create rules:
ip rule add from $ip1 table rt_dev1
ip rule add from $ip2 table rt_dev2
# If we already have a 'nexthop' route, delete it:
if [ ! -z "`ip route show table main | grep 'nexthop'`" ] ; then
ip route del default scope global
fi
# Balance links based on routes:
ip route add default scope global nexthop via $gw1 dev $DEV1 weight 1 nexthop via $gw2 dev $DEV2 weight 1
# Flush cache table:
ip route flush cache
# All done...
=======================================================================
Regards
Abdulrehman
Abdulrehman
Are u the author of this script? its great, tell us what problem come so u not able to use initially and how u resolve that.mejam wrote:This scrip it for load balancing only.....mentioned link will guide about fail over
http://blog.taragana.com/index.php/arch ... -on-linux/
======================================================================
#!/bin/bash
#
# bal_local Load-balance internet connection over two local links
#
# Author: Abdulrehman <arvagabond5@gmail.com>
#
=======================================================================
Thanks,
Noman Liaquat
why is it strange?
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?