- 6-node MariaDB cluster with GTID replication - MaxScale 24.02 proxy with automatic failover - Flask dashboard with SSE transaction monitor - Per-server toggle controls + mode selector - Systemd services for auto-start on boot - One-command deploy.sh
129 lines
4.1 KiB
Markdown
129 lines
4.1 KiB
Markdown
# MariaDB HA Demo
|
||
|
||
Real-time high availability demonstration with a 6-node MariaDB cluster, MaxScale proxy, and live dashboard.
|
||
|
||
---
|
||
|
||
## Quick Start
|
||
|
||
```bash
|
||
git clone https://git.sechpoint.app/customer-engineering/mariadb-demo.git
|
||
cd mariadb-demo
|
||
bash deploy.sh
|
||
```
|
||
|
||
Open **http://{host}:5000** in your browser.
|
||
|
||
---
|
||
|
||
## Architecture
|
||
|
||
```
|
||
┌─ Cluster 1 ─────────────┐ ┌─ Cluster 2 ─────────────┐
|
||
│ mariadb1 PRIMARY │ │ mariadb4 SECONDARY │
|
||
│ mariadb2 SECONDARY │ │ mariadb5 SECONDARY │
|
||
│ mariadb3 SECONDARY │ │ mariadb6 SECONDARY │
|
||
└─────────────────────────┘ └──────────────────────────┘
|
||
│ │
|
||
└─────── MaxScale ──────────┘
|
||
(port 4000)
|
||
│
|
||
┌──────┴──────┐
|
||
│ Dashboard │
|
||
│ (port 5000)│
|
||
└─────────────┘
|
||
```
|
||
|
||
- **6 MariaDB nodes**: 2 clusters with GTID-based async replication
|
||
- **MaxScale 24.02**: read-write splitting, automatic failover
|
||
- **Dashboard**: real-time SSE transaction monitor with per-server toggle controls
|
||
|
||
---
|
||
|
||
## Dashboard Controls
|
||
|
||
| Action | How |
|
||
|--------|-----|
|
||
| Start transactions | Click **⚡ Initialize DB** then **▶ Start Demo** |
|
||
| Kill a server | Click the green/red circle on any server card |
|
||
| Kill entire cluster | Toggle all 3 servers in a cluster OFF |
|
||
| Recover | Click the circle again (red → green) |
|
||
| Switch mode | Use dropdown: **Primary + DR** or **2 Independent Clusters** |
|
||
|
||
### What Visitors See
|
||
- **Terminal feed**: live INSERT→SELECT→DELETE transactions
|
||
- **Status circle**: green = healthy, red = transaction lost
|
||
- **Server cards**: PRIMARY (green), SECONDARY (blue), DOWN (red)
|
||
- **Availability %**: drops during failover, recovers automatically
|
||
|
||
---
|
||
|
||
## Demo Scenarios
|
||
|
||
### 1. Standard Failover
|
||
Kill the PRIMARY server — MaxScale promotes a SECONDARY. Availability drops briefly, then recovers.
|
||
|
||
### 2. Cross-Cluster Failover (DR Mode)
|
||
Switch to **Primary + DR** mode. Kill all 3 servers in Cluster 1 — Cluster 2 takes over as PRIMARY.
|
||
|
||
### 3. Independent Clusters
|
||
Switch to **2 Independent Clusters**. Each cluster has its own PRIMARY — kill one without affecting the other.
|
||
|
||
### 4. MaxScale GUI
|
||
Open **http://{host}:5000/maxscale** — full MaxScale admin interface. Login: `admin` / `mariadb`
|
||
|
||
---
|
||
|
||
## Systemd Services
|
||
|
||
```bash
|
||
sudo systemctl start mariadb-cluster # Start cluster
|
||
sudo systemctl stop mariadb-cluster # Stop everything
|
||
sudo systemctl start mariadb-monitor # Start dashboard
|
||
bash scripts/cluster.sh status # Health check
|
||
```
|
||
|
||
Services auto-start on boot when installed via `deploy.sh`.
|
||
|
||
---
|
||
|
||
## Requirements
|
||
|
||
- Ubuntu 24.04+ / Debian 12+
|
||
- 8 GB RAM, 4 CPU cores
|
||
- Docker installed (`deploy.sh` handles this automatically)
|
||
- Ports: 5000 (dashboard), 4000 (MaxScale), 8989 (MaxScale API), 3307–3312 (MariaDB)
|
||
|
||
---
|
||
|
||
## Manual Deployment (without deploy.sh)
|
||
|
||
```bash
|
||
python3 -m venv venv
|
||
source venv/bin/activate
|
||
pip install -r requirements.txt
|
||
|
||
# Start cluster
|
||
bash scripts/cluster.sh start
|
||
|
||
# Start dashboard
|
||
python3 app.py
|
||
```
|
||
|
||
---
|
||
|
||
## Files
|
||
|
||
| File | Purpose |
|
||
|------|---------|
|
||
| `engine.py` | Transaction engine (INSERT→SELECT→DELETE every 1s) |
|
||
| `app.py` | Flask app: routes, SSE endpoint, MaxScale proxy |
|
||
| `scripts/cluster.sh` | Docker cluster control (start/stop/status) |
|
||
| `scripts/mariadb-cluster.service` | Systemd unit for cluster |
|
||
| `scripts/mariadb-monitor.service` | Systemd unit for dashboard |
|
||
| `cluster-config/` | MariaDB config files (server1-6.cnf) |
|
||
| `templates/dashboard.html` | Single-page dashboard |
|
||
| `static/dashboard.js` | Dashboard logic + SSE consumer |
|
||
| `static/dashboard.css` | Dark theme styles |
|
||
| `deploy.sh` | One-command deployment |
|
||
| `requirements.txt` | Python dependencies |
|