Single-Server to Multi-Node Cluster Migration
This guide explains how to convert an existing single-node hermEX server into a multi-node (multi-pod) cluster without reinstalling from scratch or losing mailbox data. You promote the existing server to Pod 0, share its MariaDB database or move the database to a highly available MariaDB cluster, join new backend pods (Pod 1 and later), monitor all pods from Live status, and move populated mailboxes between pods live.
For a greenfield multi-node cluster, use Multi-Node Installation. For DRBD/Pacemaker Active-Passive failover pairs and rolling updates, see HA & Rolling Updates.
1. How the Conversion Works
A standalone single-node installation already uses the same binaries, schema, and /etc/hermex/config.json format as a multi-node cluster:
| Component | Before (Single Node) | After (Multi-Node Cluster) |
|---|---|---|
| Existing host role | Implicit node_id: 0, local MariaDB + local data_dir | Explicit Pod 0 (node_id: 0), servers ID 0 |
| Directory & relay state | Local MariaDB on 127.0.0.1:3306 | Shared MariaDB reachable by every pod (either secured cluster bind or dedicated HA MariaDB VIP) |
| Pod-to-pod bridge | Unused (internal_pod_secret empty) | Enabled on all pods with matching internal_pod_secret and optional internal_pod_addr |
| Mailbox placement | Every mailbox on the single host | Partitioned by users.homeserver and domains.homeserver, movable live across pods |
2. Step 1: Back Up Directory State, Secrets, and Mailboxes
Before changing database bindings or network settings, capture a complete backup on the existing single-node server:
# 1. Back up the MariaDB directory, relay spool, and audit chain
sudo hermex-admin backup-db --output /root/hermex-precluster-db.sql.gz
# 2. Copy /etc/hermex/config.json (holds key_secret and all cluster secrets) to safe offline storage
sudo cp /etc/hermex/config.json /root/config.json.precluster
sudo chmod 600 /root/config.json.precluster
# 3. Optional full mailbox snapshot before topology changes
sudo hermex-admin backup-mail all /var/backups/hermex-precluster-mail
Verify that all 14 hermex-* units and targets report Up before starting:
sudo /root/install.sh status
sudo hermex-admin -config /etc/hermex/config.json status
3. Step 2: Move or Expose MariaDB for the Cluster
Choose one of two MariaDB topologies depending on whether you keep the database on Pod 0 temporarily or move immediately to a dedicated HA MariaDB cluster:
Option A: Migrate MariaDB to a Dedicated HA Cluster (Recommended for Production)
- Provision a 3-node MariaDB 11.8 Galera cluster (or managed HA MariaDB) behind a private VIP (for example
10.0.0.5:3306) using the complete step-by-step guide in Shared MariaDB 11.8 Cluster. - Create the
emaildatabase and grant privileges to your cluster database user over the private subnet (10.0.0.0/24). - Restore the database backup taken in Step 1 into the shared MariaDB cluster, or stop all
hermex-*services onPod 0briefly to take a final consistentmariadb-dumpand import it cleanly:sudo systemctl stop 'hermex-*'mysqldump --single-transaction --routines --triggers email > /root/final-email.sqlmysql -h 10.0.0.5 -u hermex -p email < /root/final-email.sql - Update
database_dsn(andrelay_database_dsnif separated) inPod 0/etc/hermex/config.jsonto point to10.0.0.5:3306.
Option B: Expose MariaDB on Pod 0 Inside the Private Cluster Network
If you are adding a second application pod immediately and plan to externalize MariaDB later:
- Bind MariaDB on
Pod 0to its private VLAN IP (10.0.0.10) in/etc/my.cnf.d/hermex.cnfor/etc/mysql/mariadb.conf.d/99-hermex.cnf(bind-address = 10.0.0.10). - Grant the database user access only from your private cluster subnet (
10.0.0.0/24) and restrict TCP3306in the firewall to cluster pod IPs only. - Point
database_dsnonPod 0and later pods to10.0.0.10:3306.
3306 to the public InternetRestrict 3306 in firewalld, ufw, or cloud security groups to the private IP addresses of your hermEX nodes only.
4. Step 3: Enable Multi-Node Secrets and node_id: 0 on Pod 0
Edit /etc/hermex/config.json on the original server so it acts explicitly as Pod 0:
- Generate a 32-byte hex
internal_pod_secret:openssl rand -hex 32 - Set
node_id,internal_pod_secret, and optionallyinternal_pod_addrin/etc/hermex/config.json:Keep the existing{"node_id": 0,"cluster_edge_only": false,"database_dsn": "hermex:DB_PASS@tcp(10.0.0.5:3306)/email?parseTime=true&multiStatements=true","relay_database_dsn": "","internal_pod_secret": "REPLACE_WITH_64_HEX_CHARS","internal_pod_addr": ":8443"}webmail_secret,admin_secret,key_secret,digest_secret, andnotify_secretvalues unchanged. - Verify schema readiness and restart the daemons on
Pod 0:sudo hermex-admin -config /etc/hermex/config.json ensure-schemasudo systemctl restart 'hermex-*'sudo hermex-admin -config /etc/hermex/config.json status
internal_pod_addr vs gateway port 443If internal_pod_addr is set (for example 10.0.0.10:8443), inter-pod admin and health bridge calls connect directly on that private port. If internal_pod_addr is omitted, internal_http_url on HTTPS port 443 serves /_internal/cluster/pod/ through the gateway.
5. Step 4: Provision Pod 1 (node_id: 1) and Register Both Pods
- Synchronize clocks (
chronyorsystemd-timesyncd) on all nodes. - Install the identical hermEX release binaries on
Pod 1(10.0.0.11) following Multi-Node Installation. - Copy the six shared secrets (
webmail_secret,admin_secret,key_secret,digest_secret,notify_secret, andinternal_pod_secret) fromPod 0/etc/hermex/config.jsonintoPod 1/etc/hermex/config.json, set"node_id": 1, pointdatabase_dsnto the same MariaDB cluster, and runensure-schema+ start services. - Ensure private firewall rules allow TCP
3306,443(or yourinternal_pod_addr),143,110,4190, and25betweenPod 0andPod 1. - Register both pods in the
serversdirectory table (using CLI, Admin Panel System -> Servers, or MCPcreate_server):Wait up to 15 seconds for every daemon's cluster router loop to refresh the server registry, or confirm immediately withsudo hermex-admin update-server 0 \--name=pod-0 \--hostname=pod0.internal \--http-url=https://10.0.0.10:443 \--imap=10.0.0.10:143 \--pop3=10.0.0.10:110 \--sieve=10.0.0.10:4190 \--smtp=10.0.0.10:25 \--default=on \--enabled=onsudo hermex-admin create-server 1 pod-1 \--hostname=pod1.internal \--http-url=https://10.0.0.11:443 \--imap=10.0.0.11:143 \--pop3=10.0.0.11:110 \--sieve=10.0.0.11:4190 \--smtp=10.0.0.11:25 \--default=off \--enabled=onsudo hermex-admin list-servers.
6. Step 5: Verify Multi-Pod Live Status Across Pods
Once two or more enabled pods exist in servers, Live status automatically probes every enabled remote pod through the signed internal pod bridge (/_internal/cluster/pod/admin/health). You do not need to expose each pod's loopback :8701..:8712 health ports over the network.
Check cluster-wide health from any surface:
- Admin Panel: Open System -> Live status (
/admin/ui/status). Local daemons appear in the primary table, followed by one status section per remote enabled pod (pod-1 (Pod #1), and so on). If a pod bridge endpoint is unreachable, that pod reportsDownwith the connection error while healthy pods keep rendering. - REST API:
GET /admin/statusreturns local daemon entries plus each remote pod's probes (node_idandpod_nameincluded). - CLI: Run
sudo hermex-admin -config /etc/hermex/config.json statuson the admin pod to inspect local targets and every enabled remote pod in one output. - MCP: Call the
statusMCP tool to fetch the combined JSON array across all enabled pods.
7. Step 6: Place New Accounts or Move Populated Mailboxes Live
After Pod 1 is active:
- New domains or new empty accounts: Assign the domain or user
homeserverdirectly to1before the first mail delivery (hermex-admin update-domain example2.com --homeserver=1orhermex-admin update-user newuser@example.com --homeserver=1). - Existing populated mailboxes on
Pod 0: Never changeusers.homeservermanually on a populated account. Use the two-phase live pod-to-pod mailbox move (pod_move), which keeps the mailbox online until final cutover.
How Two-Phase Live Mailbox Move (pod_move) Works
- Pre-flight validation: Verifies the account exists, the target pod is enabled and differs from the account's current
homeserver, and no activepod_movejob is already running for that mailbox. - Phase 1 (
warm_copy): Streams a fulltar.gzsnapshot of the source mailbox (objects.sqlite3,imapindex.sqlite3,cid/, andeml/) to the target pod's temporary staging directory (/_internal/cluster/pod/admin/mailbox-move-stage) while users continue reading and writing normally on the source pod. - Phase 2 (
cutover_lock+final_sync+commit):- Acquires a timed cutover write lock in MariaDB (
mailbox_move_locks) and terminates active webmail sessions (DeleteWebmailSessionsFor). - All front-door protocols reject writes transiently during cutover (
503+Retry-After: 5on Gateway HTTPS,NO [UNAVAILABLE]on IMAP,-ERR [SYS/TEMP]on POP3,NO "TRYLATER"on ManageSieve, and SMTP451 4.3.2/ internal503on MTA delivery). - Waits briefly for in-flight store writers to drain, streams a final delta sync snapshot, runs
CheckMailboxverification on the staged target store, atomically swaps the staged store into the live mailbox directory (/_internal/cluster/pod/admin/mailbox-move-commit), atomically switchesusers.homeserverin MariaDB inside a transaction (CompleteMailboxMove), and releases the cutover lock.
- Acquires a timed cutover write lock in MariaDB (
- Source cleanup (
keep_source): By default, once the target commit succeeds and passes store verification, the old source mailbox directory is removed so stale data never remains behind. Pass--keep-source(CLI/MCP/REST) or check Keep source mailbox files on origin pod after verification (Admin UI) if you want to keep a cold copy on the source pod for extra validation.
data_partitions paths if pods use non-default rootsEvery pod preserves the account's stored users.maildir path during cutover. Keep the default /var/lib/hermex/mail root consistent across pods, or list every shared partition path inside data_partitions in /etc/hermex/config.json on pods that receive moved mailboxes.
Running a Live Mailbox Move
Use any of the four administrative interfaces:
- Admin Panel (
Migration & Bulk): Open System -> Migration & Bulk (/admin/ui/migration), locate Live pod-to-pod mailbox move (shown when two or more pods exist), select the mailbox and target pod, choose whether to keep the source copy, and click Start live mailbox move. Track live phase counters in Migration jobs. - Admin Panel (
User detail): Open Directory -> Users -><user>-> General (/admin/ui/users/<email>), select the target pod under Live pod-to-pod mailbox move, and submit. - REST API (
PermSystemAdminrequired):Returnscurl -X POST https://admin.example.com/admin/migrations/pod-move \-b cookies.txt \-H "X-CSRF-Token: $CSRF" \-H "Content-Type: application/json" \-d '{"email":"alice@example.com","target_node":1,"keep_source":false}'202 Acceptedwith the queued job JSON,400for same or disabled target pod, and409 Conflictif a move is already active for that mailbox. - CLI:
# Queue for the background worker on Pod 0 (and optionally wait until completion)sudo hermex-admin move-mailbox alice@example.com 1 --wait# Or execute inline from the CLI and preserve the source copy on Pod 0sudo hermex-admin move-mailbox alice@example.com 1 --keep-source --direct
- MCP: Call the
move_mailboxtool ({"email":"alice@example.com","target_node":1,"keep_source":false}).
Recovery After Interrupted Moves
If the worker restarts mid-move before cutover commit, startup runs CleanExpiredMailboxMoveLocks() to clear expired locks and ResetStaleRunningMigrationsForHomeserver() to return interrupted jobs to recoverable state. Re-run or cancel via hermex-admin cancel-migration <id> / hermex-admin resume-migration <id> or the Migration jobs table. If warm_copy or final_sync fails before CompleteMailboxMove, the temporary staging directory on the target pod is aborted (/_internal/cluster/pod/admin/mailbox-move-abort) and the account stays untouched on its origin pod.
8. Step 7: Update DNS / Edge Load Balancing and Verify End-to-End
- Route public mail and Exchange traffic using one of the three dedicated ingress guides: DNS Round-Robin (No Extra Proxy), hermEX Stateless Edge Proxy (
cluster_edge_only: true), or L4 TCP Load Balancer (HAProxy, Envoy, Keepalived VIP, or Cloud LB forwarding L4 TCP ports25,80,110,143,443,465,587,993,995, and4190). - Confirm unauthenticated calls to internal endpoints return
403:curl -sk -o /dev/null -w '%{http_code}\n' -X POST https://mail.example.com/_internal/cluster/pod/admin/healthcurl -sk -o /dev/null -w '%{http_code}\n' -X POST https://mail.example.com/_internal/cluster/pod/admin/mailbox-move-stage - Verify cluster health, account routing, and mailbox integrity:
sudo hermex-admin statussudo hermex-admin show-user alice@example.comsudo hermex-admin check-mailbox all
- Sign in via Webmail, IMAP (
993), and ActiveSync/EWS against a moved user (alice@example.comnow onPod 1) while connecting throughPod 0or the edge load balancer, send a test message to an account still onPod 0, and confirm delivery in both directions.