Skip to main content

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:

ComponentBefore (Single Node)After (Multi-Node Cluster)
Existing host roleImplicit node_id: 0, local MariaDB + local data_dirExplicit Pod 0 (node_id: 0), servers ID 0
Directory & relay stateLocal MariaDB on 127.0.0.1:3306Shared MariaDB reachable by every pod (either secured cluster bind or dedicated HA MariaDB VIP)
Pod-to-pod bridgeUnused (internal_pod_secret empty)Enabled on all pods with matching internal_pod_secret and optional internal_pod_addr
Mailbox placementEvery mailbox on the single hostPartitioned 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:

  1. 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.
  2. Create the email database and grant privileges to your cluster database user over the private subnet (10.0.0.0/24).
  3. Restore the database backup taken in Step 1 into the shared MariaDB cluster, or stop all hermex-* services on Pod 0 briefly to take a final consistent mariadb-dump and import it cleanly:
    sudo systemctl stop 'hermex-*'
    mysqldump --single-transaction --routines --triggers email > /root/final-email.sql
    mysql -h 10.0.0.5 -u hermex -p email < /root/final-email.sql
  4. Update database_dsn (and relay_database_dsn if separated) in Pod 0 /etc/hermex/config.json to point to 10.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:

  1. Bind MariaDB on Pod 0 to its private VLAN IP (10.0.0.10) in /etc/my.cnf.d/hermex.cnf or /etc/mysql/mariadb.conf.d/99-hermex.cnf (bind-address = 10.0.0.10).
  2. Grant the database user access only from your private cluster subnet (10.0.0.0/24) and restrict TCP 3306 in the firewall to cluster pod IPs only.
  3. Point database_dsn on Pod 0 and later pods to 10.0.0.10:3306.
Never expose MariaDB TCP 3306 to the public Internet

Restrict 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:

  1. Generate a 32-byte hex internal_pod_secret:
    openssl rand -hex 32
  2. Set node_id, internal_pod_secret, and optionally internal_pod_addr in /etc/hermex/config.json:
    {
    "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"
    }
    Keep the existing webmail_secret, admin_secret, key_secret, digest_secret, and notify_secret values unchanged.
  3. Verify schema readiness and restart the daemons on Pod 0:
    sudo hermex-admin -config /etc/hermex/config.json ensure-schema
    sudo systemctl restart 'hermex-*'
    sudo hermex-admin -config /etc/hermex/config.json status
Dedicated internal_pod_addr vs gateway port 443

If 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​

  1. Synchronize clocks (chrony or systemd-timesyncd) on all nodes.
  2. Install the identical hermEX release binaries on Pod 1 (10.0.0.11) following Multi-Node Installation.
  3. Copy the six shared secrets (webmail_secret, admin_secret, key_secret, digest_secret, notify_secret, and internal_pod_secret) from Pod 0 /etc/hermex/config.json into Pod 1 /etc/hermex/config.json, set "node_id": 1, point database_dsn to the same MariaDB cluster, and run ensure-schema + start services.
  4. Ensure private firewall rules allow TCP 3306, 443 (or your internal_pod_addr), 143, 110, 4190, and 25 between Pod 0 and Pod 1.
  5. Register both pods in the servers directory table (using CLI, Admin Panel System -> Servers, or MCP create_server):
    sudo 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=on

    sudo 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=on
    Wait up to 15 seconds for every daemon's cluster router loop to refresh the server registry, or confirm immediately with sudo 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 reports Down with the connection error while healthy pods keep rendering.
  • REST API: GET /admin/status returns local daemon entries plus each remote pod's probes (node_id and pod_name included).
  • CLI: Run sudo hermex-admin -config /etc/hermex/config.json status on the admin pod to inspect local targets and every enabled remote pod in one output.
  • MCP: Call the status MCP 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 homeserver directly to 1 before the first mail delivery (hermex-admin update-domain example2.com --homeserver=1 or hermex-admin update-user newuser@example.com --homeserver=1).
  • Existing populated mailboxes on Pod 0: Never change users.homeserver manually 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​

  1. Pre-flight validation: Verifies the account exists, the target pod is enabled and differs from the account's current homeserver, and no active pod_move job is already running for that mailbox.
  2. Phase 1 (warm_copy): Streams a full tar.gz snapshot of the source mailbox (objects.sqlite3, imapindex.sqlite3, cid/, and eml/) 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.
  3. 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: 5 on Gateway HTTPS, NO [UNAVAILABLE] on IMAP, -ERR [SYS/TEMP] on POP3, NO "TRYLATER" on ManageSieve, and SMTP 451 4.3.2 / internal 503 on MTA delivery).
    • Waits briefly for in-flight store writers to drain, streams a final delta sync snapshot, runs CheckMailbox verification on the staged target store, atomically swaps the staged store into the live mailbox directory (/_internal/cluster/pod/admin/mailbox-move-commit), atomically switches users.homeserver in MariaDB inside a transaction (CompleteMailboxMove), and releases the cutover lock.
  4. 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.
Ensure matching data_partitions paths if pods use non-default roots

Every 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 (PermSystemAdmin required):
    curl -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}'
    Returns 202 Accepted with the queued job JSON, 400 for same or disabled target pod, and 409 Conflict if 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 0
    sudo hermex-admin move-mailbox alice@example.com 1 --keep-source --direct
  • MCP: Call the move_mailbox tool ({"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​

  1. 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 ports 25, 80, 110, 143, 443, 465, 587, 993, 995, and 4190).
  2. 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/health
    curl -sk -o /dev/null -w '%{http_code}\n' -X POST https://mail.example.com/_internal/cluster/pod/admin/mailbox-move-stage
  3. Verify cluster health, account routing, and mailbox integrity:
    sudo hermex-admin status
    sudo hermex-admin show-user alice@example.com
    sudo hermex-admin check-mailbox all
  4. Sign in via Webmail, IMAP (993), and ActiveSync/EWS against a moved user (alice@example.com now on Pod 1) while connecting through Pod 0 or the edge load balancer, send a test message to an account still on Pod 0, and confirm delivery in both directions.