0514-86177077
9:00-17:00(工作日)
用这个脚本管理之前,需要先配置下面的内核参数,否则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
标签:西藏 青岛 延边 南充 通辽 朝阳 雅安 随州
上一篇:收集的48个Shell脚本小技巧
下一篇:awk中实现ord函数功能