This is article 39 in the Big Data series. This article introduces compiling and installing Redis from source on big data cluster nodes, and completing basic startup configuration.
Complete illustrated version: CSDN Original | Juejin
Why Compile from Source
Compared to package manager installation, advantages of compiling from source:
- Version Control: Specify any version without being limited by system repositories
- Customization: Enable optional features like TLS, JSON modules, systemd integration
- Performance Tuning: Choose memory allocators like
jemallocto reduce memory fragmentation - Quick Fixes: Quickly apply security patches in production
Environment Requirements
| Dependency | Requirement |
|---|---|
| Compiler | GCC >= 10 or Clang >= 13 (C11 support required) |
| Build Tool | GNU make |
| Optional | OpenSSL development library (TLS support), TCL >= 8.5 (test suite) |
# Install build dependencies on Ubuntu/Debian
apt-get install -y gcc make
Download Source Code
wget http://download.redis.io/releases/redis-6.2.9.tar.gz
Extract and Organize Directory
tar -zxvf redis-6.2.9.tar.gz
mv redis-6.2.9 /opt/servers/
Compile and Install
cd /opt/servers/redis-6.2.9/src
make
# Install to specified directory
mkdir -p /usr/redis
make install PREFIX=/usr/redis
After installation, the /usr/redis/bin/ directory will contain the following executables:
| File | Description |
|---|---|
redis-server | Redis server |
redis-cli | Command line client |
redis-benchmark | Performance benchmark tool |
redis-check-aof | AOF file repair tool |
redis-check-rdb | RDB file check tool |
Configuration
Copy the default configuration file to the installation directory and modify it:
cp /opt/servers/redis-6.2.9/redis.conf /usr/redis/bin/
vim /usr/redis/bin/redis.conf
Key configuration items:
# Run as daemon (background)
daemonize yes
# Listen on all network interfaces (default only listens on 127.0.0.1)
bind 0.0.0.0
# Disable protected mode (internal cluster environment)
protected-mode no
# Port (default 6379)
port 6379
# Log file path
logfile "/usr/redis/data/redis.log"
# Data directory
dir /usr/redis/data
mkdir -p /usr/redis/data
Start Redis
cd /usr/redis/bin
./redis-server redis.conf
Verify Connection
redis-cli -h 127.0.0.1 -p 6379
After entering the interactive command line:
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
"world"
View Process and Stop
# View Redis process
ps -ef | grep redis
# Graceful shutdown via redis-cli
./redis-cli shutdown
# Or kill directly
kill -9 <pid>
System Tuning Recommendations
For production environments, it is recommended to modify the following kernel parameters:
# Prevent OOM during fork
echo 1 > /proc/sys/vm/overcommit_memory
# Disable transparent huge pages to reduce memory latency
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# Increase file descriptor limit (high concurrency scenarios)
ulimit -n 65535
# Reduce swap usage
echo 1 > /proc/sys/vm/swappiness
Write the above parameters to /etc/sysctl.conf for persistent effect.