Skip to content

Deploying Valkey 7.x cluster on Ubuntu 22.04 — and migrating from Redis

Stand up a Valkey 7 cluster on Ubuntu 22.04, with TLS and ACLs, and walk through the migration path from a Redis Cluster of the same shape — including the gotchas.

The Redis license change in March 2024 (BSD3/RSALv2/SSPLv1 dual licensing) put a small but real question on every operator’s roadmap: do we keep upgrading Redis under its new license, do we freeze on the last BSD version, or do we migrate to the Linux Foundation fork. Eighteen months later that question has a clear answer for most self-hosted teams: Valkey 7 is BSD-3-Clause, protocol-compatible with Redis OSS 7.2, has a real release cadence, and is what AWS ElastiCache, GCP Memorystore, and a growing list of distros now ship. If you’re standing up a new cache or planning a migration, this article gets you to a running 6-node Valkey 7 cluster with TLS and ACLs on Ubuntu 22.04 — and the migration path from an existing Redis cluster.

What’s happening

Valkey forked from Redis 7.2.4 in March 2024 and has shipped 7.2.x and 8.x releases since. From an operator’s perspective:

  • Wire protocol identical to Redis 7.2. Every Redis client library (redis-py, ioredis, lettuce, go-redis, jedis) connects to Valkey unchanged. You don’t even have to change the connection string format.
  • Config file identical. redis.conf works as-is. The binary is valkey-server, the CLI is valkey-cli, but redis-cli against a Valkey instance also works.
  • Cluster mode, ACL, TLS, Sentinel, Pub/Sub, Streams, Modules — same surface area. The Modules API is binary-compatible with the 7.2 Modules API.
  • Different defaults in a few places. Valkey enables I/O threads by default in 8.x. Memory usage telemetry is slightly different.
  • License is BSD 3-Clause. No commercial source-available concerns; ships in major Linux distros’ repos.

Where it diverges from Redis going forward is in the roadmap — Valkey 8.x adds multi-threaded I/O on by default, better key replication for sharded clusters, and observability hooks that Redis 7.4+ does not have. Conversely, some of the newer Redis Stack modules (RediSearch, RedisJSON, RedisTimeSeries) are not part of Valkey core; if you depend on them, evaluate the OSS alternatives (the modules are still available, but under the source-available license).

Migration from Redis to Valkey is, in our experience: install Valkey alongside Redis, replicate the Redis cluster to the Valkey cluster using the replication protocol (Valkey speaks it natively), cut over clients in a maintenance window, decommission Redis. There is no data export step.

How to verify

After the installer runs on all six nodes:

# Cluster topology from any node
valkey-cli --tls \
  --cacert /etc/valkey/tls/ca.crt \
  --cert /etc/valkey/tls/valkey.crt \
  --key /etc/valkey/tls/valkey.key \
  -h 10.50.0.11 -p 6379 \
  --user admin -a "$ADMIN_PASS" \
  cluster nodes

Six lines: three masters, three replicas, all connected. Slot ranges covering 0-16383 with no gaps.

# Confirm slots
valkey-cli --tls ... cluster slots

# Confirm Valkey, not Redis
valkey-cli --tls ... info server | grep -E 'valkey_version|redis_version'
# Valkey reports both valkey_version and redis_version (for client compat)

If you’re migrating from an existing Redis cluster, confirm replication state mid-migration:

# On a Valkey master that's replicating from a Redis master
valkey-cli --tls ... info replication
# role:slave
# master_host:<redis-master-ip>
# master_link_status:up
# master_sync_in_progress:0
# slave_repl_offset:<should grow>

The fix

Save the script as /root/setup-valkey-cluster-node.sh and run it on each of the six nodes after editing the variables at the top. Same overall shape as the Redis Cluster installer: Ubuntu 22.04 base hardening, kernel/sysctl, Valkey 7.2 from the Valkey APT repo, TLS material from a private CA, valkey.conf for cluster mode on the private interface only, ACL file, and a one-shot valkey-cli --cluster create on the bootstrap node.

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

