首页 > 代码库 > redis3.2.8 设置开机自启动
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 设置开机自启动