安裝后redis,默認系統不會自啟動,如果關機或重啟redis不會自行啟動,linux下/etc/init.d/目錄下基本上存放所有系統的大多數的啟動腳本,放在這個目錄下的腳本可以實現自啟動操作。
在 /etc/init.d/目錄下創建redis的shell文件
#!/bin/bash #config:/usr/local/src/redis.conf #pidfile:/var/run/redis.pid source /etc/init.d/functions BIN="/usr/local/bin" REDIS_CONFIG="/usr/local/src/redis.conf" PIDFILE="/var/run/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 $REDIS_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 ;; status) status $prog RETVAL=$? ;; *) echo $"Usage:$0{start|stop|restart|condrestart|status}" RETVAL=1 esac exit $RETVAL
service redis start
service redis stop
service redis restart
service redis status
都正常
將redis加入自啟動計划
cd /etc/init.d/
chmod -R 775 redis
chkconfig --list|grep redis
添加啟動計划到系統
[root@dongzi init.d]# chkconfig --add redis
service redis does not support chkconfi
再在腳本里面加入兩行注釋
# chkconfig: - 20 80
# description: Starts and stops the redis daemon.
運行正常
[root@dongzi init.d]# chkconfig --add redis You have new mail in /var/spool/mail/root [root@dongzi init.d]# chkconfig --list|grep redis redis 0:off 1:off 2:off 3:off 4:off 5:off 6:off You have new mail in /var/spool/mail/root [root@dongzi init.d]# chkconfig --level 2345 redis on [root@dongzi init.d]# chkconfig --list|grep redis redis 0:off 1:off 2:on 3:on 4:on 5:on 6:off