首页 > 代码库 > redis3.2.8 设置开机自启动

redis3.2.8 设置开机自启动

  首先在 /etc/init.d中建立redis 文件,文件内容如下:

  1. #!/bin/bash

  2. # redis-3.2.8  - this script start and stop the redis-server daemon

  3. #

  4. # processname: redis-server

  5. # config:      /opt/app/redis-3.2.8/bin/redis.conf  自己redi.conf 文件路径

  6. # pidfile:     /var/run/redis_6379.pid 

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

  8.  

  9. REDISPORT=6379

  10. EX_EC=/opt/app/redis-3.2.8/bin/redis-server

  11. REDIS_CLI=/opt/app/redis-3.2.8/bin/redis-cli

  12.  

  13. PIDFILE=/var/run/redis_6379.pid

  14. CONF="/opt/app/redis-3.2.8/bin/redis.conf"

  15.  

  16. case "$1" in

  17.     start)

  18.         if [ -f $PIDFILE ]

  19.         then

  20.                 echo "$PIDFILE exists, process is already running"

  21.         else

  22.                 echo "Starting Redis server..."

  23.                 $EX_EC $CONF

  24.         fi

  25.         if [ "$?"="0" ]

  26.         then

  27.               echo "Redis is running..."

  28.         fi

  29.         ;;

  30.     stop)

  31.         if [ ! -f $PIDFILE ]

  32.         then

  33.                 echo "$PIDFILE does not exist, process is not running"

  34.         else

  35.                 PID=$(cat $PIDFILE)

  36.                 echo "Stopping ..."

  37.                 $REDIS_CLI -p $REDISPORT SHUTDOWN

  38.                 while [ -x ${PIDFILE} ]

  39.                do

  40.                     echo "Waiting for Redis to shutdown ..."

  41.                     sleep 1

  42.                 done

  43.                 echo "Redis stopped"

  44.         fi

  45.         ;;

  46.    restart|force-reload)

  47.         ${0} stop

  48.         ${0} start

  49.         ;;

  50.   *)

  51.     echo "Usage: /opt/app/redis-3.2.8/bin/redis {start|stop|restart|force-reload}" >&2

  52.         exit 1

  53. 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 设置开机自启动