hinst.net

Random infrequently updated miscellaneous Linux stuff

  • Increase font size
  • Default font size
  • Decrease font size

Building Simple Load-Balancing Apache Clusters Using Round Robin DNS and NFS

E-mail Print PDF

One of the great advantages of Linux is its ability to run happily on yesterday's hardware, unlike some other resource-hogging operating systems we all love to hate. Finding a server to run a basic Linux/Apache setup is often as easy as looking around for whatever unused old computer you have laying around. Many a system administrator still contentedly churns out web content on her old Pentium 166 from 1997. Sometimes, however, if you're lucky, your web site will generate enough traffic that it will outgrow such a setup. When apache begins to consistently cause excessive system loads, it's time to think about an upgrade. But never fear - you needn't break the bank for enhanced performance. With just a little more elbow grease, you can set up a small cluster, easily capable of meeting your increased demands.

One of the great advantages of Linux is its ability to run happily on yesterday's hardware, unlike some other resource-hogging operating systems we all love to hate. Finding a server to run a basic Linux/Apache setup is often as easy as looking around for whatever unused old computer you have laying around. Many a system administrator still contentedly churns out web content on her old Pentium 166 from 1997. Sometimes, however, if you're lucky, your web site will generate enough traffic that it will outgrow such a setup. When apache begins to consistently cause excessive system loads, it's time to think about an upgrade. But never fear - you needn't break the bank for enhanced performance. With just a little more elbow grease, you can set up a small cluster, easily capable of meeting your increased demands.

 

One of the beautiful things about a load-balanced cluster is the way in which it scales. When your old P-166 isn't doing the job anymore, add another P-166. When 2 ain't good enough, add a third. It might go against everything you've learned, but when it comes to clusters, it's quantity - not quality. And the great thing is, not only does it work, it works really, really well. This is why Google runs on warehouses full of old PC's rather than one super huge supercomputer.

Overview


Let's get down to the details of how it works. In a traditional (non-clustering) server setup, the web files reside on a single server that serves them up as requested. Simple. In a clustering setup, a web request will direct a client to one of multiple web servers, called nodes.  Each and every one of these nodes needs to have access to a copy of the web files. One way to accomplish this would be to put a duplicate copy of your web files on every computer. A better way, however, would be to have all the files reside on one server (either one of the cluster nodes or, preferably, another server designated as a file server). Each of the nodes can then use NFS to mount the directory containing the web files. This eliminates the needs to maintain multiple copies of all of your web files. 

Because the web requests are spread out over n servers, each server will only be handling 1/n as many requests, which results in less resource usage and a happier server. Another benefit is that if one node is, say, obliterated in a fiery explosion, you simply take its IP address out of the Round Robin DNS, and you're none the worse for wear. You're simply operating with n-1 nodes now, with no effect on the content being served.

Setting up Round-Robin DNS


There are numerous mechanisms for distributing web requests to multiple nodes instead of a single, standalone server. One of the simplest is Round Robin DNS. Normally, when you resolve a domain name, it will resolve to a single IP address. With Round Robin DNS, you make a domain name resolve to two or more IP addresses. The DNS server takes turns sending out each address, so that (in theory), every address will receive an equal amount of requests.

If you're already using BIND (http://www.isc.org/index.pl?/sw/bind/) for DNS for your single-server setup, a Round-Robin setup is easy to configure. You should have an A record that looks something like this:

www.website.com A 172.30.28.101

In order to create a Round-Robin configuration, simple create multiple A
records for the same domain name, like so:

www.website.com A 172.30.28.101

www.website.com A 172.30.28.102

www.website.com A 172.30.28.103


In the above example, 172.30.28.101, 172.30.28.102, and 172.30.28.103 are our 3 cluster nodes. The DNS server will take turns resolving www.website.com to each of the 3. If every DNS lookup resulted in an HTTP request, this would ensure that each of the 3 nodes received an equal number of HTTP requests, thus equally balancing the load of HTTP traffic.  In reality this isn't the case, but Round-Robin DNS still does a reasonably good of distributing traffic - and for it's ease-of-use, it's a popular method of achieving a cluster.

