Centos7下redis-3.2.8安裝(單機版)

一、[官網]下載redis-3.2.8

二、經過FTP(WinSCP,FileZilla等)工具上傳到「/usr/local/redis」目錄

三、安裝前準備

yum install gcc tcl

四、使用解壓命令解壓到當前目錄

tar -zvxf redis-3.2.8.tar.gz

五、編譯源碼

make PREFIX=/usr/local/redis/redis install MALLOC=libc

六、複製「/usr/local/redis/redis-3.2.8/」目錄下的redis.conf文件到「/usr/local/redis/redis」目錄下,並命名爲6379.conf

七、修改6379.conf

#將原有的綁定到127.0.0.1註釋掉換成ip地址,否則遠程沒法鏈接
#bind 127.0.0.1 
bind 192.168.213.210

八、啓動redis

./redis-server 6379.conf

九、設置開機啓動

複製「/usr/local/redis/redis-3.2.8/utils」目錄下的「redis_init_script 」文件到「/usr/local/redis/redis/bin」目錄下,並命名爲redis 修改文件內容以下redis

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

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

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/redis/bin/${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

十、修改6379.conf文件

daemonize yes

十一、設置權限和開機啓動

#設置權限
chmod 755 redis
#設置開機啓動
#修改/etc/下的rc.local添加以下命令
su - root -c '/usr/local/redis/redis/bin/redis start'
相關文章
相關標籤/搜索