Redis officially provides source installation and an official tutorial. If you prefer the original version, click here. This post is more of a translation and some extra notes. Also a quick review of common commands.
Installation
The official approach is source installation.
$ wget http://download.redis.io/redis-stable.tar.gz
# 解压,释放源代码文件
$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
# 编译
$ make
In the src directory, you will see these executable scripts:
- redis-server the Redis server itself
- redis-sentinel is the Redis Sentinel executable (monitoring and failover).
- redis-cli Redis interactive CLI
- redis-benchmark used to check Redis performance
- redis-check-aof and redis-check-dump are useful in the rare event of corrupted data files.
Copy the binaries
Run the following two commands in src:
sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/
Or simply run sudo make install.
Startup
In practice, you should set it up as a service with auto-start for easier management. For example:
- Create directories for Redis config and data
sudo mkdir /etc/redis
sudo mkdir /var/redis
- Copy the init script under
utilsto/etc/init.d
sudo cp utils/redis_init_script /etc/init.d/redis
- Edit the init script
sudo vi /etc/init.d/redis
- Specific edits
#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/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
Compared with the original config, the key differences are:
#chkconfig: 2345 80 90$EXEC $CONF &
- Register the service
# 注册服务
$ chkconfig -add redis
- Enable auto-start
$ chkconfig redis on
Install via yum
The above is source installation, which is more tedious. Using yum is much simpler.
$ yum install -y redis
After installation, just start the service.

