不多说,直接入正题。
1.到官网下载redis,然后解压到合适的目录
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxvf redis-3.2.8.tar.gz
make
make install
2.进入文件夹,找到redis.conf,修改以下内容,配置redis作为守护进程运行(即后台运行)
daemonize yes //默认为no,这里改为yes
3.配置初始化脚本,进入etc/init.d文件夹,创建redis文件
cd /etc/init.d
vim redis
在redis文件内加入以下内容
/#!/bin/sh
/# chkconfig: 2345 10 90
/# description: redis
/#
/# processname: redis-server
/# config:/opt/redis-2.8.13/redis.conf //你自己的redis配置文件,目录要写对
/# pidfile:/var/run/redis.pid //pid文件所在位置,可以在redis.conf中查看或者修改
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/opt/redis-2.8.13/src/redis-server
REDIS_CLI=/opt/redis-2.8.13/src/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/opt/redis-2.8.13/redis.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
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 R
保存退出,并给文件redis加上可执行权限
chmod +x redis
5.如果redis已经启动,先手动关掉redis,要不然你直接service redis stop的话可能会出现redis.pid not found的问题
redis-cli
quit
6.启动redis
service redis restart #或者service redis start
大功告成。