Sharing Web Files Using NFS


As we said earlier, we're going to want to share our web files among all of the nodes in our cluster. Like everything in Linux, the way we can accomplish this are countless. I like NFS because it's easy to set up and does a good job. Before going any futher, you must make sure that your kernel was compiled with support for NFS (compiling it as a module is fine). Next, using your favorite package manager install the NFS server utilities and portmapper software on your file server (or on one of the nodes itself, if you're short on servers). Once these are running, sharing a directory is trivial. All you have to do is create a one-line entry in /etc/exports, and then restart the NFS server. You can read the man page for details on all the options, but here's a typical entry:

/var/shared_www 172.30.28.0/24(rw,sync)

This will allow any host on the 172.30.28.0/24 network to mount this shared directory. The rw option allows clients to have read-write access (as opposed to read-only), and the sync option forces the nfs server to wait until changes have been committed to the disk before responding to reqeusts for the data. This affects performance slightly (but probably unnoticeably), and spares us the risk of data loss and/or corruption in the event of a crash.

For the purpose of this example, let's assume that the NFS server from the above example resides at 172.30.28.104 and we want the shared web directory to be located at /mnt/nfs/shared_www. In order to mount this shared file system, simply install portmapper and the NFS client on each node computer and type the following command:

mount 172.30.28.4:/var/shared_www /mnt/nfs/shared_www

That's all there is to it. If you want to make the change permanent upon reboot, add an entry to /etc/fstabthat looks like this:

172.30.27.4:/var/shared_www /mnt/nfs/shared_www nfs defaults 0 0

Next time you boot, it will automatically get mounted.

Apache Setup


Lastly, you'll need to install and configure apache. This is easy because it's basically identical to setting up apache for a single server, you just need to do it on each node computer. Using all of the exampl information from above, the VirtualHost entry for our web site might look as follows on one of our node servers:

ServerAlias www.website.com

DocumentRoot /mnt/nfs/shared_www

Other Concerns


If your web site uses other data sources for storing information, such as a database or PHP sessions, you'll need to set up a way for each node server to share the information. For a database, this is easy - simply set all of the nodes to connect to the same database server and use the same database (assuming the database solution you're using is a multi-user server solution like MySQL or PostgreSQL).

Sharing PHP sessions are a little more work, but nothing we haven't already covered above. All you need to do is set up another NFS share for the directory where PHP stores session files. I would recommend changing this from /tmp to somewhere else before you do this. There's no reason for all of the cluster nodes to share everything in their /tmp directories.  You can change this with the session.save_path option in your php.ini file (http://us3.php.net/manual/en/ref.session.php#ini.session.save-path). Then just use the techniques mentioned above to create an NFS share for this directory, and mount it on each of the cluster nodes.

Comments

avatar Beatrice
0
 
 
Hi. Hollywood is a place where they place you under contract instead of under observation. Help me! There is an urgent need for sites: Topamax as weight loss drug. I found only this - topamax depression. J postgrad med, online version this peer reviewed periodical, a publication of the staff society of seth I was given the lamisil prescription cause some of my fingerails are discolored, that would be my guess because lamisil is just an anti fungal, and I don think. With best wishes :cool:, Beatrice from Arab.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Chip
0
 
 
Good afternoon. Depend not on another, but lean instead on thyself...True happiness is born of self-reliance.
I am from Pakistan and now teach English, give true I wrote the following sentence: "Now she is pregnant, and her progesterone level at weeks is just around."

With respect :-), Chip.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Ackerley
0
 
 
Salut! Informative, good design, well done!.
I am from Kyrgyzstan and , too, and now am writing in English, give please true I wrote the following sentence: "Buy progesterone online don buy progesterone online help for any this time when you heart and other is an everyday user getting him involved would be very."

Thank you very much ;-). Ackerley.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Julianne
0
 
 
Hi everyone. The people who are regarded as moral luminaries are those who forego ordinary pleasures themselves and find compensation in interfering with the pleasures of others.
I am from Macedonia and learning to read in English, give true I wrote the following sentence: "Timeline gant chart, sweden includes released yet, although it takes in some classic enormous shorts with nato and some due children, in score to spacious project with single special things in the verse of night city and part bombing."

