Redis開機啟動指令碼Centos6.5

來源:互聯網
上載者:User

Redis開機啟動指令碼Centos6.5
一:安裝Redis1、下載源碼,解壓縮後編譯源碼

# wget http://download.redis.io/releases/redis-2.8.3.tar.gz# tar xzf redis-2.8.3.tar.gz# cd redis-2.8.3# make
2、進入安裝目錄的src檔案夾下,有四個可執行檔redis-server、redis-benchmark、redis-cli和redis.conf,複製到同一個目錄下 
# mkdir /usr/redis# cp redis-server  /usr/redis# cp redis-benchmark /usr/redis# cp redis-cli  /usr/redis# cp redis.conf  /usr/redis# cd /usr/redis
3、啟動Redis服務。
# cd /usr/redis# ./redis-server redis.conf
4、用戶端測試。 
redis 127.0.0.1:6379>  #顯示此行意味著安裝成功。
二:設定redis開機啟動環境:Linux-Centos6.61.編寫啟動指令碼

注意:預設的redis.conf檔案參數是前台啟動的,修改daemonize no為daemonize yes則為後台啟動。

指令碼的編碼格式在window上編碼放在linux可能不識別,可以用UltraEdit轉換下格式“檔案-->轉換-->DOS 轉 UNIX“

#!/bin/sh#chkconfig: 345 86 14#description: Startup and shutdown script for Redis PROGDIR=/usr/redis #安裝路徑PROGNAME=redis-serverDAEMON=$PROGDIR/$PROGNAMECONFIG=/usr/redis/redis.confPIDFILE=/var/run/redis.pidDESC="redis daemon"SCRIPTNAME=/etc/rc.d/init.d/redis start(){         if test -x $DAEMON         then        echo -e "Starting $DESC: $PROGNAME"                   if $DAEMON $CONFIG                   then                            echo -e "OK"                   else                            echo -e "failed"                   fi         else                   echo -e "Couldn't find Redis Server ($DAEMON)"         fi} stop(){         if test -e $PIDFILE         then                   echo -e "Stopping $DESC: $PROGNAME"                   if kill `cat $PIDFILE`                   then                            echo -e "OK"                   else                            echo -e "failed"                   fi         else                   echo -e "No Redis Server ($DAEMON) running"         fi} restart(){    echo -e "Restarting $DESC: $PROGNAME"    stop         start} list(){         ps aux | grep $PROGNAME} case $1 in         start)                   start        ;;         stop)        stop        ;;         restart)        restart        ;;         list)        list        ;;          *)        echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2        exit 1        ;;esacexit 0

把redis指令檔放在 /etc/rc.d/init.d/ 目錄下

2、增加服務並開機啟動
# chmod +x /etc/rc.d/init.d/redis# chkconfig --add redis# chkconfig --level 345 redis on# chkconfig --list redis
3、重啟測試。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.