Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Red Hat This forum is for the discussion of Red Hat Linux.


  Search this Thread
Old 07-06-2009, 02:24 AM   #1
LQ Newbie
Registered: Jul 2008
Location: Mumbai
Distribution: CentOs 5
Posts: 5

Rep: Reputation: 1
Smile how to configure a linux server for networking load balancing and Data Mirroring

Hi Friendz,
Can u provide me an idea regarding network load balancing and failover can be done on linux server. Actually what i want to do is create a dedicated web-server which will process thousands of users at a time so a setting up a single server will be a bad idea, bcoz network traffic , so i want to have more than 1 server to handle it . so how can i setup multiple servers to communicate with each other share their database and if one server fails the second should take control .
Any idea's do plz forward me.
Old 07-06-2009, 04:03 AM   #2
Senior Member
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,506

Rep: Reputation: 100Reputation: 100

There are probably much more complicated ways for doing that compared to a crude and simple approach that might work using PHP:

1. Load distribution

You can setup a "dispatcher server". I. e. you can have one machine with a simple PHP script and associated database. Each time this PHP script serves a page, it can increment a counter. Then you can store a table with a list of the "actual" servers' IP addresses in that dispatcher, and all it does is increment the counter for each hit. It then redirects the incoming browser to the server IP address indicated in the list. When it reaches the end, it wraps back to the beginning. I.e. something like

For each hit
      Get target server ip according to index
      Increment index
      Redirect visitor to the server ip previously retrieved, with token
since all the dispatcher will be doing is the above, and you actually need a very simple script and database to do this, even a modest machine should be able to effieciently handle 50 or more simultaneous users, sending them off in turn to an "Actual" server.

To prevent misuse or direct hits from "outside" on servers in your server farm, you can tokenise accesses, i. e. on the dispatcher you generate a token when you "send" a vistior off to a server in the server farm. You keep this token on the dispatcher for a set time limit. Once the "target" has "received" the visitor, it checks the token back with you, and that server, if the dispatcher does hold such a token, sets up a session variable that indicates to the server that that user is a valid visitor. The MD5 of each visitor's IP, coupled with the system microtime might suffice, for example, for generting MD5 hashes to use as tokens. This is simple and of course hackable (since the session is stored userside) but for casual needs it should suffice.

If login is implied in your setup, you can load balance relatively easily - you can store user credentials on the dispatcher, and then you can logically bind a user to "his" server (where he will be in the db) and then send him to "his" server whenever he logs in. You can then for example, evenly distribute users over available servers as they register in your system. Or, you can make, for example, that all users with surnames starting with A-K are on Server #1, L-O are on Server #2, or whatever.

2. Database sharing

AFAIK MySQL does offer automatic replication and mirroring, which you can probably use in this scenario. The obvious thing is of course to have two database servers (primary and standby) and many HTTP servers, which might work in situations where you might be serving lots of HTML, but little dynamic PHP generated HTML off data based content.

Another technique may be to have each server write its database to a big-disced backup server at set intervals. You can have one backup server (dangerous, but less expensive) or a backup server per "frontline" server (safe, but expensive).

3. Backup & redundancy

Should be obvious - if a primary fails for some reason, you can just note that in your dispatcher, for example, and redirect people to the backup server. You can even pre-store backup server IPs on the dispatcher, with a flag that indicates for it so "send to primary" or "send to backup" for that server entry in its database. Then, if you have the space, you can for example setup a cronjob every 24 hours that copies the entire database to peers - i. e. each day, each server gets a complete copy of the entire dataset in the system. Note that this may be very expensive in disc space and network load, though, but gives you a very high degree of survivablity. For example, if 9 of your 10 servers fail together, you at least have, on Server #10, all 9 other databases you should have.

Actually, there are VERY many scenarious you can set up, and relatively simple logic and very simple PHP code should get you quite a long way without going very expensive and very specialised, or to dedicate hardware / router setups.
Old 07-24-2009, 12:00 PM   #3
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
You might want to take a look at:

Linux HA


The above links provide some pretty good ideas as well as software for central data storage and cluster technology that can be used in a load balanced system.


Old 07-24-2009, 12:40 PM   #4
Registered: Feb 2002
Location: Canada
Distribution: Fedora/RHEL
Posts: 152

Rep: Reputation: 31

LVS - load-balancing


balancing, between, data, load, mirroring, network, servers

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to configure Load Balancing with 2 ISPs ThanhDuongCong Linux - Networking 2 12-05-2008 05:20 PM
Load Balancing Server cocobra798 Linux - Server 1 12-04-2008 09:59 PM
Linux server load balancing and NIC bonding question. ulver Linux - Networking 1 03-06-2008 10:35 AM
mail server load balancing kanwar_rajan Linux - Networking 1 09-24-2004 05:23 AM
load balancing: mail server bswrj Linux - Networking 5 05-12-2003 05:29 AM > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 08:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration