CentOS 6.6 安裝Redis 及自訂啟動指令碼

來源:互聯網
上載者:User

一、安裝

1.官方:http://www.redis.cn/download.html

2.下載、解壓、編譯

wget http://download.redis.io/releases/redis-2.8.18.tar.gz  tar xzf redis-2.8.18.tar.gz   cd redis-2.8.18  make  

(註:執行make時可能會出現的錯誤:1.未安裝gcc,請先:yum intsall gcc;2.安裝報錯 error: jemalloc/jemalloc.h: No such file or directory;解決方案:make 換==》make MALLOC = libc)


3.設定檔指定到自訂/use/local/redis

mkdir /usr/local/redis  cp src/redis-server  /usr/local/redis  cp src/redis-benchmark /usr/local/redis  cp src/redis-cli  /usr/local/redis  cp redis.conf  /usr/local/redis  

4.測試並啟動

cd /usr/local/redis  ./redis-server redis.conf 



二、通過自訂指令碼,設定開機啟動

1.啟動指令碼

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

vi /etc/init.d/redis
將一下指令碼複製到/etc/init.d/redis

#!/bin/sh#chkconfig:2345 80 90#description: Startup and shutdown script for Redis PROGDIR=/usr/local/redis #安裝路徑PROGNAME=redis-serverDAEMON=$PROGDIR/$PROGNAMECONFIG=/usr/local/redis/redis.conf PIDFILE=/var/run/redis.pidDESC="redis daemon"SCRIPTNAME=/etc/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
2.增加服務並設定開機啟動

chmod +x /etc/init.d/redis  chkconfig --add redis  chkconfig --level 345 redis on  chkconfig --list redis 

3.測試

ps -ef |grep redis //是否已經有redis執行個體service redis stopservice redis start

4.開放6379連接埠,供遠端連線

vi /etc/sysconfig/iptables //開放6379

service iptables restart //重啟

5.遠端連線:兩種方式

a.安裝:

sudo apt-get install redis-tools

b.直接telnet



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.