There is a Utils folder under the Redis source directory , which provides the Install_server.sh installation tool to generate a self-booting Redis script.
[[email protected]]# cd utils/[[email protected] utils]# ./install_server.sh Welcometo the redis service installerThisscript will help you easily set up a running redis server pleaseselect the redis port for this instance: [6379] selectingdefault: 6379pleaseselect the redis config file name [/etc/redis/6379.conf] /usr/local/redis/etc/ redis.confpleaseselect the redis log file name [/var/log/redis_6379.log] / Usr/local/redis/log/redis.logpleaseselect the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/data/Pleaseselect the redis executable path [/usr/local/redis/bin/redis-server] selectedconfig:port : 6379configfile : /usr/local/redis/etc/redis.conflogfile :/usr/local/redis/log/redis.logdatadir : /usr/local/ redis/data/executable : /usr/local/redis/bin/redis-servercliexecutable : /usr/local/redis/bin/redis-cliis thisok? then press enter to go on or ctrl-c to abort. Copied/tmp/6379.conf => /etc/init.d/redis_6379installingservice ... successfullyadded to chkconfig! successfullyadded to runlevels 345! Startingredis server ... installationsuccessful!
According to the actual situation, fill in the configuration file, log file, rdb/aof data storage directory
The script reads as follows:
[[email protected] utils]# cat /etc/init.d/redis_6379#!/bin/sh#configurationsinjected by install_server below.... exec=/usr/local/redis/bin/redis-servercliexec=/usr/local/ redis/bin/redis-clipidfile=/var/run/redis_6379.pidconf= "/usr/local/redis/etc/redis.conf" REDISPORT= "6379" ###### ########## sysvinit information#chkconfig: - 58 74#description: redis_6379 is the redis daemon.## #BEGIN init info#provides: redis_6379#required-start: $network $local _fs $remote _fs#required-stop: $network $local _fs $remote _fs# default-start: 2 3 4 5#default-stop: 0 1 6#should-start: $syslog $named #should-stop: $syslog $named #short-description: start and stop redis_6379# Description: redis daemon### endinit info case "$" in start) if [ -f $PIDFILE ] then echo "$PIDFILE Exists, processis already running or crashed " else echo "Starting redisserver $EXEC $CONF fi ;; stop) if [ ! -f $ pidfile ] then echo "$PIDFILE does not exist,process is not Running " else pid=$ (cat $PIDFILE) echo "stopping   $CLIEXEC -p $ redisport shutdown while [ -x /proc/${pid} ] do echo " WAITING FOR REDIS TOSHUTDOWN&NBSP: " sleep 1 done echo "redis Stopped " fi ;; status) pid=$ (cat $PIDFILE) if [ ! -x /proc/${PID} ] then echo ' redis is not running ' else echo "redis is running ($PID)" fi ;; restart) $0 stop $0 start ;; *) echo "PleAse use start, stop,restart or status as first argument " ;; Esac
To add a service and change the run level:
[[email protected] utils]# chkconfig--add redi_6379[[email protected] utils]# chkconfig--level redi_6379
This article is from the "HUNT" blog, make sure to keep this source http://hunt1574.blog.51cto.com/1390776/1631780
Configure Redis self-boot scripts