Centos开机自启动redis

前端之家收集整理的这篇文章主要介绍了Centos开机自启动redis前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

原文链接http://my.oschina.net/indestiny/blog/197272?p={{page}}

[html] view plain copy
  1. #BydefaultRedisdoesnotrunasadaemon.Use'yes'ifyouneedit.
  2. #NotethatRediswillwriteapidfilein/var/run/redis.pidwhendaemonized.
  3. daemonizeyes

  • 编写脚本,vim /etc/init.d/redis:
@H_502_47@copy
#chkconfig:23451090
  • #description:StartandStopredis
  • PATH=/usr/local/bin:/sbin:/usr/bin:/bin
  • REDISPORT=6379#实际环境而定
  • EXEC=/usr/local/redis/src/redis-server#实际环境而定
  • REDIS_CLI=/usr/local/redis/src/redis-cli#实际环境而定
  • PIDFILE=/var/run/redis.pid
  • CONF="/usr/local/redis/redis.conf"#实际环境而定
  • case"$1"in
  • start)
  • if[-f$PIDFILE]
  • then
  • echo"$PIDFILEexists,processisalreadyrunningorcrashed."
  • else
  • echo"StartingRedisserver..."
  • $EXEC$CONF
  • fi
  • if["$?"="0"]
  • then
  • echo"Redisisrunning..."
  • ;;
  • stop)
  • if[!-f$PIDFILE]
  • echo"$PIDFILEexists,processisnotrunning."
  • else
  • PID=$(cat$PIDFILE)
  • echo"Stopping..."
  • $REDIS_CLI-p$REDISPORTSHUTDOWN
  • while[-x$PIDFILE]
  • do
  • echo"WaitingforRedistoshutdown..."
  • sleep1
  • done
  • echo"Redisstopped"
  • restart|force-reload)
  • ${0}stop
  • ${0}start
  • *)
  • echo"Usage:/etc/init.d/redis{start|stop|restart|force-reload}">&2
  • exit1
  • esac

  • 执行权限:
    • 开机自启动:

    猜你在找的CentOS相关文章