Scripts2026年7月15日·1 分钟阅读

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 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Keepalived
先审查命令
npx -y tokrepo@latest install 069396be-7fe5-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产