11.2.3 Redis的启动停止

11.2.3  Redis的启动停止

Redis安装配置完成后,启动过程非常简单,执行命令/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf即可。停止Redis的最简单的方法是在启动实例的session中,直接使用Control-C命令。当然还可以通过客户端来停止服务,如可以用shutdown来停止Redis实例,具体命令为src/redis-cli shutdown。

下面是一个Shell脚本(供参考),用于管理Redis(启动、停止、重启)。为其赋予可执行权限,即可像其他服务一样使用。

  1. #!/bin/sh  
  2. #  
  3. # redis - this script starts and stops the redis-server daemon  
  4. #  
  5. # chkconfig:   - 85 15  
  6. # description:  Redis is a persistent key-value database  
  7. # processname: redis-server  
  8. # config:      /usr/local/redis-2.4.X/bin/redis-server  
  9. # config:      /usr/local/ /redis-2.4.X/etc/redis.conf  
  10. # Source function library.  
  11. . /etc/rc.d/init.d/functions  
  12. # Source networking configuration.  
  13. . /etc/sysconfig/network  
  14. # Check that networking is up.  
  15. [ "$NETWORKING" = "no" ] && exit 0  
  16. redis="/usr/local/webserver/redis-2.4.X/bin/redis-server" 
  17. prog=$(basename $redis)  
  18. REDIS_CONF_FILE="/usr/local/webserver/redis-2.4.X/etc/redis.conf" 
  19. [ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis  
  20. lockfile=/var/lock/subsys/redis  
  21. start() {  
  22.     [ -x $redis ] || exit 5  
  23.     [ -f $REDIS_CONF_FILE ] || exit 6  
  24.     echo -n $"Starting $prog: "  
  25.     daemon $redis $REDIS_CONF_FILE  
  26.     retval=$?  
  27.     echo  
  28.     [ $retval -eq 0 ] && touch $lockfile  
  29.     return $retval  
  30. }  
  31. stop() {  
  32.     echo -n $"Stopping $prog: "  
  33.     killproc $prog -QUIT  
  34.     retval=$?  
  35.     echo  
  36.     [ $retval -eq 0 ] && rm -f $lockfile  
  37.     return $retval  
  38. }  
  39. restart() {  
  40.     stop  
  41.     start  
  42. }  
  43. reload() {  
  44.     echo -n $"Reloading $prog: "  
  45.     killproc $redis -HUP  
  46.     RETVAL=$?  
  47.     echo  
  48. }  
  49. force_reload() {  
  50.     restart  
  51. }  
  52. rh_status() {  
  53.     status $prog  
  54. }  
  55. rh_status_q() {  
  56.     rh_status >/dev/null 2>&1  
  57. }  
  58. case "$1" in  
  59.     start)  
  60.         rh_status_q && exit 0  
  61.         $1  
  62.         ;;  
  63.     stop)  
  64.         rh_status_q || exit 0  
  65.         $1  
  66.         ;;  
  67.     restart|configtest)  
  68.         $1  
  69.         ;;  
  70.     reload)  
  71.         rh_status_q || exit 7  
  72.         $1  
  73.         ;;  
  74.     force-reload)  
  75.         force_reload  
  76.         ;;  
  77.     status)  
  78.         rh_status  
  79.         ;;  
  80.     condrestart|try-restart)  
  81.         rh_status_q || exit 0  
  82.     ;;  
  83.     *)  
  84.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart| reload|orce-reload}"  
  85.         exit 2  
  86. esac  
原文地址:https://www.cnblogs.com/mfryf/p/4643222.html