Building Scalable Web Cluster using LVS

Jump to: navigation, search


Web cluster is a cluster system of more than one computer to provide HTTP and HTTPS service (also called web server farm). Clustering is the best approach to achieve the scalability, availability and reliability of web services.

Web cluster with many inexpensive commodity servers can easily handle large volumes of web requests, without creating unwanted delays. The number of servers can be added as workload is increasing.


The general architecture of LVS-based web cluster is illustrated in the following figure.


The architecture has three ties:

  • Load balancer, which usually use IP load balancing technologies for higher system throughput
  • Web server pool, which actually perform HTTP and/or HTTPS services
  • Shared storage, which can be database, network file system, distributed file system, or the hybrid ones.

For dynamic web pages (such as PHP, JSP and ASP pages), data that is accessed by dynamic pages usually is stored in database system. The database service is running at stand-alone server, and is shared by all the web servers. No matter if multiple dynamic pages from a web server or different web servers access the same data, database engines provide atomicity and locking facility to serialize data access, so that it is easier to guarantee data consistency.

The static files, such as HTML, graphics, and dynamic page scripts file, can be stored in network file system (NFS or CIFS) or distributed file system. Whether to choose network file system and distributed file system, it depends on system scale and the loading of file access. Through shared network file system and distributed file system, webmaster can see a single image of file storage space, so that it is easier to maintain those files, and any updates is effective for all the web servers.

In this architecture of shared storage, system administrators can easily add new web servers to handle increasing load of web access, and do not need to copy the contents to local disks of new web servers.

Most web sites may use HTTP cookie, which is to store cookie in client browser and send cookie to web server to track sessions from different HTTP request from the same browser. Once HTTP cookie is used, all the requests from a client must be sent to the same web server if web servers don't know their generated cookie sessions one another.

Some web sites may use HTTPS protocol, which is to transfer HTTP over SSL (Secure Socket Layer) connection. When a SSL connection is made to port 443 for secure web service, a key for the connection must be chosen and exchanged. Since it is time consuming to negociate and generate the SSL key, the successive connections from the same client can also be granted by the server in the life span of the SSL key. Therefore, all the HTTPS requests from a client must be sent to the same server in the life span of the SSL key.

Upon these connection affinity requirements, IPVS load balancer provides the persistent service feature, which is to send all the successive requests from the same client IP address to the same server in the specified time. The persistent service feature can help solve the connection affinity problem between client and server.

Configuration Example

In the configuration example, we will have a LVS/NAT cluster of three web servers. The virtual IP address of load balancer is, and gateway ip address for internal web servers is The ip addresses of three web servers are, and respectively. The web servers can run apache or other web server programs.

We use the following ipvsadm commands to setup IPVS rules:

ipvsadm -A -t -s wlc
ipvsadm -a -t -r -m -w 100
ipvsadm -a -t -r -m -w 100
ipvsadm -a -t -r -m -w 100

Then, use any computer outside the internal network ( to access, and see whether it works or not. "ipvsadm -Ln" can be used to list the IPVS table, and "ipvsadm -Lcn" can be used to list the IPVS connections.

Once the basic cluster configuration works, we can consider to use cluster management software to add reliability and availability into the web cluster system.


It's easier to build web cluster using LVS and add scalability and availability into the web system.


LVS.png "Building Scalable Web Cluster using LVS" is an LVS Example related stub. You can help LVSKB by expanding it