How to Install and Configure Redis 7 from Source on Ubuntu 24.04 VPS for Optimal Performance
Introduction
At ByteHosting, we understand the importance of low-latency caching for high-performance applications. Redis 7 is a powerful in-memory data structure store that can significantly boost your application's speed when properly installed and optimized. In this guide, we will walk you through how to install redis from source on Ubuntu 24.04, ensuring you get the best performance tailored to your VPS environment.
Prerequisites: Ubuntu 24.04 VPS setup and required packages
Before we begin, ensure your Ubuntu 24.04 VPS is up and running. You should have root or sudo privileges to install necessary packages and configure services. Our recommended packages include build tools and dependencies required for compiling Redis:
sudo apt update
sudo apt install build-essential tcl libjemalloc-dev
These packages provide the compiler, build tools, and jemalloc, which Redis uses for optimized memory allocation.
Download Redis 7 source code from the official repository
Next, we fetch the latest Redis 7 source code from the official Redis repository. It's best to download the stable release to ensure reliability:
cd /usr/local/src
sudo curl -O http://download.redis.io/releases/redis-7.0.0.tar.gz
After downloading, extract the archive:
sudo tar xzf redis-7.0.0.tar.gz
cd redis-7.0.0Compile and install Redis 7 from source
Now, compile Redis using the provided makefile. This process optimizes Redis for your system:
sudo make -j$(nproc)
Once compilation completes successfully, run the Redis test suite to verify the build:
sudo make testFinally, install Redis binaries into your system:
sudo make installThis installs the redis-server, redis-cli, and redis-benchmark commands.
Configure Redis for performance optimization (memory, persistence, security)
Configuration is key to achieving optimal Redis performance. Create a dedicated configuration directory:
sudo mkdir /etc/redisCopy the default configuration file:
sudo cp redis.conf /etc/redis/redis.confOpen the configuration file for editing:
sudo nano /etc/redis/redis.confKey settings to optimize include:
- Memory management: Set
maxmemoryandmaxmemory-policyto control how Redis handles memory limits and eviction policies. - Persistence: Disable or configure RDB and AOF persistence based on your needs. For caching, disabling persistence can improve performance.
- Security: Bind Redis to localhost or a specific IP, and set a strong password with
requirepass.
Example snippet for high-performance caching:
bind 127.0.0.1
requirepass yourStrongPassword
maxmemory 2gb
maxmemory-policy allkeys-lru
appendonly no
save ""
Start Redis as a systemd service and enable on boot
To manage Redis easily, create a systemd service file:
sudo nano /etc/systemd/system/redis.serviceInsert the following content:
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=root
Group=root
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.targetReload systemd, start Redis, and enable it to run on boot:
sudo systemctl daemon-reload
sudo systemctl start redis
sudo systemctl enable redisCheck Redis status:
sudo systemctl status redisVerify Redis installation and performance benchmarks
Ensure Redis is running correctly by connecting with the CLI:
redis-cli -a yourStrongPassword pingIf Redis responds with PONG, your installation is successful. To benchmark performance, use the redis-benchmark tool:
redis-benchmark -a yourStrongPassword -n 100000 -c 50This command tests Redis with 100,000 requests across 50 concurrent connections, giving you an idea of its throughput.
Troubleshoot common issues: memory leaks, connection problems, performance bottlenecks
If you encounter issues, consider the following:
- Memory leaks: Monitor Redis memory usage with
redis-cli info memory. Adjustmaxmemoryand eviction policies as needed. - Connection problems: Ensure Redis is bound to the correct IP and the firewall allows incoming connections on port 6379.
- Performance bottlenecks: Check system resources, optimize Redis configuration, and consider upgrading your VPS plan for more CPU or RAM.
Conclusion
Installing redis from source on Ubuntu 24.04 allows you to fine-tune Redis 7 for low-latency caching and high performance. By compiling from source, configuring for your workload, and setting up as a systemd service, you ensure a reliable and efficient Redis deployment. At ByteHosting, our cost-effective VPS plans in Frankfurt provide the perfect environment to run Redis at scale. Whether you're building a caching layer or a real-time data store, this setup will serve you well for years to come.