Installing and Configuring Redis 7 on Linux
Prerequisites: GCC Compiler Setup
Understanding GCC
GCC (GNU Compiler Collection) is the standard compiler suitee for Linux systems, supporting multiple programming languages including C, C++, Fortran, Java, and Ada. It can target various architectures such as x86, x86-64, PowerPC, SPARC, and ARM.
Before installing Redis, you need the C++ development environment:
yum -y install gcc-c++
Verify the installation:
gcc -v
Selecting a Redis Version
Check your current Redis version:
redis-server -v
Note: Due to security vulnerabilities in older versions, ensure you use version 6.0.8 or higher. This guide uses Redis 7.0.
Installation Steps for Redis 7
Step 1: Download the Package
Place the downloaded archive in the /opt directory:
wget https://download.redis.io/releases/redis-7.0.0.tar.gz
Step 2: Extract the Archive
tar -zxvf redis-7.0.0.tar.gz
Step 3: Build and Install
Navigate to the extracted directory and compile:
cd redis-7.0.0
make && make install
Step 4: Locate Installation Directory
The default binaries are installed in /usr/local/bin. Key executables include:
- redis-server - Server startup command
- redis-cli - Command-line client interface
- redis-benchmark - Performance testing utility
- redis-check-aof - AOF file repair tool
- redis-check-dump - RDB file repair tool
Copy the default configuration to a custom location:
mkdir -p /myredis
cp /opt/redis-7.0.0/redis.conf /myredis/
Step 5: Configure Redis
Edit the configuration file in /myredis/redis.conf with these essential changes:
- Change
daemonize notodaemonize yesto run as a background service - Change
protected-mode yestoprotected-mode nofor external connections - Comment out or modify
bind 127.0.0.1to allow remote access - Set a password with
requirepass your_secure_password
Restart the service after making changes.
Step 6: Start the Server
redis-server /myredis/redis.conf
Step 7: Connect to Redis
Without password authentication:
redis-cli
With password:
redis-cli -a your_password -p 6379
To suppress security warnings:
redis-cli -a your_password 2>/dev/null
Step 8: Stop the Service
For single instance:
redis-cli -a your_password shutdown
For multiple instances (specify port):
redis-cli -p 6379 shutdown
Step 9: Uninstall Redis
First, stop the running service:
redis-cli -a your_password shutdown
Remove installed binaries:
ls -l /usr/local/bin/redis-*
rm -rf /usr/local/bin/redis-*