Skip to content

Deploying MinIO distributed mode (4-node, erasure-coded) on Ubuntu 22.04

Stand up a 4-node MinIO cluster on Ubuntu 22.04 with EC:2 erasure coding, TLS, IAM accounts, bucket lifecycle policies, and a load-balanced S3 endpoint.

You shipped a single-node MinIO last quarter to absorb application uploads and Restic backups. It worked. Then the node ran out of disk during a release, the application started returning 500s on every PUT, and you spent the evening growing an LVM volume and praying nothing else was writing while you resized. The fix isn’t a bigger node — the fix is the four-node distributed mode that MinIO was actually designed for: erasure coding across drives, online tolerance for one node down, and a load balancer in front so the client doesn’t care which node it hits.

What’s happening

A single-node MinIO is, by design, not highly available. It’s a process that serves S3 on top of a filesystem. The filesystem fills up, the process dies, or the node reboots — and the bucket is gone for that window. Distributed mode is structurally different: MinIO server is launched with a list of N hosts and M drives per host (NxM endpoints in MinIO terms), it computes an erasure-coded layout (default EC:4 across 16 drives — 12 data + 4 parity), and every object written is fragmented and distributed across the N nodes. The math: for a 4-node cluster with 4 drives each (16 total drives), the default EC:4 means you can lose up to 4 drives or 1 entire node and the cluster keeps serving reads and writes. You don’t get this by accident — you get it by launching MinIO with the right endpoint list, sticking a load balancer in front that health-checks /minio/health/cluster, and treating drives as immutable members of the cluster (no swapping disk paths after the fact).

The four-node layout is the practical floor. Three nodes give you EC:2 (one node tolerance, but you can’t lose a drive on a surviving node during recovery). Four nodes give you headroom — and four matches most rack-density and zone-distribution patterns. We run this on Ubuntu 22.04 because the package ecosystem is predictable, the kernel is recent enough for io_uring on XFS, and the AppArmor profiles for MinIO are easy to whitelist.

How to verify

After the installer runs on all four nodes, cluster health from any node:

mc admin info local
# Server cluster: 4 servers
# Drives: 16 ok, 0 offline
# Pools: 1
# Status: Online

Erasure-coding parity (should report EC:4 with the default 4x4 layout):

mc admin info local --json | jq '.info.servers[0].state, .info.parity'

Try writing and reading from each node IP — they should all serve identical content:

mc alias set node1 https://10.20.0.11:9000 admin "${ROOT_PASSWORD}"
mc alias set node2 https://10.20.0.12:9000 admin "${ROOT_PASSWORD}"
echo "healthcheck-$(date +%s)" > /tmp/probe
mc cp /tmp/probe node1/sysprobe/probe
mc cat node2/sysprobe/probe

Cluster health endpoint that HAProxy will hit (returns 200 only when the node is part of a quorate cluster):

curl -sk https://10.20.0.11:9000/minio/health/cluster -o /dev/null -w '%{http_code}\n'
# 200

Pull one node out — systemctl stop minio on node3 — and confirm the other three keep serving the bucket. If a single node-stop takes the bucket offline, the endpoint list is wrong (you almost certainly launched MinIO pointing at one host’s drives only).

The fix

Save the script as /root/setup-minio-node.sh and run it on each of the four nodes after editing the NODE_IP, PEER_IPS, and ROOT_PASSWORD variables at the top. The installer covers: base hardening (UFW, fail2ban, unattended-upgrades, SSH key-only), XFS formatting on four data drives per node (the recommended FS for MinIO), MinIO binary + systemd unit with the distributed endpoint list, internal TLS using a private CA (you can swap in Let’s Encrypt later), mc client installed and aliased, a sample bucket with versioning and an ILM lifecycle policy that expires noncurrent versions after 30 days, an IAM user with a scoped policy, and a brief HAProxy snippet to drop on a separate load-balancer node (HAProxy is not co-located with MinIO).

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

