Quickly Compile and Install Redis on Linux – Full Step‑by‑Step Guide
This guide walks you through downloading, extracting, compiling, and installing Redis from source on Ubuntu, configuring its files and startup scripts, securing the service, enabling automatic boot start, and performing data migration with detailed commands and examples.
1. Compile and Install Redis
Download and extract the source package:
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxvf redis-3.2.8.tar.gz
cd redis-3.2.8Run make to build the binaries. After compilation you will see directories such as src, deps, and configuration files.
Install the binaries: sudo make install The installer copies executables like redis-server and redis-cli to /usr/local/bin.
2. Organise Deployment Files
Create unified directories for binaries and configuration files:
sudo mkdir -p /usr/local/redis/bin
sudo mkdir -p /usr/local/redis/etcMove the main configuration file:
sudo mv redis-3.2.8/redis.conf /usr/local/redis/etc/Move essential executables to the binary directory:
sudo mv redis-3.2.8/src/redis-server \
redis-3.2.8/src/redis-cli \
redis-3.2.8/src/redis-sentinel \
/usr/local/redis/bin/3. Configure and Start the Redis Service
Edit /usr/local/redis/etc/redis.conf to set required parameters, for example:
daemonize yes
port 63700
bind 10.10.101.127
logfile "/usr/local/redis/etc/redis_63700.log"
requirepass b6Pbc42gP8hXPNLzZaDnhREijtn1BSVSIYTkhTXw8SuPGpWZvN5kVpVeEVBdEQDw7M/+EZuDS6FxTOtgD2QrPe6014LPEdv2DY+YSUQZ4cE="
rename-command FLUSHALL "tinywangithubFLUSHALL"
rename-command CONFIG "tinywangithubCONFIG"
rename-command SHUTDOWN "tinywangithubSHUTDOWN"
rename-command DEBUG "tinywangithubDEBUG"Start Redis with the custom configuration:
sudo /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis63700.confVerify the process is running: ps -aux | grep redis Test the service using redis-cli:
redis-cli -h 127.0.0.1 -p 63700 -a b6Pbc42gP8hXPNLzZaDnhREijtn1BSVSIYTkhTXw8SuPGpWZvN5kVpVeEVBdEQDw7M/+EZuDS6FxTOtgD2QrPe6014LPEdv2DY+YSUQZ4cE=
set username tinywan
get usernameIf you encounter the protected‑mode error, edit redis.conf to set protected-mode no.
4. Enable Redis to Start on Boot (Ubuntu 16.04)
Create an init script /etc/init.d/redis (sample excerpt shown below). The script defines start/stop actions and uses the variables REDISPORT, EXEC, CONF, and PIDFILE.
#!/bin/sh
# Simple Redis init.d script for Linux
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CONF="/usr/local/redis/etc/redis_6379.conf"
PIDFILE=/var/run/redis_${REDISPORT}.pid
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 ..."
/usr/local/bin/redis-cli -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"
;;
esacRegister the script to start automatically: sudo update-rc.d redis defaults Or use systemd (if available):
sudo systemctl start redis
sudo systemctl stop redisCheck the service status with ps -aux | grep redis.
5. Shut Down Redis
Graceful shutdown via client: redis-cli -h 127.0.0.1 -p 6379 shutdown Force kill by PID:
ps -ef | grep redis
kill -9 <em>PID</em>6. Redis Data Migration
Locate the RDB dump file: sudo find / -name dump.rdb Copy the dump to the target host:
scp ./dump.rdb [email protected]:/home/www/redis/Typical migration steps:
Stop the destination Redis instance.
Transfer the RDB or AOF file.
Configure dir in redis.conf or enable AOF.
Start the Redis service again.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
