亲测好用的redis启动管理脚本,如果使用需要根据自己安装的redis相关文件进行调整
我是源码安装的redis-3.0.5
安装路径/usr/local/redis
编辑创建脚本文件:
vim /etc/init.d/redis
#!/bin/sh # # chkconfig: 2345 85 15 # description: this script can manager the redis-server daemon # Redis is a persistent key-value database # exec: /usr/local/redis/bin/redis-server # config: /usr/local/redis/conf/redis.conf # pidfile: /usr/local/redis/logs/redis.pid # datafile: /usr/local/redis/data/redis.rdb redis="/usr/local/redis/bin/redis-server" REDIS_CONF_FILE="/usr/local/redis/conf/redis.conf" prog=$(basename $redis) lockfile=/var/lock/subsys/redis # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 start() { [ -x $redis ] || exit 5 [ -f $REDIS_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $redis $REDIS_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { stop start } reload() { echo -n $"Reloading $prog: " killproc $redis -HUP RETVAL=$? echo } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart) $1 ;; reload) rh_status_q || exit 7 $1 ;; status) rh_status ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" exit 2 esac
修改脚本操作权限,添加可执行权限
chmod 755 /etc/init.d/redis
##### END #####
本文出自 “刺秦手记” 博客,请务必保留此出处http://ciqin.blog.51cto.com/10608412/1794671
原文地址:http://ciqin.blog.51cto.com/10608412/1794671