設置redis開機啟動

設置redis開機啟動

使用下面的方法要注意的是安裝文件路徑和配置文件的路徑。

[root@localhost?~]#?vi?/etc/init.d/redis

復制下面代碼到腳本中(注意要修改里面redis的安裝路徑,不清楚find查找下)
(這段代碼就是redis根目錄 /utils/redis_init_script 啟動腳本的代碼)

#!/bin/sh #?chkconfig:?2345?10?90?? #?description:?Start?and?Stop?redis???  REDISPORT=6379 EXEC=/usr/local/bin/redis-server CLIEXEC=/usr/local/bin/redis-server  PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/etc/redis/redis.conf"  case?"$1"?in ????start) ????????if?[?-f?$PIDFILE?] ????????then ????????????????echo?"$PIDFILE?exists,?process?is?already?running?or?crashed" ????????else ????????????????echo?"Starting?Redis?server..." ????????????????$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?to?shutdown?..." ????????????????????sleep?1 ????????????????done ????????????????echo?"Redis?stopped" ????????fi ????????;; ????restart) ????????"$0"?stop ????????sleep?3 ????????"$0"?start ????????;; ????*) ????????echo?"Please?use?start?or?stop?or?restart?as?first?argument" ????????;; esac

設置權限

[root@localhost?~]#?chmod?777?/etc/init.d/redis

設置開機啟動

?chkconfig?redis?on

啟動測試

?service?start?redis

更多相關知識請關注redis入門教程欄目

以上就是設置

? 版權聲明
THE END
喜歡就支持一下吧
點贊6 分享