Archive · DevOps

Redis 7.2: Install, Persistence and Security

Install Redis on Ubuntu 22.04 and configure persistence and access control properly.

1 min read

  • Redis 7.2
  • Ubuntu 22.04 LTS
  • redis-cli
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt update && sudo apt install -y redis

Edit /etc/redis/redis.conf:

bind 127.0.0.1 -::1        # listen only locally, or on a private IP
protected-mode yes
maxmemory 1gb
maxmemory-policy allkeys-lru   # for a cache; use noeviction for a datastore
appendonly yes                 # AOF persistence
save 900 1 300 10 60 10000     # RDB snapshots

Add authentication with ACLs rather than one shared password:

user default off
user app on >S3curePass ~app:* +@read +@write -@dangerous
sudo systemctl restart redis-server
redis-cli --user app --pass S3curePass ping
redis-cli info memory | head

RDB snapshots are compact and quick to restore; AOF loses less data. Use both for data you care about. Never expose Redis to the internet, and size maxmemory below the host’s RAM to leave room for forks.