Skip to content

Deploying Postal as a transactional relay cluster (active/active) on AlmaLinux 9

Two-node Postal cluster on AlmaLinux 9 with shared MariaDB Galera + RabbitMQ, HAProxy in front, DKIM keypair per domain, and webhook delivery for bounce handling.

You ran single-node Postal for a year. It paid for itself in upstream fees the first month. Then the host’s NIC flapped during a hypervisor migration, and for forty minutes every password reset, every order confirmation, every magic-link login lived in a queue the application couldn’t see. You decide one Postal node is not enough. This article stands up two of them — both sending, both receiving, sharing one MariaDB Galera cluster and one RabbitMQ cluster, fronted by HAProxy. A failure of either node drops capacity in half, not to zero.

What’s happening

Postal’s storage model is the constraint. Postal stores message metadata, click/open tracking, suppression lists, and routing configuration in MariaDB; the message bodies live in MySQL too (per-server messages databases). Active/active means two Postal application nodes pointing at the same MariaDB cluster, the same RabbitMQ broker, and the same disk-backed object store if you’re using one. We use MariaDB Galera (three nodes, synchronous multi-primary replication) so either Postal node can write without a primary-failover step. RabbitMQ runs in mirrored-queue mode across two nodes — the Postal queue layer is happy with either as long as both are reachable.

Three things make this topology work:

  • Stable smtp_helo_name per Postal node. Each node advertises its own hostname (postal-a.relay.example.com, postal-b.relay.example.com) and has its own forward and reverse DNS. Receivers see consistent helo + rDNS + IP and reputation accrues per host. HAProxy fronts inbound SMTP (port 25 from the world arriving for return-path bounces, and port 587 from your applications submitting outbound), but each Postal node sends out under its own identity on outbound port 25 to remote MX hosts.
  • DKIM keypair per sending domain, not per node. Both Postal nodes serve the same DKIM private key for the same domain via the database. The DNS TXT record at <selector>._domainkey.<domain> is the public half. Rotate by adding a second selector, updating Postal’s domain configuration, waiting for DNS to propagate, then deactivating the old key.
  • Suppression list shared in MariaDB. Either node bouncing a recipient writes to the same suppression table, so the other node refuses sends to that address within the same TTL. This is the killer feature of active/active — you can’t get it from two independent Postal instances.

What we deploy: two AlmaLinux 9 nodes (postal-a, postal-b) running Postal v3 in Docker, a separate three-node MariaDB Galera cluster, a two-node RabbitMQ cluster with mirrored queues, and one HAProxy box (you can run keepalived/VRRP on a pair if availability matters more than simplicity). For brevity the installer below covers a single Postal application node; the second node runs the identical script with a different NODE_NAME and HELO_NAME. Galera and RabbitMQ are assumed already provisioned — they are workloads in their own right and outside the scope of this article.

How to verify

After both Postal nodes are up:

# 1. Both nodes are healthy and pointing at the same DB
postal status
# Should report all workers green on each node

# 2. The DB sees both nodes' worker hostnames
mysql -h galera.internal -uroot -p postal -e "SELECT DISTINCT hostname FROM workers;"
# Two rows: postal-a, postal-b

# 3. RabbitMQ shows both nodes joined to the cluster
rabbitmqctl cluster_status
# Disk nodes: [postal-rmq-a, postal-rmq-b], Running: same

# 4. End-to-end send from outside via HAProxy
swaks --to yourself@example.com \
      --from notify@your-domain.example \
      --server postal.relay.example.com:587 \
      --auth-user '<credential>' --auth-password '<token>'
# Then check the message log:
mysql -h galera.internal -uroot -p postal -e \
  "SELECT id, server_id, status, last_attempted_at FROM messages \
   ORDER BY id DESC LIMIT 5;"

# 5. DKIM signature appears on outbound mail
swaks --to deliverability-check@example.com --server postal.relay.example.com:587 \
      --auth-user '<credential>' --auth-password '<token>' \
      --header "Subject: dkim test" --body "test"
# Examine headers at the recipient — DKIM-Signature: with the correct d= and s=

If the DKIM signature appears with a d= you didn’t expect or no signature at all, the domain isn’t configured in Postal’s UI under the right “organization”, or the selector public key in DNS doesn’t match the private key in Postal’s database.

The fix

Save as /root/setup-postal-node.sh and edit the top variables on each Postal node. Galera and RabbitMQ are dependencies — point at your existing clusters. The script installs Docker, deploys Postal v3 via the official compose, configures helo/rDNS, and registers the node with the shared database.

#!/usr/bin/env bash
set -euo pipefail

