You run a single-node Mailcow for 80 tenants. The host throws a kernel panic during business hours, mail is down for two hours while you bring up a fresh VM, restore last night’s mailroot, replay the missing 14 hours from backup MX, and field calls from customers who saw bounces. The post-mortem is short: Mailcow on a single host is a single point of failure, and the cheap version of HA — “we’ll restore from snapshot” — is not HA, it’s a downtime budget. A real two-node Mailcow with a DRBD-replicated mailroot, a floating VIP via keepalived, and a tested failover drill is the next step up, and it does not require redesigning the platform.
What’s happening
Mailcow is a docker-compose stack — Postfix, Dovecot, Rspamd, SOGo, Redis, MariaDB, ClamAV, a couple of nginx layers — wired together with a single bind mount called the mailroot (/var/lib/docker/volumes/... and the data volumes underneath /opt/mailcow-dockerized). All persistent state lives in that tree: maildirs, the SQL database, the Rspamd Redis, DKIM keys, attachment cache, certificates. To survive a host loss, the next host needs that tree as it was at the failure boundary, then to start the same compose stack and own the IPs the world sends mail to.
Two-node active/passive with DRBD solves it cleanly. DRBD 9 replicates a block device synchronously between the primary and secondary at the kernel level — every write to the primary is mirrored before it’s acknowledged. The mailroot lives on top of the DRBD device, mounted only on the active node. keepalived holds a VRRP-managed virtual IP and a docker-compose lifecycle script: when the active node dies, the secondary promotes the DRBD volume, mounts it, starts the compose stack, and takes the VIP — typically inside 45 to 90 seconds depending on how aggressively you tuned VRRP. It is not zero downtime, but it is bounded downtime with no data loss and no operator paged at 3 AM to manually restore.
The trade-offs are honest. DRBD is synchronous, so write latency is the inter-node round-trip — keep the two nodes on the same low-latency private network, not across regions. Quorum matters: a two-node DRBD setup will split-brain if you let it, so you need a third arbiter (DRBD’s diskless witness, or a third node running only the DRBD quorum daemon) and a clear “victim” policy. Don’t run active/active. Don’t try to run both compose stacks at once “for load.” It is one mail server with a hot standby, not two mail servers.
How to verify
Cluster status from either node:
drbdadm status mailroot
# mailroot role:Primary
# disk:UpToDate
# peer role:Secondary
# replication:Established peer-disk:UpToDate
If peer-disk is anything other than UpToDate, you are not protected — start there before any other check.
keepalived VRRP state:
ip -4 addr show eth0 | grep -E "10\.10\.0\.50"
journalctl -u keepalived -n 50 --no-pager | grep -E "(STATE|VIP)"
Only the active node should hold the VIP. If both nodes hold it, fence the secondary immediately — split-brain on the network layer alone will corrupt mailroot once writes resume.
Mailcow stack on the active node:
cd /opt/mailcow-dockerized && docker compose ps --status running
docker compose logs --tail 50 postfix-mailcow | grep -iE "(error|warning)"
Confirm the mailroot is mounted from the DRBD device, not the local disk:
mount | grep /var/lib/docker
findmnt /var/lib/docker/volumes
If the path resolves to /dev/sda2 instead of /dev/drbd0 on the active node, the mailroot is not replicated — you are running single-node Mailcow with extra moving parts.
The fix
Save the installer as /root/setup-mailcow-ha.sh and run it on each of the two nodes after editing the variables at the top. It performs the full install on Debian 12: DRBD 9 from the official LINBIT repo, an LVM volume carved out of a dedicated data disk, the docker-compose Mailcow stack pinned to the latest stable, keepalived with a VRRP virtual IP and a notify script that drives docker compose up/down on state transitions, fail2ban tuned for SMTP/IMAP brute force, and a /etc/drbd.d/mailroot.res resource with a diskless witness pointing at a third host you provision separately.
#!/usr/bin/env bash
set -euo pipefail
### Debian 12 Mailcow HA installer — active/passive with DRBD + keepalived
### Run on each of the 2 nodes after editing variables below
### A third arbiter host (witness) MUST exist for DRBD quorum
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT PER NODE ===
NODE_NAME="mail01" # mail01 or mail02
NODE_IP="10.10.0.41" # this node's private IP
PEER_IP="10.10.0.42" # the other node's private IP
WITNESS_IP="10.10.0.43" # arbiter (diskless DRBD witness)
VIRTUAL_IP="10.10.0.40" # keepalived VIP — clients send mail here
DATA_DISK="/dev/sdb" # raw device dedicated to mailroot
PUBLIC_FQDN="mail.example.com" # MX target
ROLE_PRIORITY=110 # 110 on preferred primary, 100 on standby
# =====================
echo
echo "========================================"
echo "Mailcow HA node ${NODE_NAME} (${NODE_IP})"
echo "========================================"
echo
echo "==> Base packages"
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y install \
curl wget gnupg ca-certificates lsb-release software-properties-common \
vim jq tar gzip iproute2 net-tools chrony \
fail2ban unattended-upgrades lvm2 xfsprogs
systemctl enable --now chronyd || systemctl enable --now chrony
echo "==> Hardening SSH"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart sshd
echo "==> Unattended security upgrades"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTO'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
AUTO
echo "==> Docker engine"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg \
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
> /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
systemctl enable docker
# do NOT start docker yet; mailroot is not mounted
echo "==> DRBD 9 (LINBIT repo)"
curl -fsSL https://packages.linbit.com/public/keyring.gpg \
> /etc/apt/keyrings/linbit.gpg
echo "deb [signed-by=/etc/apt/keyrings/linbit.gpg] \
https://packages.linbit.com/public/debian bookworm drbd-9" \
> /etc/apt/sources.list.d/linbit.list
apt-get update
apt-get -y install drbd-utils drbd-dkms
echo "==> LVM volume for mailroot"
if ! pvs | grep -q "${DATA_DISK}"; then
pvcreate -ff -y "${DATA_DISK}"
vgcreate mailvg "${DATA_DISK}"
lvcreate -L 400G -n mailroot mailvg
fi
echo "==> DRBD resource"
cat > /etc/drbd.d/global_common.conf <<'GLOBAL'
global {
usage-count no;
}
common {
net {
protocol C;
cram-hmac-alg sha1;
shared-secret "CHANGE_ME_DRBD";
after-sb-0pri discard-zero-changes;
after-sb-1pri discard-secondary;
after-sb-2pri disconnect;
}
options {
quorum majority;
on-no-quorum suspend-io;
}
}
GLOBAL
cat > /etc/drbd.d/mailroot.res <<EOF
resource mailroot {
device /dev/drbd0;
disk /dev/mailvg/mailroot;
meta-disk internal;
on mail01 {
address ${NODE_IP}:7788;
node-id 0;
}
on mail02 {
address ${PEER_IP}:7788;
node-id 1;
}
on witness {
address ${WITNESS_IP}:7788;
node-id 2;
volume 0 {
disk none;
}
}
connection-mesh {
hosts mail01 mail02 witness;
}
}
EOF
echo "==> DRBD bring-up (initial primary on mail01 only)"
drbdadm create-md mailroot || true
systemctl enable --now drbd
if [[ "${NODE_NAME}" == "mail01" ]]; then
drbdadm up mailroot
sleep 2
drbdadm primary --force mailroot || true
mkfs.xfs -f -L mailroot /dev/drbd0
mkdir -p /var/lib/docker
mount /dev/drbd0 /var/lib/docker
else
drbdadm up mailroot
fi
echo "==> Mailcow checkout (active node clones; passive will mount the same FS later)"
if [[ "${NODE_NAME}" == "mail01" ]]; then
cd /opt
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
./generate_config.sh <<INPUTS
${PUBLIC_FQDN}
y
INPUTS
fi
echo "==> keepalived"
apt-get -y install keepalived
cat > /etc/keepalived/keepalived.conf <<EOF
global_defs {
router_id ${NODE_NAME}
enable_script_security
script_user root
}
vrrp_script chk_drbd {
script "/usr/local/sbin/check-mailroot.sh"
interval 5
rise 2
fall 2
weight -50
}
vrrp_instance VI_MAILCOW {
state BACKUP
interface eth0
virtual_router_id 51
priority ${ROLE_PRIORITY}
advert_int 1
nopreempt
unicast_src_ip ${NODE_IP}
unicast_peer {
${PEER_IP}
}
authentication {
auth_type PASS
auth_pass CHANGE_ME_VRRP
}
virtual_ipaddress {
${VIRTUAL_IP}/24
}
track_script {
chk_drbd
}
notify_master "/usr/local/sbin/keepalived-master.sh"
notify_backup "/usr/local/sbin/keepalived-backup.sh"
notify_fault "/usr/local/sbin/keepalived-backup.sh"
}
EOF
cat > /usr/local/sbin/check-mailroot.sh <<'CHECK'
#!/usr/bin/env bash
# Healthy only if local DRBD disk is UpToDate and mailroot can be mounted
state="$(drbdadm status mailroot 2>/dev/null | head -2 | tail -1 | awk '{print $2}')"
[[ "${state}" == "disk:UpToDate" ]] || exit 1
exit 0
CHECK
cat > /usr/local/sbin/keepalived-master.sh <<'MASTER'
#!/usr/bin/env bash
set -euxo pipefail
logger -t mailcow-ha "Transition to MASTER"
# 1. Promote DRBD
drbdadm primary mailroot
# 2. Mount mailroot
mkdir -p /var/lib/docker
mountpoint -q /var/lib/docker || mount /dev/drbd0 /var/lib/docker
# 3. Start docker + mailcow
systemctl start docker
cd /opt/mailcow-dockerized
docker compose up -d
MASTER
cat > /usr/local/sbin/keepalived-backup.sh <<'BACKUP'
#!/usr/bin/env bash
set -euxo pipefail
logger -t mailcow-ha "Transition to BACKUP/FAULT"
# 1. Stop mailcow + docker
cd /opt/mailcow-dockerized 2>/dev/null && docker compose down || true
systemctl stop docker || true
# 2. Unmount mailroot
umount /var/lib/docker || true
# 3. Demote DRBD
drbdadm secondary mailroot || true
BACKUP
chmod 700 /usr/local/sbin/check-mailroot.sh \
/usr/local/sbin/keepalived-master.sh \
/usr/local/sbin/keepalived-backup.sh
systemctl enable --now keepalived
echo "==> fail2ban (SMTP/IMAP)"
cat > /etc/fail2ban/jail.d/mailcow.local <<'FAIL2BAN'
[postfix-sasl]
enabled = true
maxretry = 5
findtime = 10m
bantime = 1h
[dovecot]
enabled = true
maxretry = 5
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo
echo "========================================"
echo "DONE on ${NODE_NAME}"
echo "========================================"
echo
echo "DRBD:"
drbdadm status mailroot || true
echo
echo "keepalived:"
ip -4 addr show eth0 | grep -E "${VIRTUAL_IP}" || echo " VIP not on this node"
echo
echo "Next steps:"
echo " - On the witness host: install drbd-utils only, drbdadm up mailroot (diskless)"
echo " - On mail02: nothing else; failover will mount and start the stack"
echo " - From mail01: docker compose up -d, then run the failover drill"
Make it executable and run on both nodes in order:
chmod 700 /root/setup-mailcow-ha.sh
/root/setup-mailcow-ha.sh
Once both nodes are up and DRBD reports UpToDate on each peer, run the failover drill before any production cutover. From the active node:
# Drill 1 — graceful failover
systemctl stop keepalived
# watch the VIP move; on the passive node:
journalctl -u keepalived -f
# confirm mailroot mounts, compose starts, VIP arrives, port 25 listens
# Drill 2 — hard failover (simulates host loss)
echo b > /proc/sysrq-trigger # only on the active node, only in a drill window
The drill is the deliverable. A configuration that works in drbdadm status but has never been failed over is a configuration that has never been tested. Run the drill on day one, then quarterly. Keep two log lines next to your runbook: the VIP transition time (keepalived) and the time the first 25/tcp connection succeeded on the new active node. That number is your real failover SLO.
For tenants who need bounded mail downtime without operating the cluster yourself, our team runs Mailcow HA under Managed Cloud Ops with quarterly failover drills and DRBD-level monitoring in the monitoring plane — start a scoping call.