- 获取源码包
wget http://download.redis.io/releases/redis-3.2.11.tar.gz
- 解压
tar -zxf redis-3.2.11.tar.gz
- 编译
cd redis-3.2.11 && make
会在src目录下创建可执行文件, 如下:
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb
- 拷贝到/usr/local/redis/bin下
mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/log
touch /usr/local/redis/log/redis.log
cd src
# 拷贝可执行文件
cp redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb /usr/local/redis/bin/
# 拷贝配置文件
cd .. && cp redis.conf /usr/local/redis/
#修改配置文件如下内容
bind 0.0.0.0
daemonize yes
pidfile /var/run/redis_6379.pid
logfile "/usr/local/redis/log/redis.log"
# 设置RDB保存位置
dir /usr/local/redis
# 开启AOF
appendonly yes
- 再制作一个 init.d 的启动脚本:
vim /etc/init.d/redis-server
#!/usr/bin/env bash
#
PATH=$PATH:/usr/local/redis/bin
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/redis.conf"
#make sure some dir exist
if [ ! -d /var/lib/redis ] ;then
mkdir -p /var/lib/redis
fi
case "$1" in
status)
ps -A|grep redis
;;
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
- 启动redis服务
chmod o+x /etc/init.d/redis-server
service redis-server start
参考博客: https://blog.csdn.net/liqingtx/article/details/60330555