Skip to content

Commit 3d2dad0

Browse files
authored
Add master-slave replication — rsync+SSH config sync (#39)
Implements automatic config synchronization from a master server to one or more slave servers via rsync+SSH on a configurable interval. Synced: secrets.conf, upstreams.conf, instances.conf, config.toml Never synced: settings.conf, replication.conf (slave role preserved) New CLI: mtproxymax replication [setup|status|add|remove|sync|test| logs|promote|enable|disable|reset] TUI: [r] Replication in main menu with full management interface. Features: - Configurable SSH user (REPLICATION_SSH_USER, default root) - rsync --delete toggle (REPLICATION_DELETE_EXTRA) - flock prevents overlapping sync runs - Triple-layered exclude-list protection for slave identity - SSH key auto-generation (ed25519) with TOFU warning - Dependency checks for rsync/ssh/ssh-keygen - Promote slave to master for failover - 112 unit tests (no Docker/SSH required) Closes #39
1 parent 82ee4d0 commit 3d2dad0

3 files changed

Lines changed: 2188 additions & 2 deletions

File tree

README.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Most MTProxy tools give you a proxy and a link. That's it. MTProxyMax gives you
4040

4141
- 🔐 **Multi-user secrets** with individual bandwidth quotas, device limits, and expiry dates
4242
- 🤖 **Telegram bot** with 17 commands — manage everything from your phone
43+
- 🗂️ **Replication** — sync config to slave servers automatically via rsync+SSH
4344
- 🖥️ **Interactive TUI** — no need to memorize commands, menu-driven setup
4445
- 📊 **Prometheus metrics** — real per-user traffic stats, not just iptables guesses
4546
- 🔗 **Proxy chaining** — route through SOCKS5 upstreams for extra privacy
@@ -222,6 +223,47 @@ mtproxymax telegram setup
222223
- 🟢 Proxy started → sends connection details + QR codes
223224
- 📊 Periodic traffic reports at your chosen interval
224225

226+
---
227+
228+
### 🗂️ Replication (Master-Slave Config Sync)
229+
230+
Keep multiple proxy servers in sync automatically. The master pushes config changes to all slaves via rsync+SSH on a configurable interval. Slaves receive `secrets.conf`, `upstreams.conf`, `instances.conf`, and `config.toml` — their own role settings and local state are never overwritten.
231+
232+
**Setup takes two commands:**
233+
234+
```bash
235+
# On master — run wizard, select Master, add slave
236+
mtproxymax replication setup
237+
238+
# On slave — run wizard, select Slave
239+
mtproxymax replication setup
240+
```
241+
242+
**How it works:**
243+
- Master generates a self-contained sync script at `/opt/mtproxymax/mtproxymax-sync.sh`
244+
- A systemd timer fires every N seconds (default: 60) and runs the sync
245+
- On change — proxy container on slave is automatically restarted
246+
- `settings.conf` and `replication.conf` are always excluded — slave role is never overwritten
247+
248+
```bash
249+
mtproxymax replication status # Show role, timer state, last sync
250+
mtproxymax replication sync # Trigger immediate sync
251+
mtproxymax replication logs # View sync log
252+
mtproxymax replication test # Test SSH connectivity to all slaves
253+
mtproxymax replication promote # Promote slave to master (failover)
254+
```
255+
256+
**Roles:**
257+
258+
| Role | Description |
259+
|------|-------------|
260+
| **Master** | Pushes config to slaves on schedule |
261+
| **Slave** | Receives config, read-only. Changes must be made on master |
262+
| **Standalone** | Replication disabled (default) |
263+
264+
---
265+
266+
225267
---
226268

227269
### 🔗 Proxy Chaining (Upstream Routing)
@@ -307,6 +349,7 @@ Engine updates are delivered through `mtproxymax update`. Pre-built multi-arch D
307349
| **Telegram Bot** | ✅ (17 commands) ||||
308350
| **Interactive TUI** |||||
309351
| **Proxy Chaining** | ✅ (SOCKS5/4, weighted) | ✅ (SOCKS5) |||
352+
| **Master-Slave Replication** | ✅ (rsync+SSH, systemd) ||||
310353
| **Geo-Blocking** || IP allowlist/blocklist |||
311354
| **Ad-Tag Support** || ❌ (removed in v2) || Varies |
312355
| **QR Code Generation** |||| Some |
@@ -369,13 +412,24 @@ Telegram Client
369412
370413
371414
Telegram Servers
415+
416+
417+
Master-Slave Replication (optional):
418+
419+
Master Server Slave Server(s)
420+
┌──────────────┐ ┌──────────────┐
421+
│ mtproxymax │──rsync──▶ │ mtproxymax │
422+
│ (systemd │ +SSH │ (receives │
423+
│ timer 60s) │ │ config) │
424+
└──────────────┘ └──────────────┘
372425
```
373426

374427
| Component | Role |
375428
|-----------|------|
376429
| **mtproxymax.sh** | Single bash script: CLI, TUI, config manager |
377430
| **telemt** | Rust MTProto engine running inside Docker |
378431
| **Telegram bot service** | Independent systemd service polling Bot API |
432+
| **Replication sync service** | systemd timer pushing config to slave servers |
379433
| **Prometheus endpoint** | `/metrics` on port 9090 (localhost only) |
380434

381435
---
@@ -429,6 +483,27 @@ mtproxymax adtag remove # Remove ad-tag
429483

430484
</details>
431485

486+
487+
<details>
488+
<summary><b>Replication</b></summary>
489+
490+
```bash
491+
mtproxymax replication setup # Interactive wizard (master/slave/standalone)
492+
mtproxymax replication status # Role, timer state, last sync, slave list
493+
mtproxymax replication add <host> [port] [label] # Register a slave server
494+
mtproxymax replication remove <host_or_label> # Remove a slave
495+
mtproxymax replication list # List all slaves
496+
mtproxymax replication enable # Enable sync timer
497+
mtproxymax replication disable # Disable sync timer
498+
mtproxymax replication sync # Trigger immediate sync
499+
mtproxymax replication test [host] # Test SSH connectivity to slave(s)
500+
mtproxymax replication logs # Show sync log
501+
mtproxymax replication reset # Remove all replication config
502+
mtproxymax replication promote # Promote slave to master (failover)
503+
```
504+
505+
</details>
506+
432507
<details>
433508
<summary><b>Security & Routing</b></summary>
434509

@@ -510,7 +585,15 @@ mtproxymax telegram remove # Remove bot completely
510585

511586
## 📋 Changelog
512587

513-
### v1.0.4 — Engine v3.3.32, SNI Policy & Metrics Dashboard
588+
### v1.0.4 — Replication, Engine v3.3.32, SNI Policy & Metrics Dashboard
589+
590+
- **Replication** — sync config from master to slave servers via rsync+SSH with systemd timer
591+
- **Auto-exclude**`settings.conf` and `replication.conf` are never synced to slaves, preserving their role and local state
592+
- **Wizard** — interactive setup for master, slave, and standalone roles
593+
- **Slave protection** — setting slave role stops any local sync timer and clears stale peer list
594+
- **Promote**`mtproxymax replication promote` for manual failover (slave → master)
595+
- **Role guards**`replication add/remove/sync` are blocked with a clear error on slave servers
596+
- **Sync script auto-update** — manual `sync` always regenerates the script from current binary
514597

515598
**Engine Upgrade (v3.3.31 → v3.3.32):**
516599

0 commit comments

Comments
 (0)