Databases 12 min read

Redis 8.2.1 on CentOS 8: Source Install, Config Hardening & Common Fixes

This guide walks through installing Redis 8.2.1 on CentOS 8 from source code, covering dependency setup, compilation, configuration hardening (bind, daemonize, protected-mode, password), directory permissions, service verification, systemd integration, and troubleshooting common issues like jemalloc errors, firewall blocks, systemd failures, and memory overcommit warnings.

Cilantro Loves Linux
Cilantro Loves Linux
Cilantro Loves Linux
Redis 8.2.1 on CentOS 8: Source Install, Config Hardening & Common Fixes

Introduction

Redis in production almost always runs on Linux due to its stability, resource scheduling efficiency, and distributed support. However, operators frequently encounter missing gcc dependencies, configuration parameter errors, and remote port access failures during installation. This article focuses on CentOS 8, covering the complete flow from source compilation to service verification, along with solutions for high-frequency problems, to help build a production-ready Redis environment.

1. Full Redis Installation Process on CentOS 8

Production environments prefer source compilation (customizable configuration, hardware adaptation). Using stable Redis 8.2.1 as an example:

1.1 Check and Install Build Dependencies (gcc)

Redis compilation requires a C environment. Verify gcc installation:

# Check if gcc is installed (output means installed, no output means install needed)
rpm -qa | grep gcc

If not installed, install gcc, gcc-c++, and make via dnf (CentOS 8 package manager):

# Install gcc and C++ build dependencies (-y auto-confirms)
sudo dnf install -y gcc gcc-c++ make
# Verify installation: version output indicates success
gcc --version

1.2 Download Redis Source Package (Official Source)

Download from the official Redis website to avoid third-party mirror risks:

# Enter /usr/local/src (conventional source storage path)
cd /usr/local/src
# Download Redis 8.2.1 source package (official URL, stable speed)
sudo wget https://download.redis.io/releases/redis-8.2.1.tar.gz

If wget: command not found appears, install wget first: sudo dnf install -y wget.

1.3 Extract and Compile

# Extract tar.gz package
sudo tar -xzf redis-8.2.1.tar.gz
# Enter extracted source directory
cd redis-8.2.1
# Start compilation (core step; no error output means success)
sudo make

Compilation takes about 1-3 minutes; wait for the terminal prompt to return (if errors, see troubleshooting section).

1.4 Install to Specified Directory (Ease of Maintenance)

After compilation, install Redis to a unified path (recommended /usr/local/redis) to avoid scattered files:

# PREFIX specifies install directory; generates bin and other subdirectories
sudo make install PREFIX=/usr/local/redis

Advantage: subsequent upgrades/uninstalls only require operating on /usr/local/redis, meeting production "directory standardization" requirements.

1.5 Optimize Configuration File (Critical for Production)

Redis ships without a config file; copy from source and modify core parameters:

# Create config directory
sudo mkdir -p /usr/local/redis/etc
# Copy config file to install directory
sudo cp /usr/local/src/redis-8.2.1/redis.conf /usr/local/redis/etc/
# Change config file ownership
sudo chown -R $USER:$USER /usr/local/redis/etc/redis.conf
# Edit config file
vim /usr/local/redis/etc/redis.conf

Modify three core parameters (search quickly with /parameter_name):

bind 0.0.0.0 — Default is bind 127.0.0.1 (local-only). Change to allow remote connections from other servers (combined with firewall and password for security).

daemonize yes — Default is daemonize no (foreground, stops when terminal closes). Change to run in background, ensuring service stability independent of terminal.

protected-mode no — Default is protected-mode yes (blocks remote connections to prevent unauthorized access). Disable to allow remote connections (recommend setting a password simultaneously).

Additional settings :

# Set password (prevent unauthorized access)
# requirepass YourStrongPassword123!
requirepass Redis_123!

# Specify log file
logfile /var/log/redis/redis.log

# Set data directory
dir /usr/local/redis/data

