UnderHost
Knowledgebase Docs

VPS Clustering and High Availability

Setup high availability clusters for VPS. Multi-node clustering, failover, redundancy, database replication, shared storage.

On this page

High Availability (HA) clustering ensures your application survives server failures. Multiple VPS nodes run your app, a cluster manager detects failures, and traffic automatically routes to healthy nodes. Zero downtime during maintenance, automatic recovery from crashes. Essential for production.

HA Clustering Overview

  • Redundancy: Multiple nodes, if one fails, others survive
  • Automatic failover: Reroute traffic when node dies
  • Zero downtime: Maintenance, updates without user impact
  • Load balancing: Distribute traffic across nodes
  • Complexity: More servers, more things to manage

Cluster Architecture

Minimum HA setup (3 nodes):

User Traffic
     ↓
Virtual IP (VIP) - Managed by cluster
     ↓
├─ Node 1 (Web App + App Server)
├─ Node 2 (Web App + App Server)
└─ Node 3 (Web App + App Server)
     ↓
Database (shared or replicated)
Shared Storage (optional)

Key components:**

  • Virtual IP (VIP): Single IP address users connect to
  • Cluster manager: Keeps VIP on healthy node (Pacemaker, Keepalived)
  • Heartbeat: Constant communication between nodes
  • Shared state: Database replication or shared storage

Active-Passive Setup

One active node, others on standby:

# Keepalived config for active-passive
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100          # Higher = more priority to be master
    advert_int 1

    virtual_ipaddress {
        192.168.1.50      # VIP (virtual IP)
    }

    track_script {
        check_web         # Custom health check
    }
}

Advantages:

  • Simple setup
  • One node always ready
  • Less resource usage

Disadvantages:

  • Standby nodes wasted (not serving traffic)
  • Failover takes seconds

Active-Active Setup

All nodes serve traffic (better efficiency):

# Load balancer distributes to all nodes
Node 1: 192.168.1.101 (active)
Node 2: 192.168.1.102 (active)
Node 3: 192.168.1.103 (active)

# If Node 1 fails, load balancer removes it
# Node 2 and 3 handle all traffic
# When Node 1 recovers, it rejoins cluster

Advantages:

  • All nodes serve traffic (100% resource utilization)
  • Can handle more load
  • Better cost efficiency

Disadvantages:

  • More complex configuration
  • All nodes must have identical state
  • Database synchronization critical

Database Replication

MySQL replication (primary-replica):

# Primary server (Node 1) config
# /etc/mysql/mysql.conf.d/mysqld.cnf
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = myapp_db

# Create replication user
CREATE USER 'replicator'@'10.0.0.%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'10.0.0.%';

# Replica server (Node 2) config
server-id = 2
relay-log = /var/log/mysql/mysql-relay-bin
relay-log-index = /var/log/mysql/mysql-relay-bin.index
relay-log-recovery = ON

# Start replication from primary
CHANGE MASTER TO
    MASTER_HOST='10.0.0.1',
    MASTER_USER='replicator',
    MASTER_PASSWORD='password',
    MASTER_LOG_FILE='mysql-bin.000001',
    MASTER_LOG_POS=154;
START SLAVE;

Heartbeat and Detection

# Corosync provides cluster communication
# /etc/corosync/corosync.conf
nodename: node1
cluster_name: ha-cluster

interface {
    ringnumber: 0
    bindnetaddr: 192.168.1.0
    mcastaddr: 239.255.1.1
    mcastport: 5405
    ttl: 1
}

# Start cluster
systemctl start corosync
systemctl start pacemaker

# Check cluster status
crm status
corosync-cfgtool -s

Automatic Failover

# Pacemaker health check (primitive)
crm configure primitive web-app \
    ocf:heartbeat:apache \
    op monitor interval="30s" timeout="60s" \
    meta failure-timeout="5m"

# Failover policy: restart 3 times, then switch to next node
crm configure property -threshold="3"
crm configure property failure-timeout="5m"

# Set resource stickiness (prefer current node if healthy)
crm configure rsc_defaults resource-stickiness="100"

Test Your Cluster

# Simulate node failure
systemctl stop httpd            # Stop web server

# Monitor failover
watch crm status                # See VIP move to another node

# Kill entire node (harsh test)
systemctl poweroff              # Reboot node

# Traffic should route to remaining nodes within seconds

# Test failback (recovery)
systemctl start httpd           # Bring node back online
crm node online node1           # Mark node as online
# VIP should move back to preferred node
Database is the hardest part of HA clustering

Application servers are easy to replicate. But databases? That's where clustering gets complex. Replication lag, write conflicts, distributed transactions—know your database replication architecture intimately before production.

Related: Load balancing | VPS scaling | High availability | Database replication

Was this article helpful?

Need a Cloud VPS?

Launch an UnderHost Cloud VPS when you need root access, dedicated resources, custom software, or more control than shared hosting.

Back to Cloud VPS