Before you can use this script to manage, you need to configure the following kernel parameters, otherwise the Redis script will error when you restart or stop Redis, and you cannot automatically synchronize data to disk before stopping the service:
Copy Code code as follows:
# vi/etc/sysctl.conf
Vm.overcommit_memory = 1
Then the application takes effect:
Copy Code code as follows:
Then add the service and boot from:
Copy Code code as follows:
# chmod 755/etc/init.d/redis
# Chkconfig–add Redis
# chkconfig–level 345 Redis on
# chkconfig–list Redis
Script Source:
#!/bin/bash # # Redis-this script starts and stops the Redis-server daemon # chkconfig:-# 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" $SYS CONFIG "Retval=0 prog=" Redis-server desc= "Redis server" start () {if [-e $PIDFILE];then echo $desc Alrea
Dy 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 "in Start" start;;
stop) stop;;
restart) restart;;
Condrestart) [-e/var/lock/subsys/$prog] && restart retval=$?
;;
Status $prog retval=$?
;; * echo $ "Usage: $ {start|stop|restart|condrestart|status}" retval=1 Esac exit $RETVAL
Note: Please modify the Redis boot file, configuration file and PID file location in your script according to the location you configured, and note that the file is stored in a UNIX-run mode, otherwise you will be prompted for errors when running under Linux/bin/bash^m:bad Interpreter:no such file or directory