1.编译源码,生成可执行文件;

2.将生成的可执行文件拷贝到 /user/local/bin目录下,若没有x权限请加上;

3.将安装包中的 redis.conf配置文件移到/etc/redis.conf;并设置相应的配置值:

daemonize yes //将该属性设为yes,默认非后台启动

pidfile /var/run/redis.pid //将pid文件设为此值

4.编写启动脚本:redis-server:内容可如下所示:

#! /bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DAEMON=/usr/local/bin/redis-server

DAEMON_ARGS=/etc/redis.conf

NAME=redis-server

DESC=redis-server

PIDFILE=/var/run/redis.pid

case "$1" in

start)

echo -n "Starting $DESC: "

touch $PIDFILE

chown redis:redis $PIDFILE

${DAEMON} $DAEMON_ARGS

;;

stop)

echo -n "Stopping $DESC: "

if start-stop-daemon --stop --retry 10 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON

then

echo "$NAME."

else

echo "failed"

fi

rm -f $PIDFILE

;;

restart|force-reload)

${0} stop

${0} start

;;

*)

echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2

exit 1

;;

esac

exit 0

5. 将启动脚本移至/etc/init.d/redis-server,并加x权限

6.执行 update-rc.d redis-server defaults,开机启动,重启机器

7.可使用下面方式启动或关闭redis: 

sudo service redis-server start 或者/etc/init.d/redis-server starts

sudo service redis-server stop 或者/etc/init.d/redis-server stop

05-11 13:48