Dec 24, 2008

Network Failover

Failover is the process of switching to a backup component, element, or operation while recovery from a disruption is undertaken. Failover procedures determine the continuity of a network operation. Failover mechanisms can be devised so that they take place immediately or shortly after a disruption occurs. Many systems use automatic failover and data replication for instant recovery. Preemptive failover can also be used if an imminent disruption is detected.Failover requires the availability of a backup system to eventually take overservice. The type of failover model required dictates the backup state of readiness(Figure 2.2). There are three basic types of failover model. Each has implications onthe amount of information that must be available to the backup system at the time of failover:
• Hot or immediate failover requires a running duplicate of the production system as a backup to provide immediate recovery. Consequently, it is the more complex end expensive to implement. The backup system, referred to as a hot standby, must constantly be updated with current state information about the activity of the primary system, so that it is ready to take over operation quickly when needed. This is why this type of failover is sometimes referred to as a
stateful failover. Applications residing on the backup system must be designed to use this state information when activated. For these reasons, hot standby systems are often identical to the primary system. They are sometimes designed to load share with the primary system, processing a portion of the live traffic.
• Cold failover, on the other hand, is the least complex to implement but likely results in some disruption until the backup is able to initiate service. A cold standby backup element will maintain no information about the state of the primary system and must begin processing as if it were a new system. The backup must be initialized upon failover, consuming additional time. For these reasons, a cold failover model is usually the least expensive to implement.
• Warm failover uses a backup system that is not provided with state information on the primary system until a failover takes place. Although the backup may already be initialized, configuration of the backup with the information may be required, adding time to the failover process. In some variants of this model, the standby can perform other types of tasks until it is required to take over the primary system’s responsibilities. This model is less expensive than
the hot standby model because it reduces standby costs and may not necessarily require a backup system identical to the primary system

Dec 3, 2008

Checking Load of server in Frequent intervals

One of the major problem in linux server is rising of load to high. This can be happened due to various reason. This script will check the load of machine in frequent intervals and inform the administrator through email. This will also send the current server status.

#mkdir -p /opt/scripts
#cd /opt/scripts
#chmod 755

Copy paste the following into the

SUBJECT="Alert $(hostname) load average is $L05"
echo "Load average Crossed allowed limit." >> $TEMPFILE
echo "Hostname: $(hostname)" >> $TEMPFILE
echo "Local Date & Time : $(date)" >> $TEMPFILE
echo "| Uptime status: |" >> $TEMPFILE
echo "-----------------------------------------------------" >> $TEMPFILE
/usr/bin/uptime >> $TEMPFILE
echo "-----------------------------------------------------" >> $TEMPFILE
echo "| Top 20 CPU consuming processes: |" >> $TEMPFILE
ps aux | head -1 >> $TEMPFILE
ps aux --no-headers | sort -rn | head -20 >> $TEMPFILE
echo "| Top 10 memory-consuming processes: |" >> $TEMPFILE
ps aux --no-headers| sort -rn | head >> $TEMPFILE
echo "----------------------------------------------------" >> $TEMPFILE
echo "| Memory and Swap status: |" >> $TEMPFILE
/usr/bin/free -m >> $TEMPFILE
echo "----------------------------------------------------" >> $TEMPFILE
echo "| Active network connection: |" >> $TEMPFILE
echo "----------------------------------------------------" >> $TEMPFILE
/bin/netstat -tnup | grep ESTA >> $TEMPFILE
echo "----------------------------------------------------" >> $TEMPFILE
echo "| Disk Space information: |" >> $TEMPFILE
echo "----------------------------------------------------" >> $TEMPFILE
/bin/df -h >> $TEMPFILE
echo "-----------------THE END----------------------------" >> $TEMPFILE

#Store the Current Load into a variable
L05="$(uptime|awk '{print $(NF-2)}'|cut -d. -f1)"

#Checking whether it goes beyond the limit

if test $L05 -gt 0
mail -s "$SUBJECT $L05" "$EMAIL" < $TEMPFILE fi #Remove the Temporary file.

Create CronJob for this
#vi /etc/crontab
#The following script will run in every minute.
*/1 * * * * root /opt/scripts/

Dec 1, 2008

Block Bad Bots using htaccess

Bots are software applications that run automated tasks over the Internet. But there is some bad bots which will run on your web root and pass your information to outside public. This should be prevented. In this article I am stating how to search for a bad bot and prevent it.

Enable the htaccess as described in the previous post

Open the htaccess

vi .htaccess

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^BadBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^EvilScraper [OR]
RewriteCond %{HTTP_USER_AGENT} ^FakeUser
RewriteRule ^(.*)$ http://go.away/

Save and exit
So, what does this code do? It's simple: the above lines tell your webserver to check for any bot whose user-agent string starts with "BadBot". When it sees a bot that matches, it redirects them to a non-existent site called "go.away". And
also it will check for 3 types of bots and if found one among them the control will be directed to some site.

Prevent access from an IP address using .htaccess

htaccess is a powerful tool is used to manipulated the webroot and apache configurations as well. The Rewrite rules can be written in .htaccess file. .htaccess file normally located in the webroot.

#Open the Apache configuration file.

vi /etc/httpd/conf/httpd.conf (Redhat Based,Centos Distros)
vi /etc/apache2/apache2.conf (Debian Based,Ubuntu Distros)

# Uncomment the Following Line

LoadModule rewrite_module modules/

we need to change the AllowOverride directive also from

Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all


Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all

Perfect !!! You have enabled the .htaccess support in your apache webserver.

Now go to your webroot. Normally its /var/www/html/ Create an htaccess file

touch .htaccess

vi .htaccess

Copy paste the following in to .htaccess file

order allow,deny
deny from
deny from 012.34.5.
allow from all

Save And Exit

Viola !!! You have blocked the above IPs from watching your site. Same like you can restrict an IP range also. Do the following if you would like to block a range

order allow,deny
deny from 123.45.6
deny from 012.34.
allow from all

You can block an ISP through the above method. Changes will look like following

order allow,deny
deny from
deny from
allow from all

The above will all traffic from the specified Internet Service Providers IPs