### AlmaLinux 9 Postal node installer (active/active topology)
### Run on each Postal node, editing the variables below per node.
### Prerequisites: MariaDB Galera and RabbitMQ clusters reachable on the private net.

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

# === EDIT PER NODE ===
NODE_NAME="postal-a"
HELO_NAME="postal-a.relay.example.com"
NODE_IP="10.20.0.11"
# Shared infrastructure (same on every Postal node)
DB_HOST="galera.internal.example"
DB_USER="postal"
DB_PASS="CHANGE_ME_DB"
RMQ_HOST="postal-rmq.internal.example"
RMQ_USER="postal"
RMQ_PASS="CHANGE_ME_RMQ"
# Web admin
WEB_HOSTNAME="postal-admin.relay.example.com"
SIGNING_KEY_PATH="/opt/postal/config/signing.key"
SMTP_REGION_PUBLIC_IP="<this-node-public-ip>"
# =====================

echo "==> Base OS"
dnf -y update
dnf -y install epel-release
dnf -y install vim curl wget chrony fail2ban dnf-automatic \
  policycoreutils-python-utils lsof tcpdump bind-utils jq socat \
  iproute net-tools

systemctl enable --now chronyd

echo "==> Hostname + helo"
hostnamectl set-hostname "${HELO_NAME}"
echo "${NODE_IP} ${HELO_NAME}" >> /etc/hosts

echo "==> SELinux + sysctl"
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
setenforce 1 || true

cat > /etc/sysctl.d/99-postal.conf <<'EOF'
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.ip_local_port_range = 10240 65535
fs.file-max = 1048576
EOF
sysctl --system

echo "==> SSH hardening"
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 "==> fail2ban + auto updates"
cat > /etc/fail2ban/jail.d/sshd.local <<'EOF'
[sshd]
enabled = true
maxretry = 4
findtime = 10m
bantime = 1h
EOF
systemctl enable --now fail2ban

