<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zedomax.com &#187; uptime</title>
	<atom:link href="http://zedomax.com/blog/tag/uptime/feed/" rel="self" type="application/rss+xml" />
	<link>http://zedomax.com/blog</link>
	<description>Zedomax - The DIY, HOWTO, Mod, Hacks, Gadgets, and Tech Blog!</description>
	<lastBuildDate>Mon, 22 Mar 2010 07:25:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Linux Web Server Hack &#8211; How to Write Automated Load Balancing Script!</title>
		<link>http://zedomax.com/blog/2008/09/23/linux-web-server-hack-how-to-write-automated-load-balancing-script/</link>
		<comments>http://zedomax.com/blog/2008/09/23/linux-web-server-hack-how-to-write-automated-load-balancing-script/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 16:15:14 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Consumer]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Educational]]></category>
		<category><![CDATA[Featured Hacks]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cron job]]></category>
		<category><![CDATA[dedicated servers]]></category>
		<category><![CDATA[dedicated-server]]></category>
		<category><![CDATA[fedora linux]]></category>
		<category><![CDATA[floating point]]></category>
		<category><![CDATA[headaches]]></category>
		<category><![CDATA[httpd server]]></category>
		<category><![CDATA[load web]]></category>
		<category><![CDATA[server load]]></category>
		<category><![CDATA[server web]]></category>
		<category><![CDATA[traffic]]></category>
		<category><![CDATA[uptime]]></category>
		<category><![CDATA[web servers]]></category>
		<category><![CDATA[web-server]]></category>
		<category><![CDATA[whatnot]]></category>

		<guid isPermaLink="false">http://zedomax.com/blog/?p=9660</guid>
		<description><![CDATA[
Well, I have been manually managing the dedicated server for this site for last 2 years or so but I found a better way to automate the server so it doesn&#8217;t ever go down due to overload.
One of the common problems in dedicated servers is the fact that load can go out of control and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://zedomax.com/blog/wp-content/uploads/2008/09/load.jpg" ><img class="size-full wp-image-9661 aligncenter" title="load" src="http://zedomax.com/blog/wp-content/uploads/2008/09/load.jpg" alt="" width="284" height="149" /></a></p>
<p>Well, I have been manually managing the dedicated server for this site for last 2 years or so but I found a <strong>better way to automate the server so it doesn&#8217;t ever go down due to overload</strong>.</p>
<p>One of the common problems in dedicated servers is the fact that load can go out of control and your web server along with it, causing you to hard-restart the server.</p>
<p>A better way to deal with this over-load problem is to shut down the HTTPD server (web server) before your server load gets to something around 2 to 5.</p>
<p>When the server load drops under 2, the script then can restart the server.</p>
<p>By doing this, you save a lot of headaches especially if you get &#8220;digged&#8221; or simply need the site up as much as possible.</p>
<p>Believe it or not, there&#8217;s no script that does this available free online so I made one for all you webmasters:</p>
<p><code><br />
#!/bin/bash<br />
loadavg=`uptime | awk '{print $9}'`<br />
RESTART="/sbin/service httpd restart"<br />
# bash doesn't understand floating point<br />
# so convert the number to an interger<br />
thisloadavg=`echo $loadavg|awk -F \. '{print $1}'`<br />
if [ "$thisloadavg" -ge "5" ]; then<br />
echo "Busy - Load Average $loadavg ($thisloadavg) "<br />
httpd -k stop<br />
elif [ "$thisloadavg" -le "2" ]; then<br />
echo "Okay - Load Average $loadavg ($thisloadavg) "<br />
pgrep httpd<br />
if [ $? -ne 0 ] # if apache not running<br />
then<br />
# restart apache<br />
$RESTART<br />
echo "restart!"<br />
else<br />
echo "no restart!"<br />
fi<br />
else<br />
echo "waiting...!"<br />
fi<br />
</code></p>
<p>Save this code somewhere such as <strong>/root/checkload.sh</strong>.</p>
<p>Then add the following to your cron job.  (<strong>/etc/cron.d/sa-update</strong> for Fedora Linux)</p>
<p><strong>*/1 * * * * root sh /root/checkloadsh</strong></p>
<p>This will run the script every 1 minute to check the load and if load is too high, web server will be turned off, if it&#8217;s lower than 2 and web server is off, it will turn the web server on.</p>
<p>There&#8217;s a lot of things that can go wrong with your web server whether from extra traffic or whatnot, but this script will be handy and I do recommend it to anyone who&#8217;s having trouble with high-load web servers that go down often. (like this blog)</p>
<p>Now, go install this script, you will never have to worry about your web server dying from high load ever again.</p>
<p>You can also change the value of &#8220;2&#8243; in the code to something higher such as 5 or 10, which will wait longer to shut the web server off if load goes high.</p>
<p>I didn&#8217;t write the code from scratch, I took 2-3 different scripts and mixed it up so here&#8217;s the resources I used for the code:</p>
<p><a target="_blank" href="http://www.liamdelahunty.com/tips/linux_load_average_check.php" >Load Average Script</a> &#8211; This one is the main skeleton I used</p>
<p><a target="_blank" href="http://bash.cyberciti.biz/web-server/restart-apache2-httpd-shell-script/" >Check/Restart HTTPD Script</a> &#8211; This one I used to check HTTPD server before trying to restart it.</p>
<p><a target="_blank" href="http://usertools.plus.net/tutorials/id/1" >Cron Task Scheduler</a> &#8211; I keep forgetting that the most left number is the minutes, darn.</p>
<p>NOTE &#8211; This is a simple solution to keep your dedicated server running on 1 server (like this one), if you can afford more servers, you will need to resort to load balancing the &#8220;servers&#8221;, load balancing here refers to balancing within 1 server.</p>
<p>Brought to you by: <a href="http://zedomax.com/blog" >Zedomax.com</a></p>
<p><a href="http://zedomax.com/blog/2008/09/23/linux-web-server-hack-how-to-write-automated-load-balancing-script/" >Linux Web Server Hack &#8211; How to Write Automated Load Balancing Script!</a></p>

	<span style="display:none"><a href="http://zedomax.com/blog/tag/apache/" title="apache" rel="tag">apache</a>, <a href="http://zedomax.com/blog/category/technology/web-technology/blog/" title="Blog" rel="tag">Blog</a>, <a href="http://zedomax.com/blog/tag/blog/" title="Blog" rel="tag">Blog</a>, <a href="http://zedomax.com/blog/category/misc/consumer-misc/" title="Consumer" rel="tag">Consumer</a>, <a href="http://zedomax.com/blog/tag/cron-job/" title="cron job" rel="tag">cron job</a>, <a href="http://zedomax.com/blog/tag/dedicated-servers/" title="dedicated servers" rel="tag">dedicated servers</a>, <a href="http://zedomax.com/blog/tag/dedicated-server/" title="dedicated-server" rel="tag">dedicated-server</a>, <a href="http://zedomax.com/blog/category/diy/" title="DIY" rel="tag">DIY</a>, <a href="http://zedomax.com/blog/category/technology/educational/" title="Educational" rel="tag">Educational</a>, <a href="http://zedomax.com/blog/category/featured/featured-hacks/" title="Featured Hacks" rel="tag">Featured Hacks</a>, <a href="http://zedomax.com/blog/tag/fedora-linux/" title="fedora linux" rel="tag">fedora linux</a>, <a href="http://zedomax.com/blog/tag/floating-point/" title="floating point" rel="tag">floating point</a>, <a href="http://zedomax.com/blog/category/diy/hack/" title="Hack" rel="tag">Hack</a>, <a href="http://zedomax.com/blog/tag/headaches/" title="headaches" rel="tag">headaches</a>, <a href="http://zedomax.com/blog/category/diy/howto/" title="HOWTO" rel="tag">HOWTO</a>, <a href="http://zedomax.com/blog/tag/httpd-server/" title="httpd server" rel="tag">httpd server</a>, <a href="http://zedomax.com/blog/tag/load-web/" title="load web" rel="tag">load web</a>, <a href="http://zedomax.com/blog/category/misc/" title="Misc" rel="tag">Misc</a>, <a href="http://zedomax.com/blog/tag/server-load/" title="server load" rel="tag">server load</a>, <a href="http://zedomax.com/blog/tag/server-web/" title="server web" rel="tag">server web</a>, <a href="http://zedomax.com/blog/tag/traffic/" title="traffic" rel="tag">traffic</a>, <a href="http://zedomax.com/blog/tag/uptime/" title="uptime" rel="tag">uptime</a>, <a href="http://zedomax.com/blog/category/technology/web-technology/" title="Web" rel="tag">Web</a>, <a href="http://zedomax.com/blog/tag/web-servers/" title="web servers" rel="tag">web servers</a>, <a href="http://zedomax.com/blog/tag/web-server/" title="web-server" rel="tag">web-server</a>, <a href="http://zedomax.com/blog/tag/whatnot/" title="whatnot" rel="tag">whatnot</a>, <a href="http://zedomax.com/blog/category/technology/web-technology/blog/wordpress/" title="Wordpress" rel="tag">Wordpress</a></span>

	<h3>Related posts</h3>
	<ul class="st-related-posts">
	<li><a href="http://zedomax.com/blog/2009/10/14/wordpress-hack-how-to-run-a-wordpress-blog-on-lighttpd/" title="Wordpress Hack &#8211; How to Run a Wordpress Blog on Lighttpd! (October 14, 2009)">Wordpress Hack &#8211; How to Run a Wordpress Blog on Lighttpd!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/10/23/zedomaxcom-updated-with-a-new-dual-quad-core-xeon-harpertown-server-from-carinet/" title="Zedomax.com Updated with a New Dual Quad-Core Xeon Harpertown Server from Cari.Net! (October 23, 2008)">Zedomax.com Updated with a New Dual Quad-Core Xeon Harpertown Server from Cari.Net!</a> </li>
	<li><a href="http://zedomax.com/blog/2007/02/22/zedomax-server-upgrade-complete/" title="Zedomax Server Upgrade Complete! (February 22, 2007)">Zedomax Server Upgrade Complete!</a> </li>
	<li><a href="http://zedomax.com/blog/2009/08/17/web-server-hack-how-to-auto-restart-httpd-service-script/" title="Web Server Hack &#8211; How To Auto Restart HTTPD service script! (August 17, 2009)">Web Server Hack &#8211; How To Auto Restart HTTPD service script!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/03/04/yahoos-version-of-digg-yahoo-buzz/" title="Yahoo&#8217;s version of Digg &#8211; Yahoo Buzz! (March 4, 2008)">Yahoo&#8217;s version of Digg &#8211; Yahoo Buzz!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/08/20/watch-videos-on-the-iphone-while-drivingreflected-off-the-dashboard-of-course/" title="Watch Videos on the iPhone while Driving!(reflected off the dashboard of course) (August 20, 2008)">Watch Videos on the iPhone while Driving!(reflected off the dashboard of course)</a> </li>
	<li><a href="http://zedomax.com/blog/2008/04/15/video-interview-at-adtech-2008-with-john-chow-18-secrets-about-blogging-and-the-internet/" title="Video Interview at AdTech 2008 with John Chow &#8211; 18 Secrets about Blogging and the Internet (April 15, 2008)">Video Interview at AdTech 2008 with John Chow &#8211; 18 Secrets about Blogging and the Internet</a> </li>
	<li><a href="http://zedomax.com/blog/2008/02/04/the-biggest-pyramid-splog-scam-in-this-world-today-stumbleupon-spambleupon/" title="The biggest pyramid &#8220;splog&#8221; scam in this world today &#8211; StumbleUpon =Spambleupon (February 4, 2008)">The biggest pyramid &#8220;splog&#8221; scam in this world today &#8211; StumbleUpon =Spambleupon</a> </li>
	<li><a href="http://zedomax.com/blog/2007/04/04/interesting-links-for-the-day/" title="Interesting Links for the day (April 4, 2007)">Interesting Links for the day</a> </li>
	<li><a href="http://zedomax.com/blog/2008/01/04/how-sitehoppin-will-virally-increase-entrecards-traffic-and-users-blogs/" title="How SiteHoppin&#8217; will virally increase Blog&#8217;s traffic and users&#8217; blogs (January 4, 2008)">How SiteHoppin&#8217; will virally increase Blog&#8217;s traffic and users&#8217; blogs</a> </li>
	<li><a href="http://zedomax.com/blog/2006/11/26/forbes-video-interview-with-digg-ceo/" title="Forbes Video Interview With Digg CEO (November 26, 2006)">Forbes Video Interview With Digg CEO</a> </li>
	<li><a href="http://zedomax.com/blog/2007/12/14/entrecard-wins-entrecard-beats-blogrush-in-alexa-reach-rankings-and-traffic/" title="EntreCard WINS &#8211; EntreCard beats BlogRush in Alexa Reach, Rankings, and Traffic! (December 14, 2007)">EntreCard WINS &#8211; EntreCard beats BlogRush in Alexa Reach, Rankings, and Traffic!</a> </li>
	<li><a href="http://zedomax.com/blog/2007/11/06/diy-server-hack-howto-fightstop-dosdenial-of-service-attacks-using-open-source-code-ddos-deflate/" title="DIY Server HACK &#8211; HOWTO fight/stop DoS(Denial of Service) Attacks using open source code (D)DoS-Deflate! (November 6, 2007)">DIY Server HACK &#8211; HOWTO fight/stop DoS(Denial of Service) Attacks using open source code (D)DoS-Deflate!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/02/24/diy-linux-hack-how-to-optimize-your-wordpress-blog-mediawiki-or-any-other-high-load-website-with-compression/" title="DIY Linux HACK &#8211; HOW TO optimize your Wordpress Blog, MediaWiki, or any other high load website with Compression! (February 24, 2008)">DIY Linux HACK &#8211; HOW TO optimize your Wordpress Blog, MediaWiki, or any other high load website with Compression!</a> </li>
	<li><a href="http://zedomax.com/blog/2007/12/19/diy-dirty-tricks-to-double-your-traffic-and-talk-trash-all-day-long/" title="DIY &#8211; Dirty Tricks to Double your Traffic and talk trash all day long (December 19, 2007)">DIY &#8211; Dirty Tricks to Double your Traffic and talk trash all day long</a> </li>
	<li><a href="http://zedomax.com/blog/2008/12/14/blog-diy-how-to-make-a-wordpress-blog-in-2-hours/" title="Blog DIY &#8211; How to Make a Wordpress Blog in 2 Hours! (December 14, 2008)">Blog DIY &#8211; How to Make a Wordpress Blog in 2 Hours!</a> </li>
	<li><a href="http://zedomax.com/blog/2006/11/02/zikiwiki-technology-wiki-for-hackers-diyers-mcu-users-plc-users-etc/" title="ZikiWiki &#8211; Technology wiki for hackers, diyers, mcu users, plc users, etc&#8230; (November 2, 2006)">ZikiWiki &#8211; Technology wiki for hackers, diyers, mcu users, plc users, etc&#8230;</a> </li>
	<li><a href="http://zedomax.com/blog/2007/12/08/zedomaxnet-web-traffic-services-buy-300-to-500-visitors-of-web-traffic-from-us/" title="Zedomax.Net Web Traffic Services &#8211; Buy 300 to 500 visitors of Web Traffic from Us! (December 8, 2007)">Zedomax.Net Web Traffic Services &#8211; Buy 300 to 500 visitors of Web Traffic from Us!</a> </li>
	<li><a href="http://zedomax.com/blog/2007/09/08/zedomaxnet-logo/" title="Zedomax.Net Logo (September 8, 2007)">Zedomax.Net Logo</a> </li>
	<li><a href="http://zedomax.com/blog/2008/12/17/zedomaxcom-google-friendconnect/" title="Zedomax.com Google FriendConnect! (December 17, 2008)">Zedomax.com Google FriendConnect!</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://zedomax.com/blog/2008/09/23/linux-web-server-hack-how-to-write-automated-load-balancing-script/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
