linux下redis的安裝及配置啟動__linux

來源:互聯網
上載者:User
wget http://download.redis.io/releases/redis-2.8.6.tar.gz
tar xzf redis-2.8.6.tar.gz
cd redis-2.8.6
make


有是make會報錯 

gcc類的錯誤 則需安裝 gcc

如: 

yum install -y gcc g++ gcc-c++ make
 

此類錯誤

zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory zmalloc.h:55:2: error: #error "Newer version of jemalloc required" make[1]: *** [adlist.o] Error 1 make[1]: Leaving directory `/data0/src/redis-2.6.2/src' make: *** [all] Error 2

解決辦法是:

make MALLOC=libc

zmalloc.o: In function `zmalloc_used_memory':
/usr/local/src/redis-2.8.3/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld 返回 1
make[1]: *** [redis-server] 錯誤 1
make[1]: Leaving directory `/usr/local/src/redis-2.8.3/src'
make: *** [all] 錯誤 2


make後面加一個參數

make CFLAGS="-march=i686"  


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服務。


redis-server   redis.conf
4、然後用用戶端測試一下是否啟動成功。


redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

---------------------------------------------------------------------------------------------------------
然後自己動手製作一個redis啟動指令碼方便管理
1、vim /etc/rc.d/init.d/redisd


#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis
 
PROGDIR=/usr/redis #安裝路徑
PROGNAME=redis-server
DAEMON=$PROGDIR/$PROGNAME
CONFIG=/usr/redis.conf
PIDFILE=/var/run/redis.pid
DESC="redis daemon"
SCRIPTNAME=/etc/rc.d/init.d/redisd
 
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
        ;;
esac
exit 0


2、增加服務並開機啟動
cp ./redisd /etc/rc.d/init.d/redisd
chmod +x /etc/rc.d/init.d/redisd
chkconfig --add redisd
chkconfig --level 345 redisd on
chkconfig --list redisd
執行該指令碼後,就可以開始start|stop|restart|list你的服務了。



提示:

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


補充:這是最開始安裝所使用的方法,後來發現有人用的方法更好更簡單,另起一篇轉載 點擊開啟連結

聯繫我們

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