上传安装包并解压
解压命令
tar -zxvf redis-5.0.5
安装
进入redis-5.0.5目录执行安装命令
先建好安装目录/usr/local/redis-5.0.5
make
make PREFIX=/usr/local/redis-5.0.5 install
在将redis.conf拷贝到/usr/local/redis-5.0.5
进入/usr/local/redis-5.0.5 ,启动redis
./bin/redis-server redis.conf
设置自启
建立启动脚本
vi /etc/init.d/redis
启动脚本在编译后的redis-5.0.5/utils/redis_init_script
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### 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 #redis的默认端口, 要和下文中的redis.conf中一致
EXEC=/usr/local/redis-5.0.5/bin/redis-server #redis服务端的命令
CLIEXEC=/usr/local/redis-5.0.5/bin/redis-cli #redis客户端的命令 这两个一般都在 PATH目录下
PIDFILE=/var/run/redis.pid #reids的进程文件生成的位置,与redis.conf中的保持一致
CONF="/usr/local/redis-5.0.5/redis.conf" #redis的配置文件所在的目录
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
修改文件的权限为 可执行的 chmod a+x /etc/init.d/redis
测试一下redis 的启动
/etc/init.d/redis start
添加到自启动列表
#chkconfig --add redis
#chkconfig redis on
#chkconfig --list //查看所有注册的脚本文件