### Ubuntu 22.04 Valkey 7.x Cluster installer (6 nodes, 3 masters + 3 replicas)
### Run on each of 6 nodes after editing the variables
### Bootstrap node (IS_BOOTSTRAP=true) runs `cluster create` once all 6 are up

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

# === EDIT PER NODE ===
NODE_NAME="valkey-m1"
NODE_IP="10.50.0.11"
IS_BOOTSTRAP="true"
CLUSTER_NAME="valkey-cache"
PEER_NAMES=("valkey-m1" "valkey-m2" "valkey-m3" "valkey-r1" "valkey-r2" "valkey-r3")
PEER_IPS=("10.50.0.11" "10.50.0.12" "10.50.0.13" "10.50.0.21" "10.50.0.22" "10.50.0.23")
ADMIN_PASS="CHANGE_ME_ADMIN"
APP_PASS="CHANGE_ME_APP"
REPL_PASS="CHANGE_ME_REPL"
INTERNAL_CIDR="10.50.0.0/16"
# =====================

echo
echo "========================================"
echo "Valkey Cluster node ${NODE_NAME} (${NODE_IP})"
echo "========================================"
echo

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
apt-get -y install curl gpg lsb-release ca-certificates software-properties-common \
  ufw fail2ban unattended-upgrades \
  openssl jq net-tools tcpdump lsof bind9-host vim

echo "==> Time sync"
timedatectl set-ntp true || true

echo "==> Kernel/sysctl tuning"
cat > /etc/sysctl.d/99-valkey.conf <<'SYSCTL'
vm.overcommit_memory = 1
vm.swappiness = 1
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 10240 65535
fs.file-max = 1048576
SYSCTL
sysctl --system

echo "==> Disable transparent hugepages"
cat > /etc/systemd/system/disable-thp.service <<'THP'
[Unit]
Description=Disable Transparent Huge Pages
After=sysinit.target local-fs.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled; echo never > /sys/kernel/mm/transparent_hugepage/defrag'
RemainAfterExit=yes

[Install]
WantedBy=basic.target
THP
systemctl daemon-reload
systemctl enable --now disable-thp

cat > /etc/security/limits.d/99-valkey.conf <<'LIMITS'
valkey soft nofile 200000
valkey hard nofile 200000
valkey soft nproc 65535
valkey hard nproc 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 ssh

echo "==> UFW — internal only"
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow from "${INTERNAL_CIDR}" to any port 6379 proto tcp
ufw allow from "${INTERNAL_CIDR}" to any port 16379 proto tcp
ufw --force enable

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 "==> Unattended security upgrades"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG

echo "==> Adding Valkey APT repository"
# Valkey is in Ubuntu universe from 24.04 onward; on 22.04 we use the upstream repo.
curl -fsSL https://valkey.io/keys/valkey-archive-keyring.gpg \
  -o /usr/share/keyrings/valkey-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/valkey-archive-keyring.gpg] https://packages.valkey.io/deb $(lsb_release -cs) main" \
  > /etc/apt/sources.list.d/valkey.list
apt-get update
apt-get -y install valkey

systemctl stop valkey-server || true

echo "==> TLS material"
mkdir -p /etc/valkey/tls
cd /etc/valkey/tls
if [[ "${IS_BOOTSTRAP}" == "true" && ! -f ca.crt ]]; then
  openssl req -x509 -newkey rsa:4096 -sha256 -nodes -days 3650 \
    -keyout ca.key -out ca.crt \
    -subj "/CN=Valkey Cluster CA - ${CLUSTER_NAME}"
  chmod 600 ca.key
  echo "    Bootstrap CA generated. Copy /etc/valkey/tls/ca.{crt,key} to peers."
fi

if [[ ! -f valkey.crt ]]; then
  if [[ ! -f ca.crt || ! -f ca.key ]]; then
    echo "ERROR: copy ca.crt + ca.key from the bootstrap node before continuing." >&2
    exit 2
  fi
  openssl req -newkey rsa:2048 -nodes \
    -keyout valkey.key -out valkey.csr \
    -subj "/CN=${NODE_NAME}" \
    -addext "subjectAltName=DNS:${NODE_NAME},IP:${NODE_IP},IP:127.0.0.1"
  cat > valkey.ext <<EXT
