bolt Valebyte VPS from $4/mo — NVMe, 60s deploy.

Get a VPS arrow_forward
eco Beginner Tutorial/How-to

Installing and Configuring Redis on VPS: Secure

calendar_month Sep 01, 2026 schedule 23 min read visibility 34 views
Установка и настройка Redis на VPS: Безопасность и высокая производительность
info

Need a server for this guide? We offer dedicated servers and VPS in 50+ countries with instant setup.

Need a server for this guide?

Deploy a VPS or dedicated server in minutes.

Installing and Configuring Redis on VPS: Security and High Performance

TL;DR

In this detailed technical guide, we will step-by-step configure a high-performance and secure Redis server on your VPS. You will learn how to prepare the server, install the latest version of Redis, properly configure it for optimal performance and security, and set up backup and monitoring. All commands and configuration files are provided in a ready-to-copy and use format.

  • Preparing a VPS with the latest Ubuntu 24.04 LTS OS, configuring SSH security and firewall.
  • Installing Redis version 7.x from official repositories or compiling from source for maximum up-to-dateness.
  • Detailed configuration of redis.conf with an emphasis on security (password, IP binding) and performance (memory management, persistence).
  • Setting up automatic backup of Redis data and configuration.
  • Effective troubleshooting of common problems and answers to frequently asked questions.

What We Configure and Why

Diagram: What We Configure and Why
Diagram: What We Configure and Why

Redis (Remote Dictionary Server) is a powerful, open-source in-memory data store used as a database, cache, and message broker. It supports various data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, HyperLogLogs, geospatial indexes, and streams. By storing data in RAM, Redis provides incredibly high read and write speeds, making it an indispensable tool for modern high-load applications.

Within this guide, we will install and configure Redis on your Virtual Private Server (VPS) or dedicated server. The ultimate goal is to obtain a stable, secure, and performant Redis instance that can effectively serve your applications, whether it's a web application, microservice, gaming platform, or data processing system. You will learn not only basic installation but also fine-tuning of security parameters, memory management, and data persistence, which is critically important for a production environment.

What the reader will get in the end:

  • A working Redis server, ready for integration with your applications.
  • An understanding of key Redis configuration parameters affecting security and performance.
  • Skills in basic Redis administration, including starting, stopping, monitoring, and backing up.
  • A ready set of commands and scripts for quick deployment and maintenance.

What alternatives exist and why self-hosted on VPS:

There are several approaches to using Redis:

  • Cloud-managed Redis Services: Providers like Amazon ElastiCache, Google Cloud Memorystore, or Azure Cache for Redis offer fully managed Redis instances. They provide high availability, automatic scaling, backup, and patching without the need for manual intervention.
    Pros: Ease of use, minimal administration, built-in fault tolerance.
    Cons: High cost, less control over configuration, vendor lock-in to a specific cloud provider.
  • Self-hosted Redis on VPS/Dedicated server: You install and manage Redis yourself on your virtual or dedicated server.
    Pros: Full control over configuration, optimization for your needs, significantly lower cost compared to managed services, no vendor lock-in, ability to use specific Redis versions or modules.
    Cons: Requires technical knowledge for installation, configuration, monitoring, and maintenance; responsibility for security and fault tolerance lies with you.

Choosing self-hosted Redis on a VPS is ideal for those who value full control, want to optimize costs, and possess sufficient technical skills for self-administration. This is an excellent option for developers, startups, crypto enthusiasts, and anyone who wants to maximize the efficient use of their server resources.

What VPS Configuration is Needed for This Task

Diagram: What VPS Configuration is Needed for This Task
Diagram: What VPS Configuration is Needed for This Task

VPS requirements for Redis heavily depend on the volume of data you plan to store in memory, the intensity of read/write operations, and the number of concurrently connected clients. Redis stores all data in RAM, making RAM the most critical resource.

Minimum requirements for small projects (cache for low-traffic website, small task queue):

  • CPU: 1-2 vCPU (modern processor, e.g., Intel Xeon E3/E5 or AMD EPYC). Redis is single-threaded for most operations, but background tasks (persistence, AOF rewrite) can utilize other cores.
  • RAM: 1-2 GB. This will be sufficient for storing several hundred megabytes of Redis data plus the operating system and other basic services.
  • Disk: 20-40 GB SSD. SSD is critical for fast writing of persistent data (RDB snapshots, AOF log) and for quick data loading on restart.
  • Network: 100 Mbps - 1 Gbps. For most cases, 100 Mbps is sufficient, but for high-load applications with many requests or large data object transfers, 1 Gbps will be required.

