Step‑by‑Step Guide to Configuring an LVS Load Balancer with Direct Routing
This tutorial walks you through installing LVS on a Red Hat server, configuring the router, setting up virtual and real servers, adjusting ARP tables, and validating the cluster with ipvsadm, curl, and Tsung performance testing, all while ensuring high‑throughput static web delivery.
The article assumes you have already optimized the server and network stack and used iperf and netperf to verify support for 500,000 requests per second of static web pages.
It then guides you through installing and configuring an LVS router for a web‑server cluster.
LVS Router Configuration
Install the LVS software on the router:
yum groupinstall "Load Balancer" chkconfig piranha-gui on chkconfig pulse on
Set the web‑admin password:
/usr/sbin/piranha-passwd
Open the required port in iptables:
vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3636 -j ACCEPT
Start the web management service (wait until Piranha configuration finishes before starting pulse):
service piranha-gui start
Enable IP forwarding:
vim /etc/sysctl.conf net.ipv4.ip_forward = 1 sysctl -p /etc/sysctl.conf
Start the web server (nginx example):
service nginx start
Direct Routing Mode Setup
Log in to the Piranha web UI on the LVS router.
In the GLOBAL SETTINGS page, the default mode is Direct Routing; configure the virtual IP (VIP) for the LVS web cluster.
In the VIRTUAL SERVERS tab, create a virtual web server that represents the whole cluster.
Click ADD then EDIT .
Assign a VIP and bind it to a device interface, then click ACCEPT to save.
Proceed to the REAL SERVER page to add the actual HTTP servers:
Use ADD to list each real server, EDIT for details, then ACCEPT to save.
After configuring all real servers, activate them by clicking (DE)ACTIVATE for each.
Activate the virtual server as well:
Start the pulse service on each real server:
service pulse start
Verify the cluster is running with:
# ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.122.10:http wlc -> 192.168.122.1:http Route 1 0 0 -> 192.168.122.2:http Route 1 0 0 -> 192.168.122.3:http Route 1 0 0
Configuring Each Real Server (Direct Routing)
Assign the same VIP on each real server (e.g., eth0:1):
ip addr add 192.168.12.10 dev eth0:1
Persist the address by adding it to /etc/rc.local:
vim /etc/rc.local ip addr add 192.168.12.10 dev eth0:1
Install and configure arptables to suppress ARP replies for the VIP on real servers:
yum -y install arptables_jf arptables -A IN -d <cluster-ip-address> -j DROP arptables -A OUT -s <cluster-ip-address> -j mangle --mangle-ip-s <realserver-ip-address>
Save the ARP table configuration:
service arptables_jf save chkconfig --level 2345 arptables_jf on
Testing the Cluster
Ping the VIP from any real server (pulse must be stopped) to ensure only the LVS router responds:
ping 192.168.122.10 arp | grep 192.168.122.10
Use curl to request a web page and observe traffic with watch ipvsadm on the router:
# watch ipvsadm $ curl http://192.168.122.10/test.txt
Performance Testing with Tsung
Start Tsung on a load‑generation node:
tsung start
Run the test for at least two hours to capture peak HTTP request rates, monitoring CPU usage with htop on the cluster nodes.
Install required tools:
yum -y install htop cluster-ssh cssh node1 node2 node3 ... htop
After the test, generate the report:
cd /root/.tsung/log/20120421-1004 /usr/lib/tsung/bin/tsung_stats.pl firefox report.html
The results show that the HTTP servers handle a very high request rate while the LVS router itself remains lightly loaded.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
