Build a High‑Availability Web Cluster with Keepalived on Linux
This guide walks through installing, compiling, and configuring Keepalived across multiple Linux nodes to create a VRRP‑based high‑availability web service cluster, covering prerequisites, virtual IP setup, load‑balancing rules, and monitoring tools.
Keepalived is a VRRP‑based solution that provides high availability for web services by assigning a virtual IP that can be taken over by a backup node when the master fails.
1. Keepalived principle diagram
The diagram shows a client accessing the virtual IP, a master (control) node, a backup node, and the real servers that actually serve the content.
2. Setting up Keepalived service
Four nodes are used: two control nodes (master and backup) and two real servers. The client accesses the virtual IP. Important notes: all nodes must resolve hostnames, synchronize time, and have proper yum repositories.
Installation package:
keepalived-1.2.13.tar.gz
On each control node, extract, compile, and install Keepalived.
Before compiling, install required packages.
Compile the source.
Install the compiled binaries.
Create symbolic links for the configuration and service files.
Configure the Keepalived file: set the virtual IP, define MASTER and BACKUP roles, set delay_loop to 6 seconds, and specify the real server IPs (192.168.2.108 and 192.168.2.109) with port 80 using a round‑robin (rr) load‑balancing method.
Start the Keepalived service and verify that the virtual IP (192.168.2.110) is recognized.
Install arptable_jf on the real servers and set arptables policies.
Install ipvsadm on the control nodes to monitor service status.
If installation fails, adjust the yum repository as shown.
Install httpd on the real servers, deploy default content, and start the service.
On the master control node, view monitoring information.
Access the virtual IP (192.168.2.110) from a browser; the round‑robin policy alternates between the two real servers (192.168.2.108 and 192.168.2.109).
3. Summary
The high‑availability cluster built with Keepalived is simpler than Heartbeat and is widely used in production environments.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
