redis3.2.8 设置开机自启动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis3.2.8 设置开机自启动相关的知识,希望对你有一定的参考价值。
首先在 /etc/init.d中建立redis 文件,文件内容如下:
#!/bin/bash
# redis-3.2.8 - this script start and stop the redis-server daemon
#
# processname: redis-server
# config: /opt/app/redis-3.2.8/bin/redis.conf 自己redi.conf 文件路径
# pidfile: /var/run/redis_6379.pid
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EX_EC=/opt/app/redis-3.2.8/bin/redis-server
REDIS_CLI=/opt/app/redis-3.2.8/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/opt/app/redis-3.2.8/bin/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running"
else
echo "Starting Redis server..."
$EX_EC $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: /opt/app/redis-3.2.8/bin/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
给文件添加执行权限 chmod +x redis
加入服务 chkconfig redis on
测试启动:service redis start
测试停止:service redis stop
测试成功后,加入到linux开机启动 vi /etc/rc.d/rc.local 加入下面内容
service redis start
大功告成,重启启动liunx时,redis 服务就会自动启动了
本文出自 “菜鸟” 博客,请务必保留此出处http://gjp014.blog.51cto.com/2393413/1949181
以上是关于redis3.2.8 设置开机自启动的主要内容,如果未能解决你的问题,请参考以下文章