Separate Database Server and a Web Server Cluster

Multiple web servers provide failover and can handle more traffic. The minimum number of computers needed for a cluster is two web servers. Additionally, you need a way to switch traffic between the machines. Should one of the machines stop responding, the rest of the cluster should be able to handle the load.

Load Balancing

Load balancers distribute web traffic among web servers. There are other kinds of load balancers for distributing other resources such as a hard disks and databases, but we'll cover those later. In the case of multiple web servers, load balancers allow web services to continue in the face of one web server's downtime or maintenance.

There are two broad categories of load balancers. Software load balancers are cheaper or even free but tend to have more ongoing maintenance and administrative costs than hardware load balancers. Linux Virtual Server (http://www.linuxvirtualserver.org/) is one of the most popular Linux load balancers. Hardware load balancers are expensive, since they contain more advanced server switching algorithms and tend to be more reliable than software-based solutions.

In addition to load balancing, multiple web servers introduce several complications, primarily file uploading and keeping the codebase consistent across servers.

File Uploads and Synchronization

When Drupal is run on a single web server, uploaded files are typically stored in Drupal's files directory. The location is configurable at Administer >■ Site configuration. With multiple web servers, the following scenario must be avoided:

1. A user uploads a file on web server A; the database is updated to reflect this.

2. A user views a page on web server B that references the new file. File not found!

Clearly, the answer is to make the file appear on web server B also. There are several approaches.

Using rsync

The rsync program is a utility that synchronizes two directories by copying only the files that have changed. For more information, see http://samba.anu.edu.au/rsync/. The disadvantage of this approach is the delay that synchronization incurs, as well as having duplicate copies (and thus storage costs) of all uploaded files.

■Tip If you have many files and are doing regularly scheduled rsyncs, it might make sense to do a conditional synchronization by checking the file and file_revisions tables and skipping the synchronization if they are unchanged.

Using a Shared, Mounted File System

Rather than synchronize multiple web servers, you can deploy a shared, mounted file system, which stores files in a single location on a file server. The web servers can then mount the file server using a protocol like Network File System (NFS). The advantages of this approach are that cheap additional web servers can be easily added, and resources can be concentrated in a heavy-duty file server with a redundant storage system like RAID 5. The main disadvantage to this system is that there is a single point of failure; if your server or file system mounts go down, the site is affected unless you also create a cluster of file servers.

If there are many large media files to be served, it may be best to serve these from a separate server using a lightweight web server such as LightTPD or Tux to avoid having a lot of long-running processes on your web servers contending with requests handled by Drupal. An easy way to do this is to use a rewrite rule on your web server to redirect all incoming requests for a certain file type to the static server. Here's an example rewrite rule for Apache that rewrites all requests for JPEG files:

RewriteCond %{REOUEST_URI} V(.*\.jpg)$ [NC] RewriteRule .* http://static.example.com/%1 [R]

The disadvantage of this approach is that the web servers are still performing the extra work of redirecting traffic to the file server. An improved solution is to rewrite all file URLs within Drupal, so the web servers are no longer involved in static file requests. However, there is not a simple way to effect this change within the Drupal core at this time.

Beyond a Single File System

If the amount of storage is going to exceed a single file system, chances are you'll be doing some custom coding to implement storage abstraction. One option would be to use an outsourced storage system like Amazon's S3 service. At the time of this writing, the fileapi and filesystem modules in the Drupal contributions repository were being developed for this kind of usage (see http: //drupal.org/project/fileapi and http: //drupal.org/project/filesystem).

Was this article helpful?

0 0

Responses

  • Asmait
    When should you have separate database server drupal?
    8 years ago

Post a comment