# HighAvailabilityAndClustering **Repository Path**: sps1998/high-availability-and-clustering ## Basic Information - **Project Name**: HighAvailabilityAndClustering - **Description**: Keepalived&LVS(IPVS)从0-1实现高可用与集群功能 - **Primary Language**: C - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-30 - **Last Updated**: 2026-07-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Keepalived - High Availability & Clustering A lightweight, pure C implementation of Keepalived's core functionality, including VRRP (Virtual Router Redundancy Protocol) and IPVS (IP Virtual Server) load balancing. ## Features ### ✅ VRRP Protocol Stack - RFC 3768 VRRP Version 2 compliance - Master-Backup election mechanism - Virtual IP (VIP) management via RTNetlink - State machine (INIT → BACKUP → MASTER) - Advertisement timer with skew time calculation - Preempt timer for priority-based failover ### ✅ IPVS Load Balancing - Netlink Generic interface for kernel communication - Fallback to ipvsadm command mode - Support for multiple scheduling algorithms (rr, wrr, lc) - Automatic kernel module loading - Static compilation for universal deployment ### ✅ Event-Driven Architecture - Epoll-based I/O multiplexing - Min-heap timer management - Unified event scheduler - Signal handling ### ✅ Memory Management - Custom memory allocation wrapper - Memory leak detection - Debug-friendly allocation tracking ## Project Architecture ``` Keepalived/ ├── core/ # Core entry point │ └── main.c # Main process entry ├── lib/ # Base library modules │ ├── memory.c # Memory management │ ├── log.c # Log system │ ├── netlink.c # RTNetlink interface │ ├── ipvs.c # IPVS interface │ ├── epoll.c # Epoll wrapper │ ├── timer.c # Min-heap timer │ └── scheduler.c # Event scheduler ├── vrrp/ # VRRP protocol module │ ├── vrrp.c # VRRP core implementation │ └── vrrp.h # VRRP data structures ├── check/ # Health check module (TBD) ├── include/ # Public header files │ ├── types.h # Core data structures │ ├── list.h # Linked list utilities │ ├── memory.h # Memory interface │ ├── log.h # Log interface │ ├── netlink.h # Netlink interface │ ├── ipvs.h # IPVS interface │ ├── epoll.h # Epoll interface │ ├── timer.h # Timer interface │ └── scheduler.h # Scheduler interface ├── tests/ # Test programs │ └── test_netlink_ipvs.c # Netlink & IPVS tests └── Makefile # Build configuration ``` ## Build & Installation ### Requirements - GCC 9.0+ - Linux kernel with IPVS support - Root privileges for runtime ### Build ```bash git clone https://gitee.com/sps1998/high-availability-and-clustering.git cd high-availability-and-clustering make clean && make ``` ### Install ```bash sudo make install ``` ### Static Build The project uses static compilation by default, enabling deployment on systems with different GLIBC versions. ## Usage ### Run ```bash sudo ./keepalived ``` ### Signal Handling - `SIGINT` / `SIGTERM`: Graceful shutdown - `SIGUSR1`: Dump memory statistics - `SIGUSR2`: Check memory leaks ## Development Phases | Phase | Status | Description | |-------|--------|-------------| | Phase 1 | ✅ | Project architecture, core data structures, basic modules | | Phase 2 | ✅ | Epoll event-driven scheduler, IPVS Netlink interface optimization | | Phase 3 | ✅ | VRRP protocol stack implementation | | Phase 4 | ⏳ | Health check module | | Phase 5 | ⏳ | Configuration file parsing, complete function integration | ## VRRP State Machine ``` INIT → BACKUP → MASTER ↑ │ └──────────┘ ``` ### State Transitions | Current State | Event | Target State | |---------------|-------|--------------| | INIT | INIT / INTERFACE_UP | BACKUP | | BACKUP | ADVERT_TIMER_EXPIRED | MASTER | | BACKUP | RECEIVE_ADVERT (higher priority) | BACKUP | | BACKUP | INTERFACE_DOWN | INIT | | MASTER | RECEIVE_ADVERT (higher priority) | BACKUP | | MASTER | INTERFACE_DOWN | INIT | ## License This project is licensed under the MIT License - see the LICENSE file for details. ## References - [RFC 3768 - Virtual Router Redundancy Protocol](https://tools.ietf.org/html/rfc3768) - [Keepalived Official Documentation](https://keepalived.readthedocs.io/) - [Linux IPVS Documentation](https://www.linuxvirtualserver.org/docs/) ## Contributing Contributions are welcome! Please feel free to submit issues and pull requests.