cat > /etc/dnf/automatic.conf <<'EOF'
[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes
[emitters]
emit_via = stdio
EOF
systemctl enable --now dnf-automatic.timer

echo "==> Installing Docker"
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable --now docker

echo "==> Generating Postal signing key (if missing)"
mkdir -p /opt/postal/config /opt/postal/storage
chown -R 0:0 /opt/postal
if [[ ! -f "${SIGNING_KEY_PATH}" ]]; then
  openssl genrsa -out "${SIGNING_KEY_PATH}" 2048
  chmod 600 "${SIGNING_KEY_PATH}"
fi
# The signing key must be IDENTICAL on every Postal node — copy from postal-a to postal-b
# scp postal-a:${SIGNING_KEY_PATH} postal-b:${SIGNING_KEY_PATH}

echo "==> Writing postal.yml"
cat > /opt/postal/config/postal.yml <<EOF
version: 2

postal:
  web_hostname: ${WEB_HOSTNAME}
  smtp_hostname: ${HELO_NAME}
  use_ip_pools: false
  default_maximum_delivery_attempts: 18
  default_maximum_hold_expiry_days: 7

web_server:
  bind_address: 0.0.0.0
  port: 5000
  max_threads: 8

smtp_server:
  port: 25
  tls_enabled: true
  tls_certificate_path: /config/smtp.crt
  tls_private_key_path: /config/smtp.key
  proxy_protocol: false
  max_message_size: 25

main_db:
  host: ${DB_HOST}
  port: 3306
  username: ${DB_USER}
  password: ${DB_PASS}
  database: postal

message_db:
  host: ${DB_HOST}
  port: 3306
  username: ${DB_USER}
  password: ${DB_PASS}
  prefix: postal

rabbitmq:
  host: ${RMQ_HOST}
  port: 5672
  username: ${RMQ_USER}
  password: ${RMQ_PASS}
  vhost: /postal

dns:
  mx_records:
    - mx1.relay.example.com
    - mx2.relay.example.com
  smtp_server_hostname: relay.example.com
  spf_include: spf.relay.example.com
  return_path_prefix: psrp
  route_domain: routes.relay.example.com
  track_domain: track.relay.example.com

smtp:
  host: ${HELO_NAME}
  port: 25
  username: ""
  password: ""
  from_name: Postal
  from_address: postal@${WEB_HOSTNAME}

rails:
  secret_key: $(openssl rand -hex 64)

workers:
  quantity: 4
EOF

chmod 600 /opt/postal/config/postal.yml

echo "==> Writing docker-compose.yml"
cat > /opt/postal/docker-compose.yml <<'EOF'
services:
  postal-web:
    image: ghcr.io/postalserver/postal:3
    restart: always
    command: postal web-server
    volumes:
      - ./config:/config
      - ./storage:/storage
    network_mode: host

  postal-smtp:
    image: ghcr.io/postalserver/postal:3
    restart: always
    command: postal smtp-server
    volumes:
      - ./config:/config
      - ./storage:/storage
    network_mode: host
    cap_add:
      - NET_BIND_SERVICE

  postal-worker:
    image: ghcr.io/postalserver/postal:3
    restart: always
    command: postal worker
    volumes:
      - ./config:/config
      - ./storage:/storage
    network_mode: host

  postal-cron:
    image: ghcr.io/postalserver/postal:3
    restart: always
    command: postal cron
    volumes:
      - ./config:/config
      - ./storage:/storage
    network_mode: host

  postal-requeuer:
    image: ghcr.io/postalserver/postal:3
    restart: always
    command: postal requeuer
    volumes:
      - ./config:/config
      - ./storage:/storage
    network_mode: host
EOF

echo "==> First-time DB initialize (run ONCE from one Postal node only)"
echo "    On postal-a only, run:"
echo "    cd /opt/postal && docker compose run --rm postal-web postal initialize"
echo "    cd /opt/postal && docker compose run --rm postal-web postal make-user"
echo "    On postal-b, SKIP both — the shared DB is already initialized."

echo "==> Firewall"
firewall-cmd --permanent --add-port=25/tcp
firewall-cmd --permanent --add-port=587/tcp
firewall-cmd --permanent --add-port=5000/tcp
firewall-cmd --permanent --add-port=2525/tcp
firewall-cmd --reload

echo "==> Starting Postal"
cd /opt/postal
docker compose pull
docker compose up -d

echo "==> Waiting for SMTP listener"
for i in {1..60}; do
  if ss -lntp | grep -q ':25 '; then break; fi
  sleep 2
done

cat <<EOF

========================================
DONE — ${NODE_NAME}
========================================
SMTP HELO:    ${HELO_NAME}
SMTP listen:  ${SMTP_REGION_PUBLIC_IP}:25 (outbound + inbound bounces)
              ${NODE_IP}:587 (submission from apps via HAProxy)
Web admin:    ${WEB_HOSTNAME}
DB:           ${DB_HOST} (Galera, shared)
RMQ:          ${RMQ_HOST} (cluster, shared)

Next on this node:
- Verify DNS: dig +short ${HELO_NAME} A   ->  ${SMTP_REGION_PUBLIC_IP}
              dig +short -x ${SMTP_REGION_PUBLIC_IP}  ->  ${HELO_NAME}.
- TLS cert for smtp_hostname into /opt/postal/config/smtp.{crt,key}
- Add this node to HAProxy frontend pool for port 587 submission

Per-domain DKIM:
- Configure each sending domain in Postal admin → it generates a keypair
- Publish the public key at <selector>._domainkey.<domain>
- Postal serves the private key from the SHARED DB, so both nodes sign
  identically and outbound mail is verifiable from either node.
EOF

Run on postal-a, then repeat on postal-b with its own NODE_NAME, HELO_NAME, and NODE_IP. After both nodes report DONE, do the one-time database initialization from postal-a only:

chmod 700 /root/setup-postal-node.sh
/root/setup-postal-node.sh

# postal-a only:
cd /opt/postal && docker compose run --rm postal-web postal initialize
cd /opt/postal && docker compose run --rm postal-web postal make-user

Then in the Postal admin UI, create an Organization, a Server (mail server), and add each sending domain. Postal generates a DKIM keypair per domain and stores the private key in the shared MariaDB — both nodes sign identically. Publish the public half at <selector>._domainkey.<domain> along with SPF (v=spf1 include:spf.relay.example.com -all) and DMARC (v=DMARC1; p=quarantine; rua=mailto:dmarc@your-domain.example).

The HAProxy front for port 587 submission is straightforward:

frontend postal_submission
  bind :587
  mode tcp
  default_backend postal_submission_bk

backend postal_submission_bk
  mode tcp
  balance leastconn
  option tcp-check
  tcp-check connect
  tcp-check expect string 220
  server postal-a 10.20.0.11:587 check inter 5s fall 3 rise 2
  server postal-b 10.20.0.12:587 check inter 5s fall 3 rise 2

For inbound (port 25 receiving bounces back from remote MX servers), each node should have its own public IP and its own MX-or-A record — DO NOT load-balance return-path inbound through HAProxy unless your HAProxy is also reachable via the same IPs Postal uses to send. Reverse DNS must match the sending IP, full stop, or major receivers will flag you.

Operate active/active Postal under Stack Harbor’s Managed Cloud Ops with reputation monitoring, suppression-list growth alerts, and quarterly DKIM rotation — tell us your sending volume and we’ll size the cluster.