廢話少說,直接來步驟:
1、設定redis.conf中daemonize為yes,確保守護程序開啟。
2、編寫開機自啟動指令碼
vi /etc/init.d/redis指令碼內容如下:
# chkconfig: 2345 10 90# description: start and stop redis3、寫完後儲存退出vipath=/usr/local/bin:/sbin:/usr/bin:/bin
redisport=6379exec=/usr/redisbin/redis-server
redis_cli=/usr/redisbin/redis-cli
pidfile=/var/run/redis.pid
conf="/usr/redisbin/redis.conf"auth="1234"
case "$1" instart)
if [ -f $pidfile ]
then
echo "$pidfile exists, process is already running or crashed."
elseecho "starting redis server..."$exec $conf
fi
if [ "$?"="0"]
then
echo "redis is running..."fi
;;
stop)
if [ ! -f $pidfile ]
then
echo "$pidfile exists, process is not running."
elsepid=$(cat $pidfile)
echo "stopping..."$redis_cli -p $redisport shutdown
sleep 2
while [ -x $pidfile ]
doecho "waiting for redis to shutdown..."sleep 1done
echo "redis stopped"fi
;;
restart|force-reload)
$ stop
$ start
;;
*)
echo "usage: /etc/init.d/redis " >&2exit 1esac
4、設定許可權
chmod 755 redis5、啟動測試
/etc/init.d/redis start啟動成功會提示如下資訊:
starting redis server...使用redis-cli測試:redis is running...
[root@rk ~]# /usr/redisbin/redis-cli6、設定開機自啟動127.0.0.1:6379> setfoo bar
ok127.0.0.1:6379> getfoo
"bar"
127.0.0.1:6379> exit
chkconfig redis on7、關機重啟測試
reboot然後在用redis-cli測試即可。
Linux下Redis開機自啟(Centos)
特別說明 1.以下這些變數得配置成自己的。且 pidfile 應為 var run redis pid.不修改這裡,stop的時候關不掉。redisport 6379 exec usr redisbin redis server redis cli usr redisbin redis cli pi...
Linux下Redis開機自啟(Centos)
廢話少說,直接來步驟 1 設定redis.conf中daemonize為yes,確保守護程序開啟。2 編寫開機自啟動指令碼 vi etc init.d redis指令碼內容如下 chkconfig 2345 10 90 description start and stop redis path us...
Linux下Redis開機自啟(Centos)
1 設定redis.conf中daemonize為yes,確保守護程序開啟。2 編寫開機自啟動指令碼 vi etc init.d redis指令碼內容如下 chkconfig 2345 10 90 description start and stop redis path usr local bin...