็†ฑ้–€ๅˆ†้กž
 ่ผ‰ๅ…ฅไธญ…
็›ฎ้Œ„

๐ŸŒ Linux Apache High Availability: Full Active-Active Dual-Node Deployment Guide

    ๐ŸŒ Linux Apache High Availability: Full Active-Active Dual-Node Deployment Guide

    Traditional single-node Apache servers suffer from single points of failure and limited scalability. This guide demonstrates how to deploy a dual-node Active-Active Apache HA architecture on Linux, including load balancing, health checks, VIP failover, and content synchronization — suitable for production environments.

    ๐Ÿ“Œ 1. Overview: What Is Active-Active?

    Active-Active means both nodes serve traffic simultaneously, improving:

    • ⚡ Performance via load distribution
    • ๐Ÿ›ก️ High availability — one node fails, service continues
    • ๐Ÿ“ˆ Scalability — easy horizontal expansion
    
    Components used:
    1. Apache – Web server nodes
    2. HAProxy / Nginx – Load balancing tier
    3. Keepalived – VRRP + virtual IP + failover
    4. rsync / Unison / GlusterFS – Web content sync
      

    ๐Ÿ“ก 2. Architecture Topology

    
            +--------------------------+
            |     VIP 192.168.1.200    |
            |       (Keepalived)       |
            +------------+-------------+
                         |
                  +------+-------+
                  | Load Balancer|
                  |(HAProxy/Nginx)|
                  +------+-------+
                         |
         +---------------+---------------+
         |                               |
    +----+----------+          +---------+----+
    | Apache Node A |          | Apache Node B |
    | 192.168.1.10  |          | 192.168.1.11  |
    +---------------+          +---------------+
      

    ๐Ÿ›  3. Install Apache (Both Nodes)

    # Rocky Linux / CentOS
    sudo dnf install httpd -y
    
    # Ubuntu / Debian
    sudo apt install apache2 -y
    
    sudo systemctl enable --now httpd
      

    Create different test pages (to verify load balancing later):

    
    echo "Node A Web" | sudo tee /var/www/html/index.html
    echo "Node B Web" | sudo tee /var/www/html/index.html
      

    ๐Ÿ” 4. Web Content Synchronization Options

    Option A: rsync (Simple, uni-directional)

    
    */1 * * * * rsync -az /var/www/html/ root@192.168.1.11:/var/www/html/
      

    Option B: Unison (Recommended — two-way sync)

    Ideal for collaborative or multi-maintainer environments.

    Option C: GlusterFS (Enterprise-grade storage)

    Real-time replicated volume across nodes.


    ⚖️ 5. Deploy Load Balancer (HAProxy / Nginx)

    Option A: HAProxy (Most recommended)

    sudo dnf install haproxy -y
    /etc/haproxy/haproxy.cfg
    
    frontend http-in
        bind *:80
        default_backend apache-backend
    
    backend apache-backend
        balance roundrobin
        mode http
        option httpchk
        server web1 192.168.1.10:80 check
        server web2 192.168.1.11:80 check
      
    sudo systemctl enable --now haproxy

    Option B: Nginx as Load Balancer

    
    upstream apache_cluster {
        server 192.168.1.10;
        server 192.168.1.11;
    }
    
    server {
        listen 80;
        location / {
            proxy_pass http://apache_cluster;
        }
    }
      

    ๐Ÿท 6. Keepalived + VIP Failover

    Keepalived provides VRRP + virtual IP + failover. Usually configured as Active-Standby to avoid ARP chaos, though Active-Active with dual VIPs is also possible.

    Install

    
    sudo dnf install keepalived -y
      

    Main node (LB1)

    /etc/keepalived/keepalived.conf
    
    vrrp_instance VI_1 {
        state MASTER
        interface ens33
        virtual_router_id 51
        priority 120
        advert_int 1
    
        authentication {
            auth_type PASS
            auth_pass 123456
        }
    
        virtual_ipaddress {
            192.168.1.200
        }
    }
      

    Backup node (LB2)

    
    state BACKUP
    priority 100
      

    Enable

    
    sudo systemctl enable --now keepalived
      

    ๐Ÿงช 7. Validate Active-Active Behavior

    
    while true; do curl -s http://192.168.1.200 | grep Node; sleep 1; done
      

    You should see alternating outputs:

    
    Node A Web
    Node B Web
    Node A Web
    Node B Web
      

    ๐Ÿ“ฆ 8. Failure Testing (Important!)

    # Stop Apache on Node A
    sudo systemctl stop httpd
    
    curl http://192.168.1.200
      

    Expected: You still get Node B, without interruption.

    ๐Ÿ“˜ Conclusion

    By combining HAProxy, Apache, and Keepalived, you now have a production-ready Active-Active web architecture. The system supports load balancing, fault tolerance, and web content synchronization — perfect for enterprise workloads, APIs, and high-traffic sites. For more advanced scalability, consider adding Kubernetes, CephFS, or distributed session management.


    ๐Ÿ”— Related Articles

    — WWFandy・Systems & Network Notes

    ๐Ÿ”— ๅˆ†ไบซ้€™็ฏ‡ LINE Facebook X

    ๆฒ’ๆœ‰็•™่จ€:

    ๅผต่ฒผ็•™่จ€

    ๅญ—็ดš