ScriptsJul 15, 2026·3 min read

Keepalived — High Availability and Load Balancing for Linux

A robust VRRP and health-checking daemon that provides IP failover and real server load balancing for Linux infrastructure.

Agent ready

Review-first install path

This asset needs a review step. The copied prompt tells the agent to dry-run, show the writes, then proceed only after confirmation.

Needs Confirmation · 64/100Policy: confirm
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Keepalived
Review-first command
npx -y tokrepo@latest install 069396be-7fe5-11f1-9bc6-00163e2b0d79 --target codex

Dry-run first, confirm the writes, then run this command.

Introduction

Keepalived is a Linux system daemon that provides high availability via VRRP (Virtual Router Redundancy Protocol) and load balancing through the Linux Virtual Server (LVS/IPVS) framework. It is widely used to create active-passive or active-active failover clusters for critical services like load balancers, database proxies, and web servers.

What Keepalived Does

  • Implements VRRP for automatic virtual IP failover between multiple servers
  • Manages Linux Virtual Server (IPVS) rules for Layer 4 load balancing
  • Performs health checks on real servers using TCP, HTTP, SSL, and custom scripts
  • Supports BFD (Bidirectional Forwarding Detection) for sub-second failure detection
  • Triggers notification scripts on state transitions for custom automation

Architecture Overview

Keepalived runs as a multi-process daemon with a parent watchdog and child processes for VRRP and health checking. The VRRP process sends multicast advertisements and manages virtual IP assignment via Netlink. The health checker process monitors real servers and updates IPVS tables accordingly. Both processes communicate state changes to the parent, which can invoke notification scripts. The entire system integrates directly with the Linux kernel's networking stack for minimal overhead.

Self-Hosting & Configuration

  • Install via package manager on all major Linux distributions
  • Configuration in /etc/keepalived/keepalived.conf defines VRRP instances and virtual servers
  • Set priority values to control which node becomes MASTER (higher wins)
  • Use track_script to tie VRRP state to application health checks
  • Enable unicast_peer for environments where multicast is not available

Key Features

  • Sub-second failover with configurable advertisement intervals
  • SNMP integration for monitoring VRRP state and statistics
  • IPv4 and IPv6 dual-stack support for virtual IP addresses
  • Preemption control to prevent flapping between MASTER and BACKUP nodes
  • Sync groups for coordinating failover of multiple VRRP instances together

Comparison with Similar Tools

  • HAProxy — Layer 7 load balancer and proxy; Keepalived provides Layer 4 LVS load balancing and VIP failover that is often used alongside HAProxy
  • Pacemaker/Corosync — Full cluster resource manager for complex HA setups; Keepalived is simpler for IP failover and LVS scenarios
  • MetalLB — Kubernetes-specific load balancer implementation; Keepalived works at the OS level outside of Kubernetes
  • UCARP — Lightweight VRRP alternative; Keepalived adds LVS management and richer health checking

FAQ

Q: Can Keepalived run in containers? A: Yes, but the container needs NET_ADMIN capability and host networking to manage virtual IPs and VRRP multicast.

Q: How do I prevent split-brain? A: Use unicast peers instead of multicast, configure fencing scripts, and ensure reliable network connectivity between nodes.

Q: Does Keepalived work with HAProxy? A: Yes, a common pattern is using Keepalived for VIP failover between two HAProxy instances for a fully redundant load balancer.

Q: What is the minimum setup for simple failover? A: Two servers with Keepalived configured as MASTER and BACKUP for the same virtual_router_id, sharing a virtual IP address.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets