The marketing team picked Typesense for the new instant-search experience after the proof-of-concept ran for three months on a single VM with default settings. Launch is in six weeks, and the production checklist that came back from your engineering lead has three items you have not yet covered: clustering, API key management beyond a single bootstrap key, and a real backup strategy that is not “we’ll snapshot the VM.” Typesense 27.x ships with native Raft-based clustering, so the cluster part is straightforward — the trap is that the bootstrap API key has full admin scope and lives in plaintext in /etc/typesense/typesense-server.ini, and most teams never rotate it. This is the installer plus the rotation pattern that handles all three.
What’s happening
Typesense 27 runs Raft between an odd number of nodes (3 or 5 is the right answer for production) — one leader handles writes and replicates the WAL to followers, reads are served from any node. Configuration uses --nodes /etc/typesense/nodes pointing at a file with one line per peer: <ip>:<peering-port>:<api-port>. The Raft protocol takes care of election and split-brain prevention; your job is to put TLS on the public HTTP, expose Raft only on the private network, and not let the bootstrap key leak.
The API key model has three tiers: the bootstrap key (single value in the server config, has root admin scope, can create other keys); admin keys (created via the bootstrap key, also full scope, can be revoked); and search keys (scoped to specific collections and actions, what your application code should use). The rotation pattern is: never let application code touch the bootstrap key, mint admin keys for operators and search keys for services, rotate search keys quarterly with overlap, and rotate the bootstrap key whenever an admin leaves or every 12 months minimum. Rotating the bootstrap key requires a rolling restart with the new value in the config file — it cannot be done over the API.
The snapshot story: Typesense writes a hot, atomic snapshot of the data directory when you call POST /operations/snapshot?snapshot_path=/path. The snapshot is the entire on-disk state at the moment of the call, safe to copy off-host while the cluster is live. We schedule it once an hour on the leader, rclone it to S3-compatible storage with retention, and prove the restore path on a sandbox cluster monthly.
How to verify
Cluster health from each node:
TS_KEY=$(cat /etc/typesense/bootstrap.key)
for ip in 10.10.0.51 10.10.0.52 10.10.0.53; do
echo "== $ip =="
curl -sk -H "X-TYPESENSE-API-KEY: ${TS_KEY}" \
"https://${ip}:8108/health"
done
# {"ok":true}
Raft state — exactly one leader, two followers:
curl -sk -H "X-TYPESENSE-API-KEY: ${TS_KEY}" \
"https://10.10.0.51:8108/debug?stats=1" | jq '.state'
# 4 <- LEADER (1=FOLLOWER, 2=CANDIDATE, 4=LEADER on the active node)
API keys list (excludes the bootstrap key itself):
curl -sk -H "X-TYPESENSE-API-KEY: ${TS_KEY}" \
"https://10.10.0.51:8108/keys" | jq '.keys[] | {id,description,actions,collections}'
Snapshot succeeds and the artifact lands in object storage:
curl -sk -H "X-TYPESENSE-API-KEY: ${TS_KEY}" -XPOST \
"https://10.10.0.51:8108/operations/snapshot?snapshot_path=/var/lib/typesense/snapshots/manual-$(date +%s)"
ls -lh /var/lib/typesense/snapshots/
The fix
Save the script as /root/setup-typesense-node.sh and run it on each of the three nodes. The installer handles AlmaLinux 9 hardening, the official Typesense RPM, a per-node typesense-server.ini, the shared /etc/typesense/nodes peer file, a self-signed TLS cert for HTTPS (replace with a real cert for public exposure), a systemd unit with the right limits, an hourly snapshot timer that runs on the leader only, and a one-shot rotation helper at /usr/local/bin/ts-rotate-bootstrap.sh.
#!/usr/bin/env bash
set -euo pipefail
### AlmaLinux 9 Typesense 27.x 3-node cluster installer
### Run on each of the 3 nodes after editing variables below
### Raft peering port: 8107 (private), API port: 8108 (HTTPS)
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT PER NODE ===
NODE_NAME="ts01"
NODE_IP="10.10.0.51"
PEER_IPS=("10.10.0.51" "10.10.0.52" "10.10.0.53")
PEER_NAMES=("ts01" "ts02" "ts03")
CLUSTER_NAME="search-prod"
TS_VERSION="27.1"
API_PORT="8108"
PEERING_PORT="8107"
BOOTSTRAP_KEY="CHANGE_ME_LONG_RANDOM_BOOTSTRAP_AT_LEAST_32_CHARS"
S3_ENDPOINT="s3.us-east-2.wasabisys.com"
S3_BUCKET="acme-ts-snapshots"
S3_ACCESS_KEY="CHANGE_ME"
S3_SECRET_KEY="CHANGE_ME"
# =====================
echo
echo "========================================"
echo "Typesense node ${NODE_NAME} (${NODE_IP})"
echo "========================================"
echo
echo "==> Updating base OS"
dnf -y update
dnf -y install epel-release
dnf -y install vim curl wget chrony fail2ban dnf-automatic jq socat \
policycoreutils-python-utils lsof bind-utils tar gzip openssl unzip
systemctl enable --now chronyd
echo "==> SELinux enforcing"
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
setenforce 1 || true
echo "==> Kernel/sysctl"
cat > /etc/sysctl.d/99-typesense.conf <<'SYSCTL'
fs.file-max = 2097152
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
SYSCTL
sysctl --system
cat > /etc/security/limits.d/99-typesense.conf <<'LIMITS'
typesense soft nofile 65535
typesense hard nofile 65535
LIMITS
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 "==> firewalld: API public 8108/tcp, peering ${PEERING_PORT}/tcp peer-only"
dnf -y install firewalld
systemctl enable --now firewalld
firewall-cmd --permanent --add-port=${API_PORT}/tcp
firewall-cmd --permanent --new-zone=tsraft || true
firewall-cmd --permanent --zone=tsraft --add-port=${PEERING_PORT}/tcp
for p in "${PEER_IPS[@]}"; do
firewall-cmd --permanent --zone=tsraft --add-source="$p"
done
firewall-cmd --reload
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 "==> Installing Typesense ${TS_VERSION}"
dnf -y install "https://dl.typesense.org/releases/${TS_VERSION}/typesense-server-${TS_VERSION}-1.x86_64.rpm"
echo "==> /etc/typesense/nodes (Raft peer file)"
PEER_LINES=""
for i in "${!PEER_IPS[@]}"; do
PEER_LINES+="${PEER_IPS[$i]}:${PEERING_PORT}:${API_PORT}\n"
done
mkdir -p /etc/typesense
printf "${PEER_LINES}" > /etc/typesense/nodes
chown -R typesense:typesense /etc/typesense
echo "==> TLS cert (self-signed; replace for public exposure)"
mkdir -p /etc/typesense/tls
openssl req -x509 -newkey rsa:4096 -days 825 -nodes \
-subj "/CN=${NODE_NAME}/O=stackharbor" \
-addext "subjectAltName=DNS:${NODE_NAME},IP:${NODE_IP}" \
-keyout /etc/typesense/tls/server.key \
-out /etc/typesense/tls/server.crt
chown -R typesense:typesense /etc/typesense/tls
chmod 640 /etc/typesense/tls/*
echo "==> /etc/typesense/typesense-server.ini"
cat > /etc/typesense/typesense-server.ini <<EOF
[server]
api-address = ${NODE_IP}
api-port = ${API_PORT}
peering-address = ${NODE_IP}
peering-port = ${PEERING_PORT}
nodes = /etc/typesense/nodes
data-dir = /var/lib/typesense
api-key = ${BOOTSTRAP_KEY}
log-dir = /var/log/typesense
enable-cors = false
ssl-certificate = /etc/typesense/tls/server.crt
ssl-certificate-key = /etc/typesense/tls/server.key
reset-peers-on-error = false
EOF
chown root:typesense /etc/typesense/typesense-server.ini
chmod 640 /etc/typesense/typesense-server.ini
# Stash the bootstrap key on disk only — never echoed to a runtime store
echo "${BOOTSTRAP_KEY}" > /etc/typesense/bootstrap.key
chown root:root /etc/typesense/bootstrap.key
chmod 600 /etc/typesense/bootstrap.key
mkdir -p /var/lib/typesense/snapshots /var/log/typesense
chown -R typesense:typesense /var/lib/typesense /var/log/typesense
echo "==> systemd unit override (limits)"
mkdir -p /etc/systemd/system/typesense-server.service.d
cat > /etc/systemd/system/typesense-server.service.d/override.conf <<'OV'
[Service]
LimitNOFILE=65535
Restart=on-failure
RestartSec=5s
OV
systemctl daemon-reload
systemctl enable --now typesense-server
echo "==> Waiting for HTTPS on :${API_PORT}"
for i in {1..60}; do
if curl -sk -H "X-TYPESENSE-API-KEY: ${BOOTSTRAP_KEY}" \
"https://${NODE_IP}:${API_PORT}/health" >/dev/null; then break; fi
sleep 3
done
echo "==> /usr/local/bin/ts-rotate-bootstrap.sh (manual rotation helper)"
cat > /usr/local/bin/ts-rotate-bootstrap.sh <<'ROT'
#!/usr/bin/env bash
# Rotates the Typesense bootstrap key with rolling restart.
# Run on the leader; SSHs to peers in PEER_IPS to update the config and restart.
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <new-bootstrap-key>"
exit 1
fi
NEW_KEY="$1"
for ip in $(awk -F: '{print $1}' /etc/typesense/nodes); do
echo "==> Rotating on ${ip}"
ssh -o StrictHostKeyChecking=accept-new "root@${ip}" "
sed -i 's|^api-key = .*|api-key = ${NEW_KEY}|' /etc/typesense/typesense-server.ini
echo '${NEW_KEY}' > /etc/typesense/bootstrap.key
chmod 600 /etc/typesense/bootstrap.key
systemctl restart typesense-server
for i in \$(seq 1 30); do
curl -fsk -H \"X-TYPESENSE-API-KEY: ${NEW_KEY}\" \"https://${ip}:8108/health\" >/dev/null && exit 0
sleep 2
done
echo \"FAILED to come back on ${ip}\"
exit 1
"
done
echo "==> Bootstrap key rotated across all peers."
ROT
chmod 700 /usr/local/bin/ts-rotate-bootstrap.sh
echo "==> Snapshot script + hourly timer (idempotent on all nodes; only leader writes)"
cat > /usr/local/bin/ts-snapshot.sh <<'SNAP'
#!/usr/bin/env bash
set -euo pipefail
NODE_IP="$(awk -F'=' '/^api-address/ {gsub(/ /,""); print $2}' /etc/typesense/typesense-server.ini)"
KEY="$(cat /etc/typesense/bootstrap.key)"
# Skip if this node is not the leader (state=4)
STATE=$(curl -sk -H "X-TYPESENSE-API-KEY: ${KEY}" "https://${NODE_IP}:8108/debug?stats=1" | jq -r '.state // empty' || true)
if [[ "$STATE" != "4" ]]; then
echo "Not leader (state=${STATE}); skipping."
exit 0
fi
STAMP=$(date -u +"%Y%m%dT%H%M%SZ")
DEST="/var/lib/typesense/snapshots/${STAMP}"
mkdir -p "$DEST"
curl -fsk -H "X-TYPESENSE-API-KEY: ${KEY}" -XPOST \
"https://${NODE_IP}:8108/operations/snapshot?snapshot_path=${DEST}" >/dev/null
# Upload to S3 with rclone (configured via /root/.config/rclone/rclone.conf)
if command -v rclone >/dev/null; then
rclone sync "$DEST" "wasabi:acme-ts-snapshots/${STAMP}/" --transfers=4 --checkers=8
fi
# Retain last 168 snapshots locally (~7 days at hourly)
ls -dt /var/lib/typesense/snapshots/*/ 2>/dev/null \
| tail -n +169 | xargs -r rm -rf
SNAP
chmod 750 /usr/local/bin/ts-snapshot.sh
cat > /etc/systemd/system/ts-snapshot.service <<'SVC'
[Unit]
Description=Typesense hourly snapshot (leader-only)
[Service]
Type=oneshot
ExecStart=/usr/local/bin/ts-snapshot.sh
SVC
cat > /etc/systemd/system/ts-snapshot.timer <<'TMR'
[Unit]
Description=Run ts-snapshot hourly
[Timer]
OnCalendar=hourly
AccuracySec=1min
Persistent=true
[Install]
WantedBy=timers.target
TMR
systemctl daemon-reload
systemctl enable --now ts-snapshot.timer
echo "==> Optional: rclone for off-host snapshot copy"
if ! command -v rclone >/dev/null; then
dnf -y install rclone || true
fi
mkdir -p /root/.config/rclone
cat > /root/.config/rclone/rclone.conf <<EOF
[wasabi]
type = s3
provider = Wasabi
access_key_id = ${S3_ACCESS_KEY}
secret_access_key = ${S3_SECRET_KEY}
endpoint = ${S3_ENDPOINT}
acl = private
EOF
chmod 600 /root/.config/rclone/rclone.conf
echo
echo "========================================"
echo "DONE — ${NODE_NAME}"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ":(${API_PORT}|${PEERING_PORT})\b" || true
echo
echo "Health:"
curl -sk -H "X-TYPESENSE-API-KEY: ${BOOTSTRAP_KEY}" "https://${NODE_IP}:${API_PORT}/health" || true
echo
echo "Raft state:"
curl -sk -H "X-TYPESENSE-API-KEY: ${BOOTSTRAP_KEY}" "https://${NODE_IP}:${API_PORT}/debug?stats=1" | jq '.state' || true
echo
echo "Repeat on the other 2 nodes."
After all three nodes report state: 4 on exactly one (the leader) and state: 1 on the other two, mint scoped keys for your applications:
TS_KEY=$(cat /etc/typesense/bootstrap.key)
# Admin key for operators (revocable, full scope)
curl -sk -H "X-TYPESENSE-API-KEY: ${TS_KEY}" -XPOST \
"https://10.10.0.51:8108/keys" \
-H 'Content-Type: application/json' -d '{
"description":"ops-admin-q2-2026",
"actions":["*"],
"collections":["*"]
}'
# Search key for the storefront — read-only, scoped to one collection
curl -sk -H "X-TYPESENSE-API-KEY: ${TS_KEY}" -XPOST \
"https://10.10.0.51:8108/keys" \
-H 'Content-Type: application/json' -d '{
"description":"storefront-search-q2-2026",
"actions":["documents:search"],
"collections":["products"]
}'
Quarterly rotation: mint the new key with the next quarter’s description, deploy it to the application, retire the old key after the deploy lands. Bootstrap rotation goes through /usr/local/bin/ts-rotate-bootstrap.sh <new-key> and is a five-minute rolling restart.
For a Typesense cluster you don’t have to maintain — including snapshot drills and key-rotation cadence — our team operates it under Managed Cloud Ops on Cloud Compute. Start a scoping call.