第一步 下载解压

wget http://download.redis.io/rele...

tar –zxvf redis-5.0.0.tar.gz

第二步 编译并安装

cd redis-5.0.0

make -j cat /proc/cpuinfo | grep processor| wc -l && make install

启动Redis服务

进入刚才安装redis的目录,编译安装的基本都在/usr/local/bin

cd /usr/local/bin

./redis-server

测试:

cd /usr/local/bin

./redis-cli

ping

返回 pong

安装成功

第三步设置自定义目录

mkdir -p /storage/redis/db 数据存储目录

mkdir -p /storage/redis/confg 配置文件目录

mkdir -p /storage/redis/log log文件目录
拷贝设置相关文件

1、redis.conf

cd /usr/local/redis-5.0.0/ 拷贝redis.conf到 /storage/redis/confg

cp /usr/local/redis-5.0.0/redis.conf /storage/redis/confg

2、cd /root/redis/utils 拷贝启动脚本到init目录

cp /root/redis/utils/redis_init_script /etc/init.d/redis

3、修改两份文件的数据目录,端口,日志文件路径等。

4、测试:

启动:/usr/local/bin/redis-server /usr/local/redis-5.0.0/storage/redis/confg/redis.conf

链接redis:/usr/local/bin/redis-cli -p 26379

测试:ping

回应pong

第四步 添加系统服务,系统重启Redis自动启动

添加redis系统服务

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

chkconfig --add redis

chkconfig --level 2345 redis on

chkconfig --list | grep redis

修改redis文件

!/bin/sh

Simple Redis init.d script conceived to work on Linux systems

as it does use of the /proc filesystem.

BEGIN INIT INFO

Provides: redis_6379

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: Redis data structure server

Description: Redis data structure server. See https://redis.io

END INIT INFO

REDISPORT=6379

EXEC=/usr/local/bin/redis-server

CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid

CONF="/usr/local/redis-5.0.0/storage/redis/config/redis_8300.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


exception
69 声望1 粉丝