Recommended VPS plan for most tasks (medium traffic, several gigabytes of data, queues, pub/sub):

  • CPU: 2-4 vCPU. Will provide sufficient performance for request processing and background operations.
  • RAM: 4-8 GB. Will allow storing several gigabytes of Redis data, leaving a reserve for the OS and peak loads.
  • Disk: 80-160 GB SSD. For larger data volumes and better persistence performance.
  • Network: 1 Gbps. To ensure high bandwidth.

For such characteristics, you can get a VPS with the specified characteristics, which will allow effective use of Redis as a cache, message broker, or primary database for many applications.

When a dedicated server is needed, not a VPS:

A dedicated server becomes necessary when:

  • Data volume exceeds available RAM: If you plan to store tens or hundreds of gigabytes of data in Redis.
  • Maximum performance is required: For very high-load systems where every millisecond of latency is critical, as well as the complete absence of the "noisy neighbor effect" inherent in virtualization.
  • High security and isolation requirements: A dedicated server provides complete physical isolation.
  • Specific hardware requirements: For example, special disk types (NVMe), a large number of CPU cores, or very large amounts of RAM.

Location: what it affects

The choice of VPS geographical location has a direct impact on the latency between your application and the Redis server. The closer the Redis server is to your users or your application server, the lower the latency will be. For web applications, this means faster page responses; for game servers, smoother gameplay; for data processing systems, faster task execution.

If your application and Redis are in the same data center or at least in the same country, latency will be minimal (single-digit milliseconds). If they are located on different continents, latency can reach hundreds of milliseconds, which is unacceptable for many Redis use cases.

Server Preparation

Diagram: Server Preparation
Diagram: Server Preparation

Before installing Redis, you need to perform basic security configuration and update the operating system. We will use Ubuntu 24.04 LTS (Noble Numbat), which will be relevant in 2026 and is an excellent choice for stable production servers.

1. Connecting to the Server

Connect to your VPS via SSH using the credentials provided by your provider. This is usually the root user and password, or an SSH key.


ssh root@ВАШ_IP_АДРЕС

2. System Update

It is important to update all packages to the latest versions to ensure system security and stability.


sudo apt update && sudo apt upgrade -y

This command first updates the list of available packages (apt update), and then installs all available updates (apt upgrade -y, where -y automatically confirms all prompts).

3. Creating a New User with Sudo Privileges

Working as the root user is insecure. Let's create a new user and grant them sudo privileges.


sudo adduser redisadmin

Follow the instructions to set a password and fill in user information (you can leave it blank). Then add the new user to the sudo group:


sudo usermod -aG sudo redisadmin

Now you can switch to the new user and continue working:


su - redisadmin

Or open a new SSH connection as this user.

4. Configuring SSH Keys (Recommended)

Using SSH keys instead of passwords significantly enhances security. If you are not already using them, generate a key pair on your local machine and copy the public key to the server.

On your local machine:


ssh-keygen -t rsa -b 4096
ssh-copy-id redisadmin@ВАШ_IP_АДРЕС

After successfully copying the key, disable password authentication in the /etc/ssh/sshd_config file on the server. Open the file for editing:


sudo nano /etc/ssh/sshd_config

Find and change/add the following lines:


# Disable root login
PermitRootLogin no

# Disable password authentication
PasswordAuthentication no

# Enable public key authentication
PubkeyAuthentication yes

Save changes (Ctrl+O, Enter) and exit (Ctrl+X). Then restart the SSH service:


sudo systemctl restart sshd

IMPORTANT: Before disabling password authentication, ensure that you can log in with your SSH key by opening a new connection in another terminal. If key-based login does not work, you risk losing access to the server.

5. Firewall Configuration (UFW)

Uncomplicated Firewall (UFW) is an easy-to-use interface for iptables. It allows you to restrict access to ports on your server.

Allow SSH connections (usually port 22):


sudo ufw allow OpenSSH

