How to Build a High‑Availability Cluster with Keepalived: Step‑by‑Step Guide
This article explains the fundamentals of Keepalived, its core components, configuration file structure, and provides a detailed walkthrough of setting up a high‑availability IPVS cluster, testing failover scenarios, and verifying load‑balancing behavior.
Keepalived Overview
Keepalived implements the VRRP protocol and was originally designed to provide high‑availability for IPVS services. It can generate IPVS rules from its configuration file, perform health checks on real servers, and expose services through a shared virtual IP address. In each HA group, only one master server is active at a time while the others remain in standby; if the active server fails, another server takes over the virtual IP based on priority.
Keepalived Components
The main components are:
core : Handles the main process startup, maintenance, and global configuration.
vrrp stack : Provides high‑availability services based on the VRRP protocol.
check : Monitors the health of related processes.
system call : System‑level calls used by Keepalived.
watchdog : Oversees the check and VRRP processes; when a health check detects a service failure on the master, it notifies VRRP to shift the virtual IP to a backup server.
Configuration
The Keepalived configuration file ( /etc/keepalived/keepalived.conf) is divided into three sections: global_defs, vrrp_instance, and virtual_ipaddress. Below is a simplified example (image omitted for brevity): edit the file on each Keepalived node, adjust the priority and state values accordingly.
Test Topology
The experimental topology consists of two Keepalived nodes and two real servers. Each real server hosts a test page and an emergency response page for the Keepalived nodes.
Deployment Steps
Configure the real servers with the appropriate test and emergency pages.
Edit keepalived.conf on both Keepalived nodes, set priorities, and define the virtual IP address.
Start Keepalived on each node and verify the generated IPVS rules.
Use ipvsadm -Ln (or similar) on the Keepalived nodes to view the load‑balancing configuration.
Failover Verification
After both nodes are running, simulate a master node failure. The virtual IP address migrates to the backup node, demonstrating address failover.
Load‑Balancing Algorithm Test
The setup uses the round‑robin (RR) scheduling algorithm. The test results show traffic distribution across the real servers as expected.
Backend Failure Simulation
When one or both real servers are taken offline, the Keepalived cluster continues to serve the emergency response pages, confirming high‑availability behavior.
Conclusion
The demonstrated configuration successfully creates a Keepalived high‑availability cluster. You can further test it with a browser or deploy actual services on the backend servers to verify that traffic is distributed according to the defined scheduling algorithm.
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.