### Ubuntu 22.04 MinIO distributed-mode installer (4-node, EC:4)
### Run on each of the 4 nodes after editing the variables below
### Assumes 4 dedicated data drives mounted on /mnt/disk{1..4}

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

# === EDIT PER NODE ===
NODE_IP="10.20.0.11"      # this node's private IP
PEER_IPS=("10.20.0.11" "10.20.0.12" "10.20.0.13" "10.20.0.14")
ROOT_USER="admin"
ROOT_PASSWORD="CHANGE_ME_LONG_RANDOM_64CHAR"
DOMAIN="s3.internal.example.com"
DATA_DRIVES=("/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde")
# =====================

echo
echo "========================================"
echo "MinIO node ${NODE_IP}"
echo "========================================"
echo

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get -y update
apt-get -y upgrade
apt-get -y install \
  curl wget gnupg ca-certificates jq xfsprogs lvm2 \
  ufw fail2ban unattended-upgrades apt-listchanges \
  chrony lsof net-tools dnsutils tcpdump socat \
  apparmor apparmor-utils

systemctl enable --now chrony

echo "==> Unattended security updates"
cat > /etc/apt/apt.conf.d/52unattended-upgrades-local <<'APT'
Unattended-Upgrade::Origins-Pattern {
  "origin=Ubuntu,codename=${distro_codename},label=Ubuntu-Security";
  "origin=Ubuntu,codename=${distro_codename}-security";
};
Unattended-Upgrade::Automatic-Reboot "false";
APT
dpkg-reconfigure -fnoninteractive unattended-upgrades

echo "==> SSH key-only"
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 ssh

echo "==> fail2ban"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban

echo "==> UFW (allow internal, drop everything else)"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
for ip in "${PEER_IPS[@]}"; do
  ufw allow from "${ip}" to any port 9000 proto tcp
  ufw allow from "${ip}" to any port 9001 proto tcp
done
# allow LB subnet to reach 9000 (adjust to your LB CIDR)
ufw allow from 10.20.1.0/24 to any port 9000 proto tcp
ufw --force enable

echo "==> Kernel/sysctl for object storage workload"
cat > /etc/sysctl.d/99-minio.conf <<'SYSCTL'
fs.file-max = 4194304
vm.swappiness = 1
vm.dirty_background_ratio = 5
vm.dirty_ratio = 20
net.core.somaxconn = 8192
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535
SYSCTL
sysctl --system

cat > /etc/security/limits.d/99-minio.conf <<'LIMITS'
minio-user soft nofile 1048576
minio-user hard nofile 1048576
minio-user soft nproc 65535
minio-user hard nproc 65535
LIMITS

echo "==> Creating minio-user"
if ! id minio-user >/dev/null 2>&1; then
  groupadd -r minio-user
  useradd -M -r -g minio-user -s /sbin/nologin minio-user
fi

echo "==> Formatting and mounting data drives as XFS"
for i in "${!DATA_DRIVES[@]}"; do
  DRIVE="${DATA_DRIVES[$i]}"
  MOUNT="/mnt/disk$((i+1))"
  if [[ ! -b "${DRIVE}" ]]; then
    echo "WARN: ${DRIVE} not found — skipping. Edit DATA_DRIVES."
    continue
  fi
  if ! blkid "${DRIVE}" >/dev/null 2>&1; then
    mkfs.xfs -f -L "minio-disk$((i+1))" "${DRIVE}"
  fi
  mkdir -p "${MOUNT}"
  UUID=$(blkid -s UUID -o value "${DRIVE}")
  if ! grep -q "${UUID}" /etc/fstab; then
    echo "UUID=${UUID} ${MOUNT} xfs defaults,noatime,nodiratime,inode64 0 2" >> /etc/fstab
  fi
  mount "${MOUNT}" 2>/dev/null || true
  chown minio-user:minio-user "${MOUNT}"
done

echo "==> Downloading MinIO binary"
MINIO_VERSION="RELEASE.2026-04-15T00-00-00Z"
curl -sSL "https://dl.min.io/server/minio/release/linux-amd64/minio" \
  -o /usr/local/bin/minio
chmod +x /usr/local/bin/minio

curl -sSL "https://dl.min.io/client/mc/release/linux-amd64/mc" \
  -o /usr/local/bin/mc
chmod +x /usr/local/bin/mc

echo "==> Internal TLS (private CA generated on node1 only; copy to peers)"
mkdir -p /etc/minio/certs/CAs
if [[ "${NODE_IP}" == "${PEER_IPS[0]}" ]]; then
  if [[ ! -f /etc/minio/certs/CAs/private-ca.crt ]]; then
    openssl req -x509 -newkey rsa:4096 -nodes \
      -keyout /etc/minio/certs/CAs/private-ca.key \
      -out /etc/minio/certs/CAs/private-ca.crt \
      -days 3650 \
      -subj "/CN=MinIO Private CA/O=Internal"
  fi
  # SAN list = all node IPs + DNS name behind LB
  SAN_LIST=""
  for ip in "${PEER_IPS[@]}"; do
    SAN_LIST+="IP:${ip},"
  done
  SAN_LIST+="DNS:${DOMAIN},DNS:*.${DOMAIN},IP:127.0.0.1"

  openssl req -newkey rsa:4096 -nodes \
    -keyout /etc/minio/certs/private.key \
    -out /etc/minio/certs/server.csr \
    -subj "/CN=${DOMAIN}/O=MinIO Cluster" \
    -addext "subjectAltName=${SAN_LIST}"

  openssl x509 -req \
    -in /etc/minio/certs/server.csr \
    -CA /etc/minio/certs/CAs/private-ca.crt \
    -CAkey /etc/minio/certs/CAs/private-ca.key \
    -CAcreateserial \
    -out /etc/minio/certs/public.crt \
    -days 825 \
    -extfile <(printf "subjectAltName=%s" "${SAN_LIST}")

  rm -f /etc/minio/certs/server.csr
  echo
  echo "NOTE: Copy /etc/minio/certs/{public.crt,private.key,CAs/private-ca.crt}"
  echo "from this node to the other 3 nodes at the same paths before continuing."
  echo "Suggested: rsync -av /etc/minio/certs/ peer:/etc/minio/certs/"
  echo
fi

chown -R minio-user:minio-user /etc/minio

echo "==> MinIO environment file"
DRIVES_GLOB="https://node{1...4}.${DOMAIN}/mnt/disk{1...4}"
# alternative: ${PEER_IPS[0]} pattern when DNS isn't ready
mkdir -p /etc/default
cat > /etc/default/minio <<EOF
MINIO_ROOT_USER="${ROOT_USER}"
MINIO_ROOT_PASSWORD="${ROOT_PASSWORD}"
MINIO_VOLUMES="${DRIVES_GLOB}"
MINIO_OPTS="--address :9000 --console-address :9001 --certs-dir /etc/minio/certs"
MINIO_SERVER_URL="https://${DOMAIN}"
MINIO_BROWSER_REDIRECT_URL="https://console.${DOMAIN}"
MINIO_PROMETHEUS_AUTH_TYPE="public"
MINIO_API_REQUESTS_MAX="1600"
MINIO_API_REQUESTS_DEADLINE="10s"
EOF

chmod 640 /etc/default/minio
chown root:minio-user /etc/default/minio

echo "==> /etc/hosts entries for peer node DNS"
for i in "${!PEER_IPS[@]}"; do
  HOST="node$((i+1)).${DOMAIN}"
  if ! grep -q "${HOST}" /etc/hosts; then
    echo "${PEER_IPS[$i]}  ${HOST}" >> /etc/hosts
  fi
done

echo "==> systemd unit"
cat > /etc/systemd/system/minio.service <<'MINIO'
[Unit]
Description=MinIO
Documentation=https://min.io/docs/
After=network-online.target
Wants=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio
AssertFileNotEmpty=/etc/default/minio

[Service]
Type=notify
User=minio-user
Group=minio-user
EnvironmentFile=-/etc/default/minio
ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES
Restart=always
LimitNOFILE=1048576
LimitNPROC=65535
TimeoutStopSec=120
TasksMax=infinity
SendSIGKILL=no
OOMScoreAdjust=-1000

[Install]
WantedBy=multi-user.target
MINIO

systemctl daemon-reload
systemctl enable minio

echo
echo "==> Pre-start checklist on this node:"
echo "    - Drives mounted: $(mount | grep -c /mnt/disk)/4"
echo "    - TLS files present: $(ls /etc/minio/certs/public.crt 2>/dev/null && echo yes || echo NO)"
echo "    - Peer DNS resolves: $(getent hosts node2.${DOMAIN} >/dev/null && echo yes || echo NO)"
echo

echo "==> Starting MinIO (will hang waiting for peers — that's normal until all 4 are running)"
systemctl start minio || true

echo
echo "========================================"
echo "Wait until all 4 nodes have started MinIO,"
echo "then run on node1 only:"
echo "========================================"
echo
cat <<INIT
mc alias set local https://${PEER_IPS[0]}:9000 ${ROOT_USER} '${ROOT_PASSWORD}' --insecure

# Create application bucket with versioning + ILM
mc mb local/app-uploads --insecure
mc version enable local/app-uploads --insecure
mc ilm rule add --noncurrent-expire-days 30 local/app-uploads --insecure

# Create scoped IAM user for the application
mc admin user add local app-user '$(openssl rand -hex 32)' --insecure
cat > /tmp/app-policy.json <<'POLICY'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject","s3:PutObject","s3:DeleteObject","s3:ListBucket"],
      "Resource": ["arn:aws:s3:::app-uploads","arn:aws:s3:::app-uploads/*"]
    }
  ]
}
POLICY
mc admin policy create local app-rw /tmp/app-policy.json --insecure
mc admin policy attach local app-rw --user app-user --insecure

# Verify
mc admin info local --insecure
INIT

echo
echo "========================================"
echo "HAProxy snippet for the load-balancer node:"
echo "========================================"
echo
cat <<'HAPROXY'
# /etc/haproxy/haproxy.cfg on the LB node
frontend s3
  bind *:443 ssl crt /etc/haproxy/certs/s3.pem
  mode http
  option httplog
  default_backend minio_servers

backend minio_servers
  mode http
  balance leastconn
  option httpchk GET /minio/health/cluster
  http-check expect status 200
  default-server inter 5s fall 3 rise 2 ssl verify none
  server node1 10.20.0.11:9000 check
  server node2 10.20.0.12:9000 check
  server node3 10.20.0.13:9000 check
  server node4 10.20.0.14:9000 check
HAPROXY

echo
echo "========================================"
echo "DONE on this node."
echo "========================================"

Make it executable and run on each node, then run the post-init block on node1 only:

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

Once mc admin info local reports four servers and sixteen drives online, run the post-init block on node1: bucket creation with versioning, ILM policy for noncurrent-version expiry, and a scoped IAM user. Then point HAProxy at the four nodes using /minio/health/cluster as the health check — that endpoint returns 200 only when the node is part of a quorate cluster, which is the right signal for a load balancer to use. A drill: stop MinIO on node3, write a file through HAProxy, restart node3, confirm the file is intact. If anything is silent or partial, your endpoint list is wrong.

Treat drive failures as a runbook, not an emergency: replace a single drive with mc admin heal start ALIAS/ and let MinIO rebuild parity. Replace a whole node by reusing the same hostname/IP, mounting fresh empty drives, and starting MinIO with the same MINIO_VOLUMES value — the cluster recognizes the gap and heals.

Run distributed MinIO on Stack Harbor’s managed cloud compute with drive monitoring, EC parity alerts, and patching baked in under environment management — or scope a deployment if you’d rather we plan capacity, zones, and lifecycle policies up front.