If Redis will only be accessible locally (recommended), you do not need to open its port. However, if you plan to access it from other servers in your network (e.g., within a VPS provider's private network), open the Redis port (default 6379) for a specific IP address or subnet:


# Allow access to Redis from a specific IP
sudo ufw allow from 192.168.1.100 to any port 6379

# Or for the entire private subnet
sudo ufw allow from 10.0.0.0/8 to any port 6379

Activate the firewall:


sudo ufw enable

Confirm the action by typing y. Check the firewall status:


sudo ufw status

6. Installing Fail2ban

Fail2ban scans logs and blocks IP addresses showing signs of malicious attacks (e.g., numerous failed SSH login attempts). This provides an additional layer of security.


sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban

Create a copy of the default configuration file for customization:


sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

Edit jail.local to configure ban parameters if necessary. For example, you can increase bantime (ban time) or decrease maxretry (number of attempts).


sudo nano /etc/fail2ban/jail.local

Find the [DEFAULT] section and configure:


[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5

Restart Fail2ban to apply the changes:


sudo systemctl restart fail2ban

Your server is now basically secured and ready for Redis installation.

Software Installation — Step-by-Step

Diagram: Software Installation — Step-by-Step
Diagram: Software Installation — Step-by-Step

We will install Redis version 7.x, which will be current and stable in 2026. There are two main installation methods: from official Ubuntu repositories or compilation from source. For most users, installing from repositories is simpler and more reliable, providing automatic security updates. However, if you need the very latest version or specific compilation options, building from source might be preferable. We will cover both options, starting with the recommended one.

Option 1: Installing Redis from Ubuntu Repositories (Recommended)

This method is simple and provides a stable, tested version of Redis. Ubuntu 24.04 LTS will likely come with Redis 7.x or newer.

Step 1: Update Package List

Ensure the package list is updated to get the latest information about available Redis versions.


sudo apt update
# Updates the package index from repositories

Step 2: Install Redis Server

Install the redis-server package. This command will install Redis and all necessary dependencies, and also configure it as a system service.


sudo apt install redis-server -y
# Installs Redis Server and automatically starts it

Step 3: Check Redis Service Status

After installation, Redis should start automatically. Let's check its status:


sudo systemctl status redis-server
# Checks if the Redis service is running

The output should show "active (running)". If not, try starting it manually:


sudo systemctl start redis-server
# Starts the Redis service

Step 4: Check Redis Version

Ensure the expected Redis version is installed (presumably 7.x).


redis-server --version
# Outputs the version of installed Redis

You will see something like Redis server v=7.x.y sha=...

Step 5: Check Redis Connection

Use the redis-cli client to check the connection to the Redis server.


redis-cli ping
# Sends a PING command to the Redis server

In response, you should receive PONG, indicating a successful connection.

Option 2: Compiling Redis from Source (For Advanced Users)

This method allows you to install the very latest version of Redis (e.g., Redis 8.x, if available by 2026) or use specific compilation options. It requires installing build tools.

Step 1: Install Necessary Build Tools

Install the packages required for compiling software from source.


sudo apt install build-essential tcl -y
# Installs compilers (gcc, make) and tcl for tests

Step 2: Download Redis Source Code

Navigate to a temporary directory and download the latest stable version of Redis from the official website. For example, we use version 7.2.4, but you can replace it with the most current version for 2026.


cd /tmp
wget https://download.redis.io/releases/redis-7.2.4.tar.gz
# Downloads the Redis source archive
tar xzf redis-7.2.4.tar.gz
# Unpacks the archive
cd redis-7.2.4
# Changes to the source directory

Step 3: Compile and Install Redis

Compile Redis. Use make, then make install to install the executables into system directories.


make
# Compiles Redis
sudo make install
# Installs Redis to /usr/local/bin

Step 4: Configure Redis as a systemd Service

For Redis to run as a system service and be managed via systemctl, configuration files need to be created. Run a special script that will help with this.


sudo ./utils/install_server.sh
# Runs an interactive script to configure systemd and configuration files

Follow the script's instructions. For most questions, you can press Enter to accept the default values (e.g., port 6379, configuration file /etc/redis/6379.conf, log file /var/log/redis_6379.log, data directory /var/lib/redis/6379). After completion, the script will start Redis and configure it for autostart.

Step 5: Check Redis Service Status

Check that Redis is running and active:


sudo systemctl status redis_6379
# Checks the status of the Redis service created by the script (can be redis-server or redis_6379)

Or, if the script created a service named redis-server:


sudo systemctl status redis-server

Step 6: Check Version and Connection


redis-cli ping
# Checks connection to Redis
redis-cli info server | grep redis_version
# Outputs Redis version

Redis is now installed. Let's move on to its detailed configuration for security and optimal performance.

Configuration

Diagram: Configuration
Diagram: Configuration

The Redis configuration file is typically located at /etc/redis/redis.conf (for installations from repositories) or /etc/redis/6379.conf (if you used the install_server.sh script). We will use redis.conf for all examples.

Open the configuration file for editing:


sudo nano /etc/redis/redis.conf

1. Security

1.1. IP Address Binding (bind)

By default, Redis can listen on all available network interfaces. This is dangerous. Restrict it to listen only on the local interface (127.0.0.1) if your application runs on the same server, or a specific private IP address if Redis is accessible from the local network.

Find the line bind 127.0.0.1 -::1 and ensure it is uncommented. If you need access from other servers in a private network, specify their IP addresses or the private IP of your Redis server.


# By default, listen only on localhost
bind 127.0.0.1 -::1

# If you need to listen on a private IP, for example, 10.0.0.5
# bind 10.0.0.5

# If you need to listen on multiple IPs
# bind 127.0.0.1 10.0.0.5

# Uncomment this line if you want Redis to listen on all interfaces (HIGHLY NOT RECOMMENDED WITHOUT FIREWALL CONFIGURATION)
# bind 0.0.0.0

For most cases, when the application and Redis are on the same VPS, bind 127.0.0.1 -::1 is the safest option.

1.2. Setting a Password (requirepass)

Redis does not have authentication by default. Setting a password is a critically important security measure.

Find the line starting with # requirepass foobared. Uncomment it and replace foobared with a strong, complex password. Generate passwords at least 32 characters long.


requirepass YOUR_STRONG_REDIS_PASSWORD

Important: Never use simple passwords. Record the password in a secure location or use a password manager.

1.3. Renaming or Disabling Dangerous Commands (rename-command)

Some Redis commands (e.g., FLUSHALL, FLUSHDB, KEYS, CONFIG) can be dangerous if misused. You can rename them or disable them entirely.


# Disable a command (make it unavailable)
rename-command FLUSHALL ""
rename-command FLUSHDB ""

# Rename a command (make it available under a different name)
rename-command CONFIG CONFIG_HIDDEN

If you disable a command, ensure that your applications do not depend on it, or that they use its safe equivalents.

2. Performance and Memory Management

2.1. Maximum Memory (maxmemory)

Redis stores data in RAM. Set a memory limit to prevent exhausting all available RAM and crashing the server. It is recommended to allocate 50-70% of the total available RAM on your VPS for Redis, to leave space for the OS and other processes.

For example, if you have 4GB RAM, you can allocate 2.5GB for Redis.


maxmemory 2.5gb
2.2. Eviction Policy (maxmemory-policy)

When Redis reaches maxmemory, it needs to decide which data to remove to free up space for new data. There are various eviction policies:

  • noeviction: New writes are not accepted if memory is full.
  • allkeys-lru: Removes the least recently used (LRU) keys from the entire set.
  • volatile-lru: Removes LRU keys only from those that have a TTL (time to live).
  • allkeys-lfu: Removes the least frequently used (LFU) keys from the entire set.
  • volatile-lfu: Removes LFU keys only from those that have a TTL.
  • allkeys-random: Removes random keys from the entire set.
  • volatile-random: Removes random keys only from those that have a TTL.
  • volatile-ttl: Removes keys with the shortest remaining TTL.

For a cache, allkeys-lru or allkeys-lfu are usually good choices.


maxmemory-policy allkeys-lru
2.3. Persistence

Redis can save data to disk so that it is not lost when the server restarts. There are two main mechanisms:

  • RDB (Redis Database Backup): Takes snapshots of data at specified intervals. Fast for recovery, but can lead to data loss recorded between snapshots.
    
    # Save if at least 10000 keys changed in 60 seconds
    save 60 10000
    # Save if at least 1000 keys changed in 300 seconds
    save 300 1000
    # Save if at least 1 key changed in 900 seconds
    save 900 1
    
  • AOF (Append Only File): Records every write operation to a log file. Provides better data durability, but can be slower and consume more disk space.
    
    appendonly yes
    appendfsync everysec # Save AOF to disk every second
    

You can use both mechanisms simultaneously. For maximum data durability, AOF with appendfsync everysec is recommended. For a pure cache that can be rebuilt from another source, persistence can be disabled (comment out all save lines and set appendonly no).

3. Logging

Ensure that logging is configured to track Redis events.


logfile /var/log/redis/redis-server.log
loglevel notice

Ensure that the directory /var/log/redis/ exists and Redis has write permissions to it. If not, create it:


sudo mkdir -p /var/log/redis
sudo chown redis:redis /var/log/redis

4. Saving and Restarting Redis

After making all changes to redis.conf, save the file (Ctrl+O, Enter) and exit (Ctrl+X). Then restart the Redis service to apply the new settings.


sudo systemctl restart redis-server
# Restarts the Redis service

5. Verifying Operation with the New Configuration

After restarting, check the service status and ensure that Redis is running without errors.


sudo systemctl status redis-server

Now try connecting with a password via redis-cli:


redis-cli -a YOUR_STRONG_REDIS_PASSWORD ping
# Connects to Redis with authentication and sends PING

You should receive PONG. If you have renamed or disabled commands, ensure they behave as expected.


# Attempt to execute a disabled command (should return an error)
redis-cli -a YOUR_STRONG_REDIS_PASSWORD FLUSHALL

# Attempt to execute a renamed command (should return an error)
redis-cli -a YOUR_STRONG_REDIS_PASSWORD CONFIG GET *
# Correct call of the renamed command
redis-cli -a YOUR_STRONG_REDIS_PASSWORD CONFIG_HIDDEN GET *

If Redis is configured to listen on a private IP, ensure that you can connect from another server using that IP and port 6379, as well as the password.

Backups and Maintenance

Diagram: Backups and Maintenance
Diagram: Backups and Maintenance

Reliable backup and regular maintenance are key aspects of any production system. For Redis, this is especially important, as data is stored in RAM, and its loss can be catastrophic.

1. What to Back Up

For Redis, you need to regularly back up:

  • Redis Persistence Files:
    • dump.rdb: RDB database snapshot file. Contains the full state of Redis data at the time of the snapshot.
    • appendonly.aof: AOF file. Contains a sequence of commands that can be replayed to restore the state.
    These files are usually located in the Redis data directory specified by dir in redis.conf (e.g., /var/lib/redis/6379 or /var/lib/redis).
  • Redis Configuration Files:
    • /etc/redis/redis.conf (or /etc/redis/6379.conf): Main configuration file.
  • Other Important Files: If you use Redis for specific purposes, make sure to back up all related scripts, configurations, or data.

2. Simple Auto-Backup Script

We will create a simple script that will copy Redis persistence and configuration files. This script can be scheduled to run using cron.

Create a directory for backups:


sudo mkdir -p /var/backups/redis
sudo chown redisadmin:redisadmin /var/backups/redis

Create the backup script:


sudo nano /usr/local/bin/backup_redis.sh

Insert the following content. Make sure the paths to RDB/AOF files and configs match your installation.


#!/bin/bash

# Settings
REDIS_DATA_DIR="/var/lib/redis" # Directory where dump.rdb and appendonly.aof are located
REDIS_CONF_FILE="/etc/redis/redis.conf" # Redis configuration file
BACKUP_DIR="/var/backups/redis" # Directory for storing backups
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
BACKUP_NAME="redis_backup_${TIMESTAMP}.tar.gz"

# Check that Redis is running and save RDB before backup
echo "Saving Redis RDB to disk..."
redis-cli -a YOUR_COMPLEX_REDIS_PASSWORD BGSAVE
# Give Redis some time to save
sleep 10

echo "Starting Redis backup..."

# Create archive
sudo tar -czf "${BACKUP_DIR}/${BACKUP_NAME}" \
    -C "${REDIS_DATA_DIR}" dump.rdb appendonly.aof \
    "${REDIS_CONF_FILE}" \
    --remove-files-from "${REDIS_DATA_DIR}" # Optional: if you want to delete old RDB/AOF after copying

# Check for success
if [ $? -eq 0 ]; then
    echo "Redis backup created successfully: ${BACKUP_DIR}/${BACKUP_NAME}"
    # Clean up old backups (e.g., keep only the last 7 days)
    find "${BACKUP_DIR}" -type f -name 'redis_backup_*.tar.gz' -mtime +7 -delete
    echo "Old backups cleaned up."
else
    echo "Error creating Redis backup."
fi

# If you use AOF, you can force a rewrite to reduce its size
# echo "Rewriting AOF file..."
# redis-cli -a YOUR_COMPLEX_REDIS_PASSWORD BGREWRITEAOF

echo "Backup script finished."

Make the script executable:


sudo chmod +x /usr/local/bin/backup_redis.sh

3. Configure Cron for Automatic Backups

Add the script to cron so it runs automatically. For example, every day at 03:00 AM.


sudo crontab -e

Add the following line to the end of the file:


0 3 * * * /usr/local/bin/backup_redis.sh >> /var/log/redis_backup.log 2>&1

This entry means: "At 03:00 every day, every month, every day of the week, run /usr/local/bin/backup_redis.sh and redirect all output to /var/log/redis_backup.log".

4. Where to Store Backups (External S3 / Separate VPS)

Storing backups on the same server as the original data is risky. If the server fails (hardware failure, theft, fire), you will lose both data and backups. Always store critical backups remotely:

  • Cloud Storage (S3-compatible): Amazon S3, DigitalOcean Spaces, Backblaze B2, or similar services. For this, you can modify the backup script by adding an aws s3 cp command (if AWS CLI is installed) or rclone copy to upload the archive to the cloud.
    
    # Example of adding to backup_redis.sh script
    # After successful archive creation:
    # aws s3 cp "${BACKUP_DIR}/${BACKUP_NAME}" s3://your-s3-bucket/redis-backups/
    
  • Separate VPS or Dedicated Server: You can use rsync or scp to copy backups to another one of your servers.
    
    # Example of adding to backup_redis.sh script
    # After successful archive creation:
    # scp "${BACKUP_DIR}/${BACKUP_NAME}" user@remote_server:/path/to/remote/backups/
    
  • Specialized Tools: Such as Restic or BorgBackup, which provide deduplication, encryption, and incremental backups. They require more complex setup but are very efficient.

5. Updates: Rolling vs. Maintenance Window

Updating Redis and the operating system is an important part of maintenance. Approaches to updating:

  • Maintenance Window: A traditional approach where the server or application is temporarily taken offline, updates are performed, and then everything is brought back online.
    • Pros: Easier to implement, less risk of unexpected issues during operation.
    • Cons: Service downtime.
    For Redis, this may include stopping the service, updating, checking, and restarting.
  • Rolling Updates: Applied in clustered or high-availability configurations where individual nodes are updated in sequence without interrupting the entire service.
    • Pros: No downtime.
    • Cons: Significantly more complex to implement, requires multiple Redis instances and replication/failover mechanisms (Redis Sentinel, Redis Cluster).

For a single Redis instance on a VPS, as in our case, the maintenance window approach is usually used. Plan updates during periods of minimal load. Always perform a full backup before updating!

Redis Update Process (from repositories):


sudo systemctl stop redis-server # Stop Redis
sudo apt update && sudo apt upgrade -y # Update system and Redis
sudo systemctl start redis-server # Start Redis
sudo systemctl status redis-server # Check status

When compiling from source, the update process will involve downloading new source code, compiling, and reinstalling, followed by restarting the service.

Troubleshooting + FAQ

In this section, we will cover common issues you might encounter when working with Redis and provide answers to frequently asked questions.

1. Redis is not starting or not responding

Error: After installation or restart, systemctl status redis-server shows "failed" or "inactive".

What to check:

  • Redis Logs: The very first place to look for clues. Check the Redis log file specified in redis.conf (by default /var/log/redis/redis-server.log or /var/log/redis_6379.log).
  • System Logs: Check systemd logs: sudo journalctl -u redis-server.service.
  • Configuration File: Ensure there are no syntax errors in /etc/redis/redis.conf. Any typo can prevent startup.
  • Port Availability: Another process might already be occupying port 6379. Check: sudo ss -tulpn | grep 6379.
  • Permissions: Make sure the Redis user has read permissions for the configuration file, and write permissions for the log directory and data directory (dir in redis.conf).

How to fix: Correct errors in the config, free up the port or change the Redis port, and grant the necessary permissions. After each change, try restarting Redis: sudo systemctl restart redis-server.

2. "Connection refused" when connecting to Redis

Error: When attempting to connect with redis-cli or from an application, you receive "Could not connect to Redis at 127.0.0.1:6379: Connection refused".

What to check:

  • Redis Status: Ensure Redis is running: sudo systemctl status redis-server.
  • bind settings: Check the bind parameter in redis.conf. If it specifies 127.0.0.1, then you can only connect from the same server. If you are trying to connect from another server, bind should be set to the private IP address of the Redis server or 0.0.0.0 (which requires careful firewall configuration).
  • Firewall (UFW): Ensure the firewall is not blocking connections to port 6379. Check UFW status: sudo ufw status. If Redis should be accessible from other IPs, make sure the rule allow 6379 or allow from X.X.X.X to any port 6379 is active.

How to fix: Start Redis, adjust bind in redis.conf and/or firewall rules. Don't forget to restart Redis after changing the config: sudo systemctl restart redis-server.

3. "NOAUTH Authentication required"

Error: You receive this error when trying to execute Redis commands.

What to check: You have set a password (requirepass) in redis.conf but have not provided it when connecting.

How to fix: Provide the password when connecting via redis-cli -a YOUR_PASSWORD or configure your application to use the password.

4. Redis consumes too much memory

Error: Redis is using more memory than expected, or is approaching the maxmemory limit.

What to check:

  • maxmemory and maxmemory-policy: Ensure these parameters are correctly configured in redis.conf.
  • Memory Usage: Use the redis-cli info memory command to get detailed information about Redis memory consumption. Pay attention to used_memory_human and used_memory_peak_human.
  • Data Structures: Check which data structures are stored in Redis and how large they are. The command redis-cli --scan or MEMORY USAGE key (Redis 4.0+) can help.
  • Memory Fragmentation: mem_fragmentation_ratio in redis-cli info memory. A high ratio (more than 1.5) can indicate fragmentation, which increases memory consumption.

How to fix: Increase maxmemory (if free RAM is available), change maxmemory-policy, optimize data storage in Redis, use more compact data structures. Restarting Redis can temporarily reduce fragmentation.

5. What is the minimum suitable VPS configuration?

For basic tasks such as caching a small website or small queues, the minimum configuration is 1 vCPU, 1 GB RAM, and 20 GB SSD. This will be sufficient for Redis storing a few hundred megabytes of data. However, for more serious projects, 2 vCPU, 4 GB RAM, and 80 GB SSD are recommended.

6. What to choose — VPS or dedicated for this task?

The choice between a VPS and a dedicated server depends on the scale of your task, performance requirements, and budget. For most medium and small projects (websites, small SaaS, game servers for friends, personal nodes), a VPS will be more than sufficient and a cost-effective solution. A dedicated server becomes necessary when the data volume in Redis is measured in tens of gigabytes, absolute performance predictability without "noisy neighbors" is required, or when you have very specific hardware requirements.

7. How to monitor Redis?

To monitor Redis, you can use the redis-cli info command (e.g., redis-cli info memory, redis-cli info clients, redis-cli info persistence). For more advanced monitoring, it is recommended to use tools such as Prometheus with Grafana, using a Redis exporter, or specialized server monitoring solutions that collect Redis metrics (e.g., Netdata).

8. Redis Cluster vs Redis Sentinel?

Redis Sentinel provides high availability by automatically failing over to a replica in case of a master failure. It is designed for fault tolerance. Redis Cluster, on the other hand, provides scalability and high availability by allowing data to be distributed across multiple nodes and automatically sharding it. If you only need fault tolerance for a single Redis instance, Sentinel is your choice. If you need to scale data and queries across multiple nodes, use Cluster.

Conclusions and Next Steps

Diagram: Conclusions and Next Steps
Diagram: Conclusions and Next Steps

Congratulations! You have successfully installed and configured Redis on your VPS or dedicated server, ensuring a basic level of security and performance. You now have a powerful tool for caching, session management, message queues, and many other tasks, ready for integration with your applications.

Further steps for optimizing and scaling your Redis installation may include:

  • Monitoring Setup: Integrate Redis with a monitoring system (e.g., Prometheus + Grafana, Netdata) to track memory usage, request count, latencies, and other key metrics. This will help identify issues before they impact your users.
  • Application Performance Optimization: Ensure your application efficiently uses Redis by minimizing the number of requests, using appropriate data structures, and avoiding long blocking operations.
  • Scaling and High Availability: If your project grows, consider setting up Redis Sentinel for automatic failover or Redis Cluster for horizontal scaling and load distribution.

Continue to experiment with various Redis features and integrate it into your projects to unlock the full potential of this amazing tool.

Was this guide helpful?

Your feedback helps us improve our guides.

Share this post:

Send this guide to someone who may find it useful.

Telegram VKVK WhatsApp Facebook LinkedIn XX

Redis installation and configuration on VPS: security and high performance
support_agent
Valebyte Support
Usually replies within minutes
Hi there!
Send us a message and we'll reply as soon as possible.