centOS安裝redis3.0.6

吳峻申發表於2016-06-30

1. 安裝

尋找一個初始安裝目錄

cd /usr/local/share/applications  
wget http://download.redis.io/releases/redis-3.0.6.tar.gz
tar zxvf redis-3.0.6.tar.gz
cd redis-3.0.6
cd  /src
make&make install
make test

如果顯示

You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

表示需要安裝tcl

安裝tcl

 wget http://downloads.sourceforge.net/tcl/tcl8.5.12-src.tar.gz
 tar zxvf tcl8.5.12-src.tar.gz
 cd tcl8.5.12/unix
 ./configure options
 make
 make test
 make install

2. 設定redis為開機自啟動的系統服務

修改redis安裝根目錄下的redis.conf檔案,修改下列這段

# By default Redis does not run as a daemon. Use 'yes' if you need it. 
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized. 
daemonize yes

執行命令

cp redis.conf /etc
rename  redis.conf 6379.conf(建議重新命名為埠,方便做redis叢集配置)
cp redis-benchmark redis-cli redis-server /usr/bin/

如果沒有/var/rdb/
則建立該目錄

mkdir  /var/rdb/

新建reids自啟動指令碼
新建檔案redis,放入/etc/init.d目錄下

redis啟動指令碼內容示例:

#!/bin/sh
# chkconfig: 2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/bin/redis-server 
CLIEXEC=/usr/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/${REDISPORT}.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
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

賦予許可權

chmod +x /etc/init.d/redis

加入到系統服務中

如果沒有redis

chkconfig --add  redis

如果有

chkconfig redis on

嘗試啟動或停止redis

service redis start
service redis stop

重啟系統

reboot

兩種確認redis是否已開機自啟動的方法

ps -ef | grep redis

結果

圖1

或輸入

redis-cli  

輸入ping返回PONG即redis執行OK

圖2

相關文章