源碼安裝Redis

1、下載

http://download.redis.io/releases/redis

2、安裝

#解壓
tar -zxf redis-5.0.6.tar.gz
#移動
mv redis-5.0.6 /opt
#進入目錄
cd /opt/redis-5.0.6
#編譯
make
#進入src
cd src
#安裝
make install

make install 安裝到指定目錄,默認在/usr/local/binvim

3、修改配置文件

#進入配置文件所在目錄
cd /opt/redis-5.0.6
#修改
vim redis.conf

能夠修改的內容以下:bash

#全部IP均可以訪問
bind 0.0.0.0
#稍後進行開機啓動,須要將守護模式打開
daemonize yes

4、開機啓動

編寫腳本spa

vim /etc/init.d/redis

腳本內容code

#!/bin/sh  
#chkconfig: 2345 80 90  
# Simple Redis init.d script conceived to work on Linux systems  
# as it does use of the /proc filesystem.  
REDISPORT=6379                          #端口號,這是默認的,若是你安裝的時候不是默認端口號,則須要修改
REDISPATH=/usr/local/bin/                #redis-server啓動腳本的所在目錄,你若是忘了能夠用find / -name redis-server 或whereis redis-server找到 
EXEC=${REDISPATH}/redis-server            
CLIEXEC=${REDISPATH}/redis-cli  
PIDFILE=/var/run/redis_${REDISPORT}.pid  #在redis.conf中可找到該路徑
CONF="/opt/redis-5.0.6/redis.conf"           #redis.conf的位置, 若是不和redis-server在同一目錄要修改爲你的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  
    ;;  
  *)  
    echo "Please use start or stop as first argument"  
    ;;  
esac

給腳本受權server

chmod 777 /etc/init.d/redis

啓動redisip

/etc/init.d/redis start

設置開機啓動get

chkconfig redis on
相關文章
相關標籤/搜索