1.创建文件redis
touch redis
2.文件内容如下:
#!/bin/sh
#
# chkconfig: 2345 90 10
# description:Redis is a persisitent key-value database
#
#
# author: caicongyang
# email:1491318829@qq.com
# description:this script help you to start redis with linux system service,like this:
# service redis start|stop|restart
# while you use this script ,please Grant it execute permission
# this script test in CentOS 6.7 final and redis 3.0.7
# if you need redis install document ,please visit http://blog.youkuaiyun.com/caicongyang/article/details/50639052
#
#
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/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 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
3.unix文件格式
如果是你在windows编辑的然后上传到服务器的,需要修改文件格式
否者执行报错:/bin/sh^M: bad interpreter: No such file or directory
vi命令行下:(vi按esc进入命令行模式)
:set ff=unix
或
:set fileformat=unix
4.设置文件执行权限
#chmod+x redis
5.设置开机启动
让上文的文件copy 到/etc/init.d/目录下面
#chkconfig --add redis
#chkconfig --level 2345 redis on
执行
#chkconfig --list redis
显示redis在2345运行基本启动开启成功
更多精彩内容请继续关注我的博客:http://blog.youkuaiyun.com/caicongyang
记录与分享,你我共成长
-fromcaicongyang