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 jemalloc to reduce memory fragmentation
  • Quick Fixes: Quickly apply security patches in production

Environment Requirements

DependencyRequirement
CompilerGCC >= 10 or Clang >= 13 (C11 support required)
Build ToolGNU make
OptionalOpenSSL 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:

FileDescription
redis-serverRedis server
redis-cliCommand line client
redis-benchmarkPerformance benchmark tool
redis-check-aofAOF file repair tool
redis-check-rdbRDB 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.