With love :P, Julianne.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Isleta
0
 
 
How are you. Keep cool and you command everybody.
I am from Emirates and learning to speak English, tell me right I wrote the following sentence: "Scangroup, proposed the first consumption assets portfolio in africa to intend lead through an board."

With love :D, Isleta.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Investment advice jamaica
0
 
 
How are you doing.
I am from Guinea and also now'm speaking English, tell me right I wrote the following sentence: "As wife, byrnes however explained 0 demand, advice for investment."

Thank you so much for your future answers :p. Investment advice jamaica.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Haidee
0
 
 
How are you. It really doesn't matter if the person who hurt you deserves to be forgiven. Forgiveness is a gift you give yourself. You have things to do and you want to move on. Help me! Please help find sites for: Topamax class of medications. I found only this - topamax paralysis. In our pharmacy shop you can purchase viagra, cialis, levitra. Your information about lamisil tablets. With best wishes :o, Haidee from Slovenia.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Samuel
0
 
 
It is great! One more advantage of Linux. I've fell in love with it since I watched a documentary about its creating and learned to use it (though at first it was not easy at all untill I found some books about it at the book search engine http://pdf.rapid4me.com ). I admire their goals. And it is a good thing that Linux can show it's capable of deliver the support of a New Big Thing before the launch of it.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar AngelicaJones
0
 
 
I'mjust bowsing net and I see this site, I appreciate this article...Just keep posting... thanks and If you have not seen he freelance writing jobs... You should ty i now....
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Hmm great article! Keep up the good work! :)
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
I've checked the links, they're really great!! Thanks for this post!!
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Nice post. Really effective tips.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Linux has really a great advantage. Is there other way on Sharing Web Files Using NFS?
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar verified
0
 
 
Round Robin is not so efficient balance method, HAProxy http://haproxy.1wt.eu/ is a better method.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Susan
0
 
 
I agree with "verified" HAProxy is better i use it here http://www.realtorrentz.com and works perfectly.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Thanks for this post. I learned a lot from this article.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar Andy
0
 
 
Thanks for this post

0---------------
Forex - http://www.kenblueswell.com/
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar ferroli
0
 
 
thanks nice post http://volkswagenservi sin.com volkswagen servisi http://ferroliservisin.com ferroli kombi klima servisi http://ecaservisin.com eca servisi http://baymakservisin.com baymak klima servisi http://tesisatyikama.org tesisay yıkama ve temizleme http://cembant.com.tr çeber makinesi http://kesermakina.com plastik şişirme makinası http://perdetemizlet.com perde temizleme ve yıkama http://epilasyonmerkez i.org epilasyon merkezi http://gaggenauservisi n.com gaggenau servisi http://frigidaireservi sin.com frigidaire servisi http://generalelectric servisin.com general electric servisi http://mitsubishiklima servis.org mitsubishi klima http://bekoklimaservis.org beko klima servis http://arcelikklimaser vis.org arçelik klima servis http://fujitsuklimaser visi.org fujitsu klima servisi http://baymakklimaserv isi.org baymak klima servisi http://kadikoyvaillant servisi.net kadıköy vaillant servisi http://mecidiyekoybosc hservisi.com mecidiyeköy bosch servisi http://avcilarboschser visi.com bosch servisi http://besiktasboschse rvisi.net beşiktaş bosch servisi http://gungorenboschse rvisi.com güngören bosch servisi http://sefakoyarceliks ervisi.com sefaköy arçelik servisi http://ikitelliarcelik servisi.net ikitelli arçelik servisi http://klimaservisin.com klima servisi http://vaillantservisi.tk vaillant servisi http://buyukcekmecebek oservisi.com büyükçekmece beko servisi http://eyupboshservisi.com eyüp bosch servisi http://bakirkoyvestels ervisi.com bakırköy vestel servisi http://alaskaklimaserv isi.org alaska klima servisi http://altusklimaservi si.net altus klima servisi http://sariyervaillant servisi.net sarıyer vaillant servisi
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar 123bee
0
 
 
Flowers are the best way to express anyone’s feeling. People usually give away flowers along with a gift. People are always ready to spread happiness as they always find reasons to celebrate with one another.

