LVS Implementation and Configuration Guide

Introduction to LVS

LVS (Linux Virtual Server) is an open-source load balancing solution integrated into the Linux kernel. It enables the distribution of network traffic across multiple servers to create high-performance, highly available server clusters.

Key advantages of LVS include:

  • Operating at the network layer for optimal performance
  • Cost-effectiveness through combining multiple lower-performance servers
  • Simple configuration with multiple load balancing algorithms
  • High reliability with automatic failure handling
  • Excellent scalability for growing infrastructure needs

Installation and Setup

For Linux kernels 2.4 and above, LVS support is built-in. The only additional requirement is the management utility:

yum install ipvsadm

IPVSADM Command Usage

LVS architecture consists of two mainn components:

  • IPVS kernel module handling core functionality
  • IPVSADM user-space tool for cluster service configuration

The command structure resembles iptables, making it familiar to system administrators.

LVS Operating Modes

NAT Mode (Network Address Translation)

This mode employs network address translation for load distribution:

Client Request: CIP → VIP
Director modifies: CIP → RIP (Real Server IP)
Response: RIP → Director → VIP → CIP

Performance Consideration: Both request and response traffic pass through the Director, which can become a bottleneck with 10-20 real servers.

DR Mode (Direct Routing)

Direct Routing improves performance by having responses bypass the Director:

Client Request: CIP → VIP (via Director)
Director forwards to Real Server using MAC address modification
Response: VIP → CIP (direct from Real Server)

Configuration Methods for DR Mode:

Method 1: Router Configuration
Statically bind VIP to Director's MAC address at the router level.

Method 2: ARP Tables
Use arptables on real servers to prevent VIP advertisement.

Method 3: Kernel Parameters
Configure arp_ignore and arp_announce parameters:

# arp_ignore configuration options
0: Respond to any local configured address
1: Respond only if target matches receiving interface
2: Respond only to matching subnet requests
8: No response to all ARP queries

# arp_announce configuration options  
0: Advertise all local addresses
1: Advertise only network-matched addresses
2: Advertise only interface-matched addresses

TUN Mode (IP Tunneling)

Tunnel mode encapsulates packets for geographically distributed servers:

Original: CIP → VIP
Encapsulated: DIP → RIP (with original packet inside)
Real Server decapsulates and processes request

Advantages: Director handles only requests, enabling massive scalability.

Requirements: All servers must support IP tunneling protocol.

Health Monitoring

LVS Director doesn't include built-in health checking. System administrators must implement custom scripts to monitor real server status and automatically remove unhealthy nodes from the cluster.

Tags: LVS LoadBalancing IPVS LinuxKernel ServerCluster

Posted on Thu, 14 May 2026 08:36:08 +0000 by k0z