subjectAltName=DNS:${NODE_NAME},IP:${NODE_IP},IP:127.0.0.1
extendedKeyUsage=serverAuth,clientAuth
EXT
  openssl x509 -req -in valkey.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
    -out valkey.crt -days 825 -sha256 -extfile valkey.ext
  chmod 640 valkey.key
  chown root:valkey valkey.crt valkey.key ca.crt
fi
cd -

echo "==> Writing /etc/valkey/valkey.conf"
cat > /etc/valkey/valkey.conf <<EOF
# Network
bind ${NODE_IP} 127.0.0.1
protected-mode yes
port 0
tls-port 6379

# TLS
tls-cert-file /etc/valkey/tls/valkey.crt
tls-key-file /etc/valkey/tls/valkey.key
tls-ca-cert-file /etc/valkey/tls/ca.crt
tls-cluster yes
tls-replication yes
tls-auth-clients yes
tls-protocols "TLSv1.2 TLSv1.3"

# Cluster
cluster-enabled yes
cluster-config-file /var/lib/valkey/nodes-${NODE_NAME}.conf
cluster-node-timeout 15000
cluster-require-full-coverage no
cluster-allow-reads-when-down no
cluster-announce-ip ${NODE_IP}
cluster-announce-port 6379
cluster-announce-bus-port 16379

# Persistence
appendonly yes
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
appendfsync everysec
aof-use-rdb-preamble yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
save 900 1
save 300 10
save 60 10000
dir /var/lib/valkey

# I/O threads
io-threads 4
io-threads-do-reads yes

# Memory + eviction
maxmemory 4gb
maxmemory-policy allkeys-lru

# Logging
loglevel notice
logfile /var/log/valkey/valkey-server.log
syslog-enabled no

# Slow log
slowlog-log-slower-than 10000
slowlog-max-len 1024

# ACL
aclfile /etc/valkey/users.acl

# Replica auth
masteruser replication
masterauth ${REPL_PASS}
EOF

cat > /etc/valkey/users.acl <<EOF
# default disabled — clients authenticate by named user.
user default off nopass nocommands

# admin
user admin on >${ADMIN_PASS} ~* &* +@all

# app — production traffic
user app on >${APP_PASS} ~* &* -@dangerous -flushdb -flushall -keys -debug -shutdown -script +@all

# replication
user replication on >${REPL_PASS} +@all ~* &*
EOF

chmod 640 /etc/valkey/users.acl /etc/valkey/valkey.conf
chown root:valkey /etc/valkey/users.acl /etc/valkey/valkey.conf
mkdir -p /var/lib/valkey /var/log/valkey
chown -R valkey:valkey /var/lib/valkey /var/log/valkey

echo "==> systemd unit override"
mkdir -p /etc/systemd/system/valkey-server.service.d
cat > /etc/systemd/system/valkey-server.service.d/override.conf <<'OVR'
[Service]
LimitNOFILE=200000
TimeoutStopSec=60
Restart=on-failure
OVR

systemctl daemon-reload
systemctl enable valkey-server
systemctl start valkey-server

echo "==> Waiting for Valkey to accept TLS connections"
for i in {1..60}; do
  if valkey-cli --tls \
       --cacert /etc/valkey/tls/ca.crt \
       --cert /etc/valkey/tls/valkey.crt \
       --key /etc/valkey/tls/valkey.key \
       -h "${NODE_IP}" -p 6379 \
       --user admin -a "${ADMIN_PASS}" \
       ping >/dev/null 2>&1; then
    echo "    Valkey up."
    break
  fi
  sleep 2
done