Flowers Online
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar 123bee
0
 
 
Flowers are the best way to express anyone’s feeling. People usually give away flowers along with a gift. People are always ready to spread happiness as they always find reasons to celebrate with one another.

Flowers Online - http://www.416-florist.com
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar tercih
0
 
 
http://tercihotomotiv.com.tr/seat-acil-yol-y ardim-servisi/
http://tercihotomotiv.com.tr/skoda-mekanik-s ervisi/
http://tercihotomotiv.com.tr/volkswagen-meka nik-servisi/
http://tercihotomotiv.com.tr/audi-mekanik-se rvisi/
http://tercihotomotiv.com.tr/seat-otomatik-s anziman-servisi/
http://tercihotomotiv.com.tr/audi-bakim-serv isi/
http://tercihotomotiv.com.tr/skoda-sanziman- servisi/
http://tercihotomotiv.com.tr/volkswagen-tran sporter-servisi/
http://tercihotomotiv.com.tr/volkswagen-craf ter-servisi/
http://tercihotomotiv.com.tr/seat-kaporta-se rvisi/
http://tercihotomotiv.com.tr/audi-otomatik-s anziman-servisi/
http://tercihotomotiv.com.tr/audi-boya-servi si/
http://tercihotomotiv.com.tr/audi-sanziman-s ervisi/
http://tercihotomotiv.com.tr/audi-kaporta-se rvisi/
http://tercihotomotiv.com.tr/volkswagen-sanz iman-servisi/
http://tercihotomotiv.com.tr/volkswagen-moto r-servisi/
http://tercihotomotiv.com.tr/volkswagen-kapo rta-servisi/
http://tercihotomotiv.com.tr/volkswagen-kapo rta-servisi/
http://tercihotomotiv.com.tr/volkswagen-cara velle-servisi/
http://tercihotomotiv.com.tr/volkswagen-pass at-servisi/
http://tercihotomotiv.com.tr/volkswagen-cadd y-servisi/
http://tercihotomotiv.com.tr/skoda-fabia-ser visi/
http://tercihotomotiv.com.tr/seat-leon-servi si/
http://tercihotomotiv.com.tr/audi-a3-servisi/
http://tercihotomotiv.com.tr/volkswagen-golf -servisi/
http://tercihotomotiv.com.tr/audi-ozel-servi s/
http://tercihotomotiv.com.tr/seat-mekanik-se rvisi/
http://tercihotomotiv.com.tr/volkswagen-ozel -servis/
http://tercihotomotiv.com.tr/skoda-ozel-serv is/
http://tercihotomotiv.com.tr/seat-ozel-servi s/
http://tercihotomotiv.com.tr/volkswagen-acil -yol-yardim-ser visi/
http://tercihotomotiv.com.tr/skoda-acil-yol- yardim-servisi/
http://tercihotomotiv.com.tr/audi-acil-yol-y ardim-servisi/
http://tercihotomotiv.com.tr/volkswagen-baki m-servisi/
http://tercihotomotiv.com.tr/skoda-bakim-ser visi/
http://tercihotomotiv.com.tr/seat-bakim-serv isi/
http://tercihotomotiv.com.tr/category/audi-servisi/
http://tercihotomotiv.com.tr/category/seat-servisi/
http://tercihotomotiv.com.tr/category/skoda-servisi/
http://tercihotomotiv.com.tr/category/volkswagen-serv isi/
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar klima servisi
0
 
 
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar mitsubishi klima
0
 
 
http://www.mitsubishiklima lar.com

Türkiye de yetkili mitsubishi satış ve servis merkezi resmi satış sitesi
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
avatar eaman
0
 
 
Well I would recommend a post about comment-spammin g,
nice post by the way.
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Last Updated on Friday, 10 July 2009 13:29  
Banner

Main Menu


search