The installation

1. Download the installation package: download it from the official website. You are advised to upload it to the home directory: /usr/local/leyou

2. Unzip

 tar -xvf redis-4.09..tar.gz
Copy the code

3. Compile and install

 mv redis-4.09. redis
 cd redis
 make && make install
Copy the code

configuration

1. Modify the redis.conf file in the installation directory

vim redis.conf
Copy the code

Modify the following configuration:

#bind 127.0. 01.# comment this line of code, listen for all IP addresses, extranet can accessprotected-mode no # change yes to no, daemonize yes # change no to yes, run backgroundCopy the code

Start or stop

Redis provides both server-side commands and client-side commands:

Certificate -server command, which can contain the following parameters: start stop Stop Awkis - CLI client console, including parameters: -h XXX specifies the server address, the default value is127.0. 01.-p XXX Specifies the server port. The default value is6379
Copy the code

Setting boot

1. Run commands to create a file

vim /etc/init.d/redis
Copy the code

Enter the following:

#! /bin/sh # chkconfig:2345 90 10
# description:  Redis is a persistent key-value database
PATH=/usr/local/bin:/sbin:/usr/bin:/bin

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

PIDFILE=/var/run/redis.pid

CONF="/usr/local/leyou/redis/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  
        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 ..."  
                $REDIS_CLI -p $REDISPORT SHUTDOWN  
                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
Copy the code

Then save and exit.

Note — the following information needs to be adjusted according to the installation directory: EXEC=/usr/local/bin/redis-server # Address to execute the script

REDIS_CLI=/usr/local/bin/redis-cli # address where the client executes the script

PIDFILE=/var/run/redis.pid # Process ID File address

CONF=”/usr/local/src/redis-3.0.2/redis. CONF

2. Set permissions

chmod 755 /etc/init.d/redis
Copy the code

3. Start the test

/etc/init.d/redis start
Copy the code

The following information is displayed if the startup is successful:

Starting Redis server...
Redis is running...
Copy the code

4. Set startup

chkconfig --add /etc/init.d/redis
chkconfig redis on
Copy the code