Centos7.5下編譯安裝Redis5.0

Centos7.5下編譯安裝Redis5.0redis

一、去redis的官網下載( https://redis.io/download )最新穩定版本vim

 

下載解壓編譯Redis:bash

$ wget http://download.redis.io/releases/redis-5.0.2.tar.gz
$ tar xzf redis-5.0.2.tar.gz
$ cd redis-5.0.2
$ make

二、配置Redis測試

  • 在local下建立redis,複製剛編譯好的redis 程序到這文件夾下
[root@zzming redis-5.0.2]# mkdir /usr/local/redis
[root@zzming redis-5.0.2]# cd src/
[root@zzming src]# pwd
/mnt/soft/redis-5.0.2/src
---copy program
[root@zzming src]# cp redis-server /usr/local/redis/.
[root@zzming src]# cp redis-cli /usr/local/redis/.
[root@zzming src]# cp redis-check-aof /usr/local/redis/.
[root@zzming src]# cp redis-check-rdb /usr/local/redis/.
[root@zzming src]# cp redis-sentinel /usr/local/redis/.
[root@zzming src]# cp redis-benchmark /usr/local/redis/.
---copy config
[root@zzming src]# cd ..
[root@zzming redis-5.0.2]# cp redis.conf /usr/local/redis/.
  •  修改redis.conf 配置文件,爲了使redis能在後臺運行,將原先daemonize no 改成 daemonize yes ,保存退出。
daemonize yes

三、創建redis 自動啓動腳本, 在 /etc/init.d/下, 建立名爲:redisspa

vim /etc/init.d/redis
#! /bin/bash
# chkconfig: 2345 89 90
# description: Start and Stop redis

REDISPORT=6379
REDISPATH=/usr/local/redis
EXEC=${REDISPATH}/redis-server
REDIS_CLI=${REDISPATH}/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="${REDISPATH}/redis.conf"
AUTH="1234"

case "$1" in
        start)
                if [ -f $PIDFILE ]
                then
                        echo "$PIDFILE exists, process is already running or crashed."
                else
                        echo "Redis Starting......."
                        $EXEC $CONF
                fi
                if [ "$?"="0" ]
                then
                        echo "Redis is running......"
                fi
                ;;
        stop)
                if [ ! -f $PIDFILE ]
                then
                        echo "$PIDFILE exists, process is not running."
                else
                        PID=$(cat $PIDFILE)
                        echo "Redis Stopping......."
                       $REDIS_CLI -p $REDISPORT  SHUTDOWN
                        sleep 2
                       while [ -x $PIDFILE ]
                       do
                                echo "Waiting for Redis to shutdown..."
                               sleep 1
                        done
                        echo "Redis Stopped"
                fi
                ;;
        restart|force-reload)
                ${0} stop
                ${0} start
                ;;
        *)
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
                exit 1
esac
  • 加入開機啓動項
chkconfig --add redis

四、測試一下吧,能夠這樣使用3d

service redis stop
service redis start
service redis restart

OK,Redis安裝配置測試完畢。rest

相關文章
相關標籤/搜索