1、下载目录 /home/user/temp
cd /home/user/temp
wget http://download.redis.io/releases/redis-3.0.1.tar.gz
tar xzf redis-3.0.1.tar.gz
cd redis-3.0.1
make PREFIX=/user/local/redis install #安装到指定目录
安装完后,在/home/local/redis/下可以看到一个bin目录,包含了redis-server,redis-cli等文件
2、复制脚本到/etc/init.d/
在/home/user/temp/redis-3.0.1/utils/下有一个
redis_init_script,复制到
/etc/init.d/
cp /home/user/temp/redis-3.0.1/utils/redis_init_script /etc/init/d/
redis #拷贝并改名为redis
3、修改脚本
vi /etc/init.d/redis
修改完后:
#!/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
注意上面的$EXEC $CONF &
最后一个&表示转到后台运行的意思
4、拷贝redis配置文件/etc/redis/${REDISPORT}.conf
mkdir /etc/redis
cp /home/user/temp/redis-3.0.1/redis.conf /etc/redis/6379.conf
启动服务 service redis start
关闭redis
./redis-cli -p 6379 shutdown