if [[ "${IS_BOOTSTRAP}" == "true" ]]; then
  ALL_UP=1
  for ip in "${PEER_IPS[@]}"; do
    if ! valkey-cli --tls \
           --cacert /etc/valkey/tls/ca.crt \
           --cert /etc/valkey/tls/valkey.crt \
           --key /etc/valkey/tls/valkey.key \
           -h "${ip}" -p 6379 \
           --user admin -a "${ADMIN_PASS}" \
           ping >/dev/null 2>&1; then
      echo "    ${ip} not reachable yet — re-run this script on the bootstrap node once all 6 peers are installed."
      ALL_UP=0
    fi
  done

  if [[ "${ALL_UP}" == "1" ]]; then
    PEERS_ARG=""
    for ip in "${PEER_IPS[@]}"; do
      PEERS_ARG="${PEERS_ARG} ${ip}:6379"
    done
    echo "==> Creating cluster: ${PEERS_ARG}"
    valkey-cli --tls \
      --cacert /etc/valkey/tls/ca.crt \
      --cert /etc/valkey/tls/valkey.crt \
      --key /etc/valkey/tls/valkey.key \
      --user admin -a "${ADMIN_PASS}" \
      --cluster create${PEERS_ARG} \
      --cluster-replicas 1 \
      --cluster-yes
  fi
fi

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(6379|16379)\b' || true
echo
echo "Cluster info:"
valkey-cli --tls \
  --cacert /etc/valkey/tls/ca.crt \
  --cert /etc/valkey/tls/valkey.crt \
  --key /etc/valkey/tls/valkey.key \
  -h "${NODE_IP}" -p 6379 \
  --user admin -a "${ADMIN_PASS}" \
  cluster info || true
echo
echo "Topology:"
valkey-cli --tls \
  --cacert /etc/valkey/tls/ca.crt \
  --cert /etc/valkey/tls/valkey.crt \
  --key /etc/valkey/tls/valkey.key \
  -h "${NODE_IP}" -p 6379 \
  --user admin -a "${ADMIN_PASS}" \
  cluster nodes || true

Migration path from Redis Cluster to Valkey Cluster

The high-level shape, in order, with no application downtime:

  1. Stand up Valkey alongside Redis. Run the installer on six new nodes. Don’t run cluster create on the new Valkey side yet — keep the Valkey nodes free.

  2. Replicate Redis → Valkey at the shard level. For each Redis master, point one Valkey instance at it as a replica. Valkey speaks the replication protocol unchanged:

    valkey-cli --tls ... -h <valkey-node> -p 6379 \
      --user admin -a "$ADMIN_PASS" \
      replicaof <redis-master-ip> 6379

    Confirm master_link_status:up on each Valkey replica before moving on.

  3. Wait for sync to complete. Each Valkey replica goes through full sync, then enters online replication. For a 4 GB shard at gigabit Ethernet, expect 30-60 seconds; for a 64 GB shard, expect several minutes.

  4. Promote Valkey side and form its own cluster. Issue replicaof no one on every Valkey master-to-be. Then run cluster create on the Valkey side to form a cluster among the six Valkey nodes. The keyspace is already populated.

  5. Cut over clients. Update the connection string from redis://... to valkey://... (or just point at the new IPs — the protocol is the same). Rolling restart application pods.

  6. Run both clusters in parallel for 30-60 minutes to validate. Watch app error rates, latencies, hit ratios. If anything looks off, point clients back at Redis.

  7. Decommission Redis. cluster forget is not relevant here — just shut down the old Redis nodes.

The migration gotchas we hit most often:

  • Slot map order. When you replicate Redis master 1 → Valkey instance A, slots 0-5460 end up on A. When you form the new cluster, you must hand A those same slot ranges in cluster create. The script’s default --cluster-replicas 1 picks slots arbitrarily — for a migration you want to pin slot ownership explicitly with CLUSTER ADDSLOTS per node before forming the cluster, or your topology will reshuffle and the keys will need to move.
  • AOF differences. If you ran Redis with appendfsync always, Valkey’s everysec default is technically slacker. Set them consistently if it matters to your durability story.
  • Lua script SHAs. Cached script SHAs are not part of the replicated dataset — re-load all EVALSHA scripts on the Valkey side after cutover, or your first call after cutover will get NOSCRIPT until the client retries with EVAL.
  • Connection strings. If your app config has redis:// hardcoded, just leave it — Valkey accepts it. The scheme alias valkey:// works in newer clients but isn’t required.

For a Valkey cluster or migration we operate end-to-end, Cloud Compute plus Managed Cloud Ops covers patching, capacity, and on-call — book a scoping call to plan the cutover.