用这个脚本管理之前,需要先配置下面的内核参数,否则redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上:
vm.overcommit_memory = 1
然后增加服务并开机自启动:
脚本源码:
#!/bin/bash # # redis - this script starts and stops the redis-server daemon # # chkconfig: - 80 12 # description: redis is a persistent key-value database # processname: redis-server # config: /usr/local/redis/etc/redis.conf # pidfile: /usr/local/redis/var/redis.pid source /etc/init.d/functions bin="/usr/local/redis/bin" config="/usr/local/redis/etc/redis.conf" pidfile="/usr/local/redis/var/redis.pid" ### read configuration [ -r "$sysconfig" ] && source "$sysconfig" retval=0 prog="redis-server" desc="redis server" start() { if [ -e $pidfile ];then echo "$desc already running...." exit 1 fi echo -n $"starting $desc: " daemon $bin/$prog $config retval=$? echo [ $retval -eq 0 ] && touch /var/lock/subsys/$prog return $retval } stop() { echo -n $"stop $desc: " killproc $prog retval=$? echo [ $retval -eq 0 ] && rm -f /var/lock/subsys/$prog $pidfile return $retval } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e /var/lock/subsys/$prog ] && restart retval=$? ;; status) status $prog retval=$? ;; *) echo $"usage: $0 {start|stop|restart|condrestart|status}" retval=1 esac exit $retval
注意:请将脚本中redis的启动文件、配置文件和pid文件存放位置按你配置的位置做相应修改,文件保存的时候注意是unix下可运行的模式,否则在linux下运行的时候会提示错误,/bin/bash^m: bad interpreter: no such file or directory
如对本文有疑问, 点击进行留言回复!!
网友评论