# PID file path
pidfile /usr/local/redis/redis.pid

Save and exit: press Esc, then type :wq (w save, q quit).

1.6 Create Required Directories and Set Permissions

# Create data directory
sudo mkdir -p /usr/local/redis/data
# Create log directory
sudo mkdir -p /var/log/redis
# Set permissions
sudo chown -R $USER:$USER /usr/local/redis
sudo chown -R $USER:$USER /var/log/redis

1.7 Start Redis Service and Verify

# Enter install directory bin folder
cd /usr/local/redis/bin
# Start Redis with config file
./redis-server ../etc/redis.conf

Verify service is running (three common methods):

Check process: ps -ef | grep redis-server Check port listening: ss -tunlp | grep 6379 Command-line connection test:

./redis-cli -a Redis_123!
> ping
PONG
> info server

1.8 Create Systemd Service (Recommended)

Adjust config file: set daemonize no (systemd manages daemonization).

vim /usr/local/redis/etc/redis.conf
# daemonize no

Create systemd service file: sudo vim /etc/systemd/system/redis.service Add the following content:

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecStop=/usr/local/redis/bin/redis-cli -a Redis_123! shutdown
Restart=always

[Install]
WantedBy=multi-user.target

Enable and start service:

# Create redis user
sudo useradd -r redis
# Set directory permissions
sudo chown -R redis:redis /usr/local/redis
sudo chown -R redis:redis /var/log/redis
# Reload systemd
sudo systemctl daemon-reload
# Enable auto-start on boot
sudo systemctl enable redis
# Start service
sudo systemctl start redis
# Check status
sudo systemctl status redis

2. High-Frequency Linux Installation Problem Solutions

2.1 Compilation Error: "jemalloc/jemalloc.h: No such file or directory"

Cause: Redis defaults to jemalloc memory allocator (not bundled in source; some CentOS systems lack it).

Solution: Install jemalloc and recompile:

# Install jemalloc
sudo dnf install -y jemalloc jemalloc-devel
# Clean and recompile
make distclean
make

2.2 Remote Connection Failure (telnet server_ip 6379 unreachable)

Cause: CentOS firewall has not opened Redis port.

Solution: Open port 6379:

# Open port 6379 permanently
sudo firewall-cmd --permanent --add-port=6379/tcp
sudo firewall-cmd --reload
# Verify port status
sudo firewall-cmd --list-ports

2.3 Systemd Starts but Process Disappears Quickly

Cause 1: Config file daemonize not set to no. Fix: Modify config and restart.

Cause 2: Insufficient directory permissions. Fix:

sudo chown -R redis:redis /usr/local/redis
sudo chown -R redis:redis /var/log/redis

2.4 Memory Overcommit Warning

Solution: Modify system config:

sudo sysctl vm.overcommit_memory=1
# Make permanent
echo "vm.overcommit_memory=1" | sudo tee -a /etc/sysctl.conf

Conclusion

The core of Linux Redis installation is "source compilation for flexibility, configuration hardening for security" : source compilation adapts to different server hardware; standardized directory installation eases maintenance; bind address, background run, firewall port, and other configs directly affect service availability and security.

Next article "Redis Client Mastery: CLI + GUI Tools" will focus on daily Linux operations: common Redis CLI commands (data CRUD, cluster management), GUI tools (RDM/AnotherRedisDesktop) connecting to Linux Redis, cache data monitoring and backup, helping operators efficiently manage production Redis services.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

RedisconfigurationfirewallLinuxtroubleshootingsystemdsource compilationCentOS 8
Cilantro Loves Linux
Written by

Cilantro Loves Linux

Focused on Linux system operations and maintenance technology exchange, regularly publishing in-depth technical articles covering core areas such as system architecture, performance optimization, and security hardening. Whether you are a beginner or a seasoned expert, you can find valuable resources to enhance your skills and solve problems here. Follow us to explore the mysteries of Linux operations!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.