Building and Configuring Redis from Source with systemd Integration

Prerequisites for Building Redis from Source

Before running make test, ensure TCL 8.5 or later is installed:

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
./configure
make
make install

Install the GCC compiler:

yum install gcc -y

Building Redis with systemd Support

Download and compile Redis:

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make USE_SYSTEMD=yes PREFIX=/usr/local/redis/ install

Run the test suite:

make test

Environment Configuration

Verify the binary location:

which redis-server
# Output: /usr/local/redis/bin/redis-server

Add to system PATH by editing /etc/profile:

export PATH=/usr/local/redis/bin:$PATH
source /etc/profile

Configuration Files and Utilities

The main configuration file resides in the source distribution at redis-6.2.6/redis.conf. Copy it to /etc/ for production use.

The utils/ directory contains helpful resources:

  • redis_init_script - traditional init.d startup script
  • utils/systemd-redis_server.service - systemd unit file template

systemd Service Configuraton

Create the service file at /usr/lib/systemd/system/redis_server.service:

[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
Wants=network-online.target
After=network-online.target

[Service]
Type=notify
ExecStart=/usr/local/redis/bin/redis-server /etc/redis.conf --supervised systemd
User=redis
Group=redis

[Install]
WantedBy=multi-user.target

Important notes:

  • Type=notify requires systemd support during compilation (the --supervised systemd flag)
  • Without proper compilation flags, Redis will fail with: systemd supervision requested or auto-detected, but Redis is compiled without libsystemd support!
  • The User and Group directives create and switch to a dedicated service account
  • The binary remains owned by root, but the running process executes under the specified user

Create the Redis user and group before starting the service:

useradd -r redis

Traditional SysV Init Script

The init script from utils/redis_init_script provides port-based configuration:

#!/bin/sh
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]; then
            echo "$PIDFILE exists, process is already running or crashed"
        else
            echo "Starting Redis server..."
            $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]; then
            echo "$PIDFILE does not exist, process is not running"
        else
            PID=$(cat $PIDFILE)
            echo "Stopping ..."
            $CLIEXEC -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]; do
                echo "Waiting for Redis to shutdown ..."
                sleep 1
            done
            echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

Basic Redis CLI Operations

Query configuration parameters:

redis-cli
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""

Modify settings at runtime:

127.0.0.1:6379> config set requirepass mypassword
OK

Authenticate with password:

127.0.0.1:6379> auth mypassword
OK

Connect remotely with authentication:

redis-cli -h 10.0.0.0 -p 6379 -a redispassword
10.0.0.0:6379> info

Access Control in Redis 6+

Redis 6 introduced ACL suppport while maintaining backward compatibility. In default configuration, every new connection can execute all commands and access all keys, matching pre-6.x behavior. The requirepass directive still functions by setting a password for the default user.

Data Directory Configuration

Set the working directory in redis.conf:

dir /opt/redis_data

This location stores RDB snapshots and AOF files.

Troubleshooting Common Issues

Client timeout errors:

redis.Set([...]): read tcp 10:32562->17:6379: i/o timeout

This typically occurs during background save operations. Monitor Redis logs for related entries.

AOF fsync warnings:

* Asynchronous AOF fsync is taking too long (disk is busy?).

Consider adjusting appendfsync settings or upgrading disk I/O performance.

Verify AOF integrity:

redis-check-aof --fix appendonly.aof

Example healthy output:

The AOF appears to start with an RDB preamble.
[info] 3 keys read
[info] 0 expires
RDB preamble is OK, proceeding with AOF tail...
AOF analyzed: size=25484367, ok_up_to=25484367, diff=0
AOF is valid

RDB background saving logs:

* Background saving started by pid 1012
* DB saved on disk
* RDB: 0 MB of memory used by copy-on-write
* Background saving terminated with success

Tags: Redis installation systemd compilation configuration

Posted on Sun, 17 May 2026 21:39:10 +0000 by mechamecha