Databases Azure

Redis 8 on Ubuntu 26.04 LTS on Azure User Guide

| Product: Redis 8 on Ubuntu 26.04 LTS on Azure

Overview

This guide covers deploying and using Redis 8 on Ubuntu 26.04 LTS on Azure from cloudimg's Azure Marketplace image. Redis is the open source in memory data store used as a cache, a message broker and a low latency database. It keeps strings, hashes, lists, sets, sorted sets, streams and vector sets in memory, answers in well under a millisecond, and snapshots the data to disk so it survives a restart.

The image installs Redis 8.0.5 (redis-server and redis-tools 5:8.0.5-1ubuntu0.1) from Ubuntu 26.04's own archive, so Ubuntu's security updates and unattended upgrades keep it patched alongside the operating system. The image is secure by default. No password ships in it. Redis listens on the loopback address only, and redis-server.service is held back until the first boot of each VM has run. On that first boot, redis-firstboot.service generates a unique 48 character password for the default user, writes it to /etc/redis/conf.d/20-cloudimg-auth.conf, starts Redis and records the password in /root/redis-credentials.txt (mode 0600, root only). Clients on your workstation reach Redis through an SSH tunnel (Step 10), so port 6379 never has to be open to the internet.

What is included:

  • Redis 8.0.5 (redis-server and redis-tools) from Ubuntu 26.04's archive, with the built-in vectorset module (the VADD and VSIM vector set commands)

  • redis-server.service, enabled, listening on 127.0.0.1:6379 and [::1]:6379 only, with protected-mode yes

  • redis-firstboot.service, which generates a per-VM password on the first boot and starts Redis

  • cloudimg's settings in /etc/redis/conf.d/, loaded after the stock /etc/redis/redis.conf, so your own changes live in small files beside them

  • RDB snapshots on (Redis's default schedule) into /var/lib/redis

  • vm.overcommit_memory = 1 (Redis's recommended setting for background saves) in /etc/sysctl.d/60-redis.conf

  • A login banner with the address Redis listens on, where the password is and the tunnel command

  • Ubuntu 26.04 LTS, fully patched at build time, with unattended security updates on

  • cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours

Prerequisites

  • An active Azure subscription

  • An SSH public key for VM authentication

  • A virtual network and subnet in the target region (the portal can create them for you)

  • On your workstation, an SSH client and, if you want to connect from there, a Redis client: redis-cli, or the Redis library for your language

Recommended virtual machine size: Standard_B2s (2 vCPU, 4 GiB RAM). Redis holds the whole dataset in memory, so choose the size by memory: the data, plus room for a background save to copy pages that change while it runs. For larger datasets choose a memory optimised size such as the E series.

Step 1: Deploy from the Azure Portal

In the Azure Portal, open Marketplace, search for Redis 8 on Ubuntu 26.04, select the cloudimg entry and click Create. On Basics choose your subscription, resource group, region and size, and set the administrator user name and SSH public key. Allow inbound SSH (22) and narrow it to your own address range once the VM exists.

Do not open TCP 6379. Redis listens on loopback only, and clients reach it through SSH (Step 10).

Click Review + create, then Create. Deployment takes about two minutes. Note the VM's Public IP address on its Overview page.

Step 2: Deploy from the Azure CLI

RG="redis-prod"
LOCATION="eastus"
VM_NAME="redis-01"
ADMIN_USER="azureuser"
IMAGE_URN="cloudimg1647283583153:redis-ubuntu-26-04:default:latest"
SSH_KEY="$(cat ~/.ssh/id_rsa.pub)"

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn "$IMAGE_URN"

az group create --name "$RG" --location "$LOCATION"

az network nsg create --resource-group "$RG" --name redis-nsg

az network nsg rule create \
  --resource-group "$RG" --nsg-name redis-nsg \
  --name allow-ssh --priority 100 \
  --source-address-prefixes "<your-mgmt-cidr>" \
  --destination-port-ranges 22 --access Allow --protocol Tcp

az vm create \
  --resource-group "$RG" --name "$VM_NAME" \
  --image "$IMAGE_URN" \
  --size Standard_B2s \
  --admin-username "$ADMIN_USER" --ssh-key-values "$SSH_KEY" \
  --nsg redis-nsg \
  --public-ip-sku Standard

Read the VM's public IP address:

az vm show -d --resource-group "$RG" --name "$VM_NAME" --query publicIps -o tsv

Step 3: Connect with SSH

ssh azureuser@<vm-public-ip>

The login banner shows where Redis listens and where its password is:

  Redis 8 on Ubuntu 26.04 LTS (cloudimg Azure Marketplace image)
  Listening on 127.0.0.1:6379 (loopback only); the password for this VM:
    sudo cat /root/redis-credentials.txt
  Remote clients: ssh -N -L 6379:127.0.0.1:6379 azureuser@<this VM>
  User guide:  https://www.cloudimg.co.uk/guides/redis-8-on-ubuntu-26-04-azure/

Step 4: Check the Redis service

First boot has already made this VM's password and started Redis:

sudo test -f /var/lib/cloudimg/redis-firstboot.done && echo FIRSTBOOT_DONE
systemctl is-active redis-server
ss -ltnH 'sport = :6379'
redis-server --version
FIRSTBOOT_DONE
active
LISTEN 0      511    127.0.0.1:6379 0.0.0.0:*
LISTEN 0      511        [::1]:6379    [::]:*
Redis server v=8.0.5 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=d47fc40702b1fad8

Redis listens on the IPv4 and IPv6 loopback addresses only. The drop-in 10-cloudimg-first-boot.conf in the service's status is the gate that keeps Redis from starting before first boot has set its password.

redis-server active with the cloudimg first boot drop-in, listening on 127.0.0.1:6379 and [::1]:6379, and the Redis 8.0.5 version line

Step 5: Read the password

sudo cat /root/redis-credentials.txt
# Redis 8 on Ubuntu 26.04 LTS (cloudimg Azure Marketplace image)
# This password is unique to THIS VM, made on its first boot. Store it safely.

REDIS_USER=default
REDIS_PASSWORD=<REDIS_PASSWORD>
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
#
# On the VM:
#   export REDISCLI_AUTH="$(sudo sed -n 's/^REDIS_PASSWORD=//p' /root/redis-credentials.txt)"
#   redis-cli PING
# Redis listens on loopback only. From your workstation, open an SSH tunnel and connect to localhost:
#   ssh -N -L 6379:127.0.0.1:6379 azureuser@<this VM's public IP>

The file and the Redis setting that holds the password are readable by root (and, for the setting, the redis group) only:

sudo stat -c '%a %U:%G %n' /root/redis-credentials.txt /etc/redis/conf.d/20-cloudimg-auth.conf
600 root:root /root/redis-credentials.txt
640 root:redis /etc/redis/conf.d/20-cloudimg-auth.conf

The credentials file with the password hidden, and the permissions on it and on the password setting

Step 6: Connect with redis-cli

redis-cli reads the password from the REDISCLI_AUTH environment variable, which keeps it out of your shell history and the process list. Set it once per SSH session:

export REDISCLI_AUTH="$(sudo sed -n 's/^REDIS_PASSWORD=//p' /root/redis-credentials.txt)"
redis-cli PING
redis-cli INFO server | grep -E '^(redis_version|redis_mode|tcp_port|config_file):'
PONG
redis_version:8.0.5
redis_mode:standalone
tcp_port:6379
config_file:/etc/redis/redis.conf

Step 7: Store and read data

Strings, with an expiry, as a cache or session store uses them:

redis-cli SET greeting 'hello from cloudimg'
redis-cli GET greeting
redis-cli SET session:42 "user=ada" EX 3600
redis-cli TTL session:42
OK
hello from cloudimg
OK
3600

A hash, a list used as a queue, and a sorted set used as a leaderboard:

redis-cli HSET user:1 name Ada lang en
redis-cli HGETALL user:1
redis-cli RPUSH jobs build test deploy
redis-cli LPOP jobs
redis-cli ZADD scores 120 ada 95 linus 150 grace
redis-cli ZREVRANGE scores 0 -1 WITHSCORES
2
name
Ada
lang
en
3
build
3
grace
150
ada
120
linus
95

A stream, Redis's append-only log for events and consumer groups:

redis-cli XADD events '*' type signup user ada
redis-cli XLEN events
1796271616768-0
1

XADD prints the new entry's ID, which is the time in milliseconds and a sequence number, so yours will differ.

PING, a string set and read, a hash, a counter and the key count, after REDISCLI_AUTH is set

Step 8: Vector sets

Redis 8 adds vector sets, a data type for similarity search over embeddings, through its built-in vectorset module. Add three two-dimensional vectors and ask for the two nearest to a query vector:

redis-cli VADD points VALUES 2 1.0 0.0 apple
redis-cli VADD points VALUES 2 0.9 0.1 pear
redis-cli VADD points VALUES 2 0.0 1.0 rocket
redis-cli VCARD points
redis-cli VSIM points VALUES 2 1.0 0.05 COUNT 2 WITHSCORES
1
1
1
3
apple
0.9993761960067786
pear
0.9989067337010056

Real embeddings from a model have hundreds of dimensions; VADD takes them the same way, or as a binary blob with FP32.

Ubuntu's Redis package carries the open source core and the vectorset module only. The Redis Query Engine, JSON, time series and probabilistic modules that the redis.io packages bundle are not part of it: redis-cli MODULE LIST lists vectorset alone.

Step 9: Check the security settings

A client with no password, and one with a wrong password, are refused:

env -u REDISCLI_AUTH redis-cli PING
REDISCLI_AUTH=not-the-password redis-cli PING
NOAUTH Authentication required.
AUTH failed: WRONGPASS invalid username-password pair or user is disabled.
NOAUTH Authentication required.

Redis binds to loopback only, with protected mode on:

redis-cli CONFIG GET bind
redis-cli CONFIG GET protected-mode
bind
127.0.0.1 -::1
protected-mode
yes

A connection to the VM's own private address is refused, because nothing listens there:

redis-cli -h "$(hostname -I | awk '{print $1}')" PING || echo REFUSED
Could not connect to Redis at 10.20.0.22:6379: Connection refused
REFUSED

PING refused without a password and with a wrong one, then bind, protected mode and the module list with the password set

Step 10: Connect from your workstation

Open an SSH tunnel that carries your workstation's port 6379 to Redis on the VM, and leave it running:

ssh -N -L 6379:127.0.0.1:6379 azureuser@<vm-public-ip>

In another terminal on your workstation, connect to 127.0.0.1:6379 with the VM's password:

export REDISCLI_AUTH='<REDIS_PASSWORD>'
redis-cli -h 127.0.0.1 -p 6379 PING
PONG

An application connects the same way, with host 127.0.0.1, port 6379, user default and the password, for example the URL redis://default:<REDIS_PASSWORD>@127.0.0.1:6379/0. If port 6379 is already in use on your workstation, tunnel another local port instead (-L 16379:127.0.0.1:6379) and connect to that.

Applications that run on other VMs in the same virtual network can reach Redis without a tunnel once you open it to that network: add the VM's private address to the bind line in /etc/redis/conf.d/10-cloudimg.conf (for example bind 127.0.0.1 -::1 10.20.0.22), restart Redis, and add a network security group rule that allows TCP 6379 from that subnet only. Never open 6379 to the internet.

Step 11: Persistence and memory

Redis writes RDB snapshots to /var/lib/redis on its default schedule: after an hour with at least one change, five minutes with 100 changes, or a minute with 10,000 changes. Append-only file (AOF) logging is off:

redis-cli CONFIG GET save
redis-cli CONFIG GET appendonly
redis-cli CONFIG GET dir
redis-cli BGSAVE
save
3600 1 300 100 60 10000
appendonly
no
dir
/var/lib/redis
Background saving started

Turn on AOF for durability. AOF logs every write, so a crash loses at most a second of writes. Turn it on live first, so that Redis writes the AOF from the data it already holds, then make the setting permanent:

redis-cli CONFIG SET appendonly yes
echo 'appendonly yes' | sudo tee /etc/redis/conf.d/30-local.conf
sudo chown root:redis /etc/redis/conf.d/30-local.conf
sudo chmod 0640 /etc/redis/conf.d/30-local.conf

Do it in that order. If you only add appendonly yes to a file and restart, Redis starts from an empty AOF instead of the RDB snapshot, and the data looks lost.

Set a memory limit when Redis is a cache. By default Redis has no memory limit (maxmemory 0) and refuses writes only when the VM runs out of memory. For a cache, cap it and let Redis evict the least recently used keys, in a file of your own beside cloudimg's:

printf 'maxmemory 2gb\nmaxmemory-policy allkeys-lru\n' | sudo tee -a /etc/redis/conf.d/30-local.conf
sudo systemctl restart redis-server

Use redis-cli CONFIG SET for a change you want only until the next restart. Avoid CONFIG REWRITE: it writes every running setting, the password included, into redis.conf.

Step 12: Components

Component Where
Redis server and CLI /usr/bin/redis-server, /usr/bin/redis-cli (Ubuntu packages redis-server, redis-tools)
Stock configuration /etc/redis/redis.conf, which includes /etc/redis/conf.d/*.conf at its end
cloudimg settings (bind, port, protected mode) /etc/redis/conf.d/10-cloudimg.conf
This VM's password /etc/redis/conf.d/20-cloudimg-auth.conf (0640 root:redis) and /root/redis-credentials.txt (0600)
Data (RDB and AOF) /var/lib/redis
Log /var/log/redis/redis-server.log
First boot redis-firstboot.service, /usr/local/sbin/redis-firstboot.sh
Kernel setting /etc/sysctl.d/60-redis.conf (vm.overcommit_memory = 1)

Step 13: Managing the service

sudo systemctl status redis-server --no-pager
sudo systemctl restart redis-server
sudo systemctl stop redis-server
sudo systemctl start redis-server
sudo tail -f /var/log/redis/redis-server.log

Updates: unattended upgrades install Ubuntu's security updates, Redis's included; sudo apt update && sudo apt upgrade applies the rest. A Redis package update restarts the server, which reloads the latest snapshot (or the AOF, when it is on).

Change the password: generate a new one, put it in both places and restart:

NEW="$(openssl rand -hex 24)"
echo "requirepass ${NEW}" | sudo tee /etc/redis/conf.d/20-cloudimg-auth.conf >/dev/null
sudo sed -i "s/^REDIS_PASSWORD=.*/REDIS_PASSWORD=${NEW}/" /root/redis-credentials.txt
sudo systemctl restart redis-server

Then update every client.

Step 14: Troubleshooting

NOAUTH Authentication required.

  • REDISCLI_AUTH is not set in this shell: run the export line from Step 6 again (each SSH session needs it)

WRONGPASS invalid username-password pair

  • The password in REDISCLI_AUTH or your client is not this VM's: read it again from /root/redis-credentials.txt. Every VM from the image has its own

Could not connect to Redis at 127.0.0.1:6379: Connection refused

  • Redis is not running: sudo systemctl status redis-server --no-pager and the end of /var/log/redis/redis-server.log say why

  • On a brand new VM, first boot may still be running: systemctl status redis-firstboot --no-pager

The tunnel connects but the client hangs or is refused

  • The SSH session that carries the tunnel must stay open, and its local port must not already be in use on your workstation

OOM command not allowed when used memory > 'maxmemory'

  • The memory limit from Step 11 is reached and the eviction policy is noeviction: raise maxmemory, choose an eviction policy, or move to a VM with more memory

Step 15: Security recommendations

  • Keep Redis on loopback and reach it through SSH, or bind it to a private address with a network security group rule for your application subnet only. Never open TCP 6379 to the internet

  • Narrow the SSH rule to the addresses you administer from

  • Give each application its own Redis user with only the commands and keys it needs (ACL SETUSER), and keep the default user's password for administration

  • Rename or disable commands an application should never run, such as FLUSHALL and CONFIG, through ACLs

  • Turn on AOF (Step 11) when the data matters, and copy the files in /var/lib/redis off the VM on a schedule

Step 16: Support and licensing

Redis 8 is offered by its authors under your choice of the RSALv2, SSPLv1 or AGPLv3 licences. Ubuntu packages it under that tri-licence, and this image uses Redis under the AGPLv3, an open source licence approved by the OSI. There is no per-core, per-instance or per-connection fee for Redis itself.

cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours.