CentOS7 安裝Redis6.0.10

1、安裝Redis6.0.10需要高版本gcc,所以先臨時升級gcc

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

#臨時將gcc設置爲高版本,會話結束就變回低版本gcc
scl enable devtoolset-9 bash

2、安裝Redis6.0.10

tar zxvf redis-6.0.10.tar.gz
mv redis-6.0.10 redis
cd redis
make
make install

3、修改配置文件

vi /usr/local/redis/redis.conf 

#主要修改的內容
port 18890    #端口
daemonize yes    #後臺運行
pidfile /var/run/redis.pid    #pid文件位置,和啓動腳本保持一至就行

4、啓動腳本

vi /etc/rc.d/init.d/redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
source /etc/init.d/functions
REDISPORT=18890
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli
 
PIDFILE=/var/run/redis.pid
CONF=/usr/local/redis/redis.conf
BIND_IP='0.0.0.0'
 
start(){     
    if [ -f $PIDFILE ]
    then
        echo "$PIDFILE exists, process is already running or crashed"
    else
        echo "Starting Redis server..."
        $EXEC $CONF
    fi
    if [ "$?"="0" ]  
    then  
        echo "Redis is running..." 
    fi 
}
 
stop(){ 
    if [ ! -f $PIDFILE ]
    then
        echo "$PIDFILE does not exist, process is not running"
    else
        PID=$(cat $PIDFILE)
        echo "Stopping ..."       
        $CLIEXEC -h $BIND_IP  -p $REDISPORT  SHUTDOWN 
        sleep 1
        while [ -x /proc/${PID} ]
        do
            echo "Waiting for Redis to shutdown ..."
            sleep 1
        done
            echo "Redis stopped"
    fi
}
 
restart(){
    stop
    start 
}

status(){ 
    ps -ef|grep redis-server|grep -v grep >/dev/null 2>&1 
    if [ $? -eq 0 ];then 
        echo "redis server is running" 
    else
        echo "redis server is stopped" 
    fi
} 
 
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;         
    restart)
        restart
        ;;         
    status)
        status
        ;;     
    *)
     
     echo "Usage: redis-server {start|stop|status|start}" >&2 
     exit 1 
esac

腳本加權限

chmod +x /etc/rc.d/init.d/redis

啓動

service redis start

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章