What You'll Learn in This Guide
Redis is one of the most powerful tools you can deploy on a dedicated server. Whether you're running a high-traffic web application, an e-commerce platform, or an API backend, Redis can cut your database load by up to 90% and deliver sub-millisecond response times β all by keeping frequently accessed data in RAM.
At Leo Servers, we've helped hundreds of clients set up Redis on dedicated servers. This guide covers everything you need: installation on Ubuntu and CentOS, essential configuration, security hardening, memory tuning, and a quick performance test to confirm it's working.
Table of Contents
What is Redis & Why Use It
Prerequisites
1. Installing Redis on Ubuntu
2. Installing Redis on CentOS
3. Configuring Redis for Production
4. Securing Redis
5. Enabling Persistence
6. Performance Tuning
7. Application Integration
FAQ & Troubleshooting
What Is Redis and Why Does It Matter for Dedicated Servers?
Redis (Remote Dictionary Server) is an open-source, in-memory data structure store. It functions as a cache, message broker, and NoSQL database simultaneously. Unlike traditional disk-based databases, Redis stores data in RAM, which makes reads and writes orders of magnitude faster.
On a dedicated server, Redis is especially powerful because you have dedicated resources β meaning you can allocate a significant portion of RAM to Redis without competing with other tenants. Common use cases include:
- Session caching β store user sessions in Redis instead of the database
- Object/page caching β cache rendered HTML, API responses, and database query results
- Rate limiting β implement efficient request throttling using Redis counters
- Pub/Sub messaging β build real-time features like notifications and live feeds
- Leaderboards & queues β use sorted sets for game leaderboards or task queues
All Leo Servers dedicated server plans include NVMe SSD storage, but Redis bypasses disk entirely β it lives in RAM. If your app is database-heavy, pairing it with Redis on a gaming dedicated server or GPU server is one of the highest-ROI infrastructure upgrades you can make.
Prerequisites & System Requirements
Before you install Redis on your dedicated server, make sure you have the following in place:
| Requirement | Minimum | Recommended (Production) |
|---|---|---|
| Operating System | Ubuntu 20.04 / CentOS 7 | Ubuntu 22.04 LTS / CentOS 8+ |
| RAM | 512 MB available for Redis | 2 GB+ dedicated to Redis |
| SSH Access | Required (root or sudo user) | SSH key-based auth recommended |
| Firewall | UFW or firewalld installed | Active and configured |
| Redis Version | Redis 6.x | Redis 7.x (latest stable) |
Installing Redis on Ubuntu 22.04
Start by connecting to your dedicated server via SSH. Then follow these steps to install Redis on Ubuntu using the official APT package manager.
Update System Packages
# Update the package index
sudo apt update && sudo apt upgrade -y
Install Redis Server
# Install Redis from the official Ubuntu repository
sudo apt install redis-server -y
Enable & Start the Redis Service
# Enable Redis to start on boot
sudo systemctl enable redis-server
# Start Redis now
sudo systemctl start redis-server
# Verify Redis is running
sudo systemctl status redis-server
Test the Installation
# Connect to the Redis CLI
redis-cli
# Inside redis-cli, type:
127.0.0.1:6379> PING
PONG # β
Redis is running!
# Test basic key-value storage
127.0.0.1:6379> SET leoservers "Hello from Leo Servers"
OK
127.0.0.1:6379> GET leoservers
"Hello from Leo Servers"
127.0.0.1:6379> EXIT
If you received PONG, Redis is installed and running successfully on your Ubuntu dedicated server.
Installing Redis on CentOS / RHEL 8
On CentOS and RHEL-based dedicated servers, the Redis installation process uses the dnf package manager and requires enabling the EPEL repository.
# Enable the EPEL repository
sudo dnf install epel-release -y
# Install Redis
sudo dnf install redis -y
# Enable and start Redis
sudo systemctl enable redis
sudo systemctl start redis
# Verify
sudo systemctl status redis
On CentOS 7, use yum instead of dnf, and the service name is redis (not redis-server). Run: sudo yum install redis -y
Configuring Redis for Production
The Redis configuration file is located at /etc/redis/redis.conf (Ubuntu) or /etc/redis.conf (CentOS). Open it with your preferred editor:
sudo nano /etc/redis/redis.conf
# or on CentOS:
sudo nano /etc/redis.conf
Set the Supervised Mode (Ubuntu Only)
Find the supervised directive and change it from no to systemd:
# Change this:
supervised no
# To this:
supervised systemd
Bind Redis to Localhost
This is a critical security step. By binding Redis to 127.0.0.1, you ensure it only accepts connections from the local server β not the open internet.
# Bind to localhost only (most secure for single-server setups)
bind 127.0.0.1 -::1
# If Redis needs to accept connections from other servers in your network:
# bind 127.0.0.1 10.0.0.5 (replace with your internal IP)
Set a Password for Redis Authentication
# Find the requirepass line and set a strong password:
requirepass YourStrongPasswordHere2025!
# Use a long, random string in production β at least 32 characters
Configure Memory Limit & Eviction Policy
Telling Redis how much RAM it can use β and what to do when that limit is reached β is essential for stable operation on a dedicated server.
# Set the maximum memory Redis can use (adjust to your server's RAM)
maxmemory 512mb
# Eviction policy: remove least recently used keys when memory is full
# Best for caching use cases:
maxmemory-policy allkeys-lru
# Other common policies:
# volatile-lru β evict keys with expiry, LRU order
# allkeys-lfu β evict least frequently used (Redis 4+)
# noeviction β return error when memory full (use for queues, not caches)
Save Your Changes & Restart Redis
# Restart Redis to apply config changes
sudo systemctl restart redis-server # Ubuntu
sudo systemctl restart redis # CentOS
Securing Redis on Your Dedicated Server
An unsecured Redis instance is a serious vulnerability. Redis has been involved in multiple high-profile breaches where attackers exploited exposed Redis ports to write SSH keys and gain root access. Follow these steps to lock it down.
Configure UFW Firewall (Ubuntu)
# Block port 6379 from external access (Redis should be local only)
sudo ufw deny 6379
# If you need Redis accessible from a specific trusted IP only:
sudo ufw allow from 10.0.0.5 to any port 6379
# Enable UFW if not already active
sudo ufw enable
sudo ufw status
Configure firewalld (CentOS / RHEL)
# Remove Redis port from public zone (block external access)
sudo firewall-cmd --zone=public --remove-port=6379/tcp --permanent
# Reload firewall rules
sudo firewall-cmd --reload
Disable Dangerous Redis Commands
Rename or disable commands like FLUSHALL and CONFIG that could be abused if an attacker gains partial access:
# Disable FLUSHALL (wipes ALL Redis data)
rename-command FLUSHALL ""
# Disable FLUSHDB (wipes a specific DB)
rename-command FLUSHDB ""
# Rename CONFIG to a secret name to prevent unauthorized configuration changes
rename-command CONFIG SECRET_CONFIG_9x3k
# Disable DEBUG command (information leak risk)
rename-command DEBUG ""
After renaming CONFIG, update any application code or Redis management tools that use this command to use the new name. Restarting Redis will apply these changes.
Enabling Redis Data Persistence
By default, Redis is a cache β data is lost when the server restarts. For use cases where durability matters (sessions, queues), enable persistence via RDB snapshots or AOF (Append-Only File) logging.
RDB Snapshots (Default)
# Save a snapshot every 900 seconds if at least 1 key changed
save 900 1
# Save every 300 seconds if at least 10 keys changed
save 300 10
# Save every 60 seconds if at least 10,000 keys changed
save 60 10000
# Path for the RDB dump file
dir /var/lib/redis
dbfilename dump.rdb
AOF (Append-Only File) β More Durable
# Enable AOF logging
appendonly yes
appendfilename "appendonly.aof"
# Sync policy:
# always β safest, slowest (writes to disk after every command)
# everysec β good balance (sync every second, recommended)
# no β OS decides (fastest, least safe)
appendfsync everysec
Performance Tuning for Dedicated Servers
On a dedicated server, you have control over OS-level settings that significantly impact Redis performance. These settings prevent Redis from throwing warnings in logs and ensure it operates at full speed.
Disable Transparent Huge Pages (THP)
# Disable THP (Redis recommends this; THP causes latency spikes)
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# Make it permanent across reboots by adding to /etc/rc.local:
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
Set vm.overcommit_memory
# Allow Redis to use more memory during background saves (fork)
sudo sysctl vm.overcommit_memory=1
# Make permanent:
echo "vm.overcommit_memory = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Increase File Descriptor Limits
# Allow Redis to handle more simultaneous connections
maxclients 10000
# Increase the backlog for TCP connections
tcp-backlog 511
Integrating Redis with Your Application
PHP Integration (phpredis extension)
# Install the PHP Redis extension
sudo apt install php-redis -y # Ubuntu
sudo dnf install php-pecl-redis -y # CentOS
# Restart PHP-FPM
sudo systemctl restart php8.1-fpm
Python Integration (redis-py)
# Install redis-py
pip install redis
# Python code:
import redis
r = redis.Redis(
host='127.0.0.1',
port=6379,
password='YourStrongPasswordHere2025!',
decode_responses=True
)
# Store a value with 60-second TTL
r.setex('session:user42', 60, 'active')
# Retrieve
status = r.get('session:user42')
print(status) # Output: active
WordPress Object Cache (WP Redis Plugin)
To use Redis as an object cache in WordPress on your dedicated server, install the Redis Object Cache plugin, then add this to wp-config.php:
// Redis connection settings for WordPress
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PASSWORD', 'YourStrongPasswordHere2025!' );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );
Frequently Asked Questions & Troubleshooting
Troubleshooting
- Redis Not Starting? Check logs via
sudo journalctl -u redis-server -n 50 --no-pager - Connection Refused? Confirm Redis is running and the
binddirective inredis.confis configured correctly. Ensure the firewall isn't blocking internal access. - High Memory Usage? Check memory with
redis-cli INFO memory | grep used_memory_humanand ensure a maxmemory limit is set.
FAQ
Need a Dedicated Server Ready for Redis?
Leo Servers offers high-performance dedicated servers with NVMe SSDs and DDR4 RAM β perfect for Redis deployments that demand speed and reliability.
View Dedicated Server Plans βConclusion
You've successfully learned how to install and configure Redis on a dedicated server β from initial installation on Ubuntu and CentOS, through essential redis.conf settings, security hardening with firewall rules and password authentication, enabling data persistence, and integrating Redis with PHP, Python, and WordPress.
Redis is one of the most impactful performance upgrades you can make on a dedicated server. When properly configured, it can handle hundreds of thousands of requests per second from RAM β transforming slow, database-heavy applications into lightning-fast experiences.
At Leo Servers, our dedicated server infrastructure is purpose-built for workloads like Redis. If you have questions about your Redis configuration or want expert guidance on server setup, our team is ready to help.
Discover Leo Servers Dedicated Server Locations
Leo Servers servers are available around the world, providing diverse options for hosting high-performance environments. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.
