Official Address:

[https://redis.io/download#installation](https://redis.io/download#installation)
Copy the code

Installation steps:

Wget http://download.redis.io/releases/redis-4.0.10.tar.gz tar XVZF redis - stable. Tar. Gzcd redis-stable
make
Copy the code

Installation exception handling:

There should be no problem with the previous 3 steps. The main problem is that an exception occurs when executing make. Error 2: make[2]: cc: Command not found error 2: yum install GCC -C ++

Zmalloc. h:51:31: error: jemalloc/jemalloc. H: No such file or directory Clean it up and make it.

After make succeeds, make test is required. An exception occurred in make test. Error 1: couldn’t execute “tclSH8.5 “: no such file or directory Cause: TCL is not installed. Solution: yum install -y TCL

Configuration:

After make is successful, there are more executables in the SRC directory: redis-server, redis-cli, etc. Run the cp command to copy the file to the /usr/local/bin directory, so that the file can be invoked anywhere on the CLI.

cp redis-server /usr/local/bin/
cp redis-cli /usr/local/bin/
Copy the code

Then create a new directory to store configuration and runtime files

mkdir /user/local/redis   # Save the configuration file
mkdir /var/redis          # store runtime files
mkdir /var/redis/log      # Store LOG files
mkdir /var/redis/run      Save PID file
mkdir /var/redis/6379     # store database files
Copy the code

Find the configuration file template in the redis decompression root directory and copy it to the following location:

cp redis.conf /usr/local/redis/redis.conf
Copy the code

Run the vim command to modify redis.conf

daemonize yes                            # Support background running
pidfile /var/redis/run/redis_6379.pid    Set pid file
logfile /var/redis/log/redis_6379.log    Set the log file
dir /var/redis/6379                      Set the database directory
Copy the code

Finally, you can run Redis as follows:

$ redis-server /usr/local/redis/redis.conf
Copy the code

You are advised to optimize the operating mode as follows: Write a script, vim /etc/init.d/redis

# chkconfig: 2345 10 90
# description: Start and Stop redis

PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379 # Depending on the actual situation
EXEC=/usr/local/bin/redis-server # Depending on the actual situation
REDIS_CLI=/usr/local/bin/redis-cli # Depending on the actual situation

PIDFILE=/var/redis/run/redis_6379.pid
CONF="/usr/local/redis/redis.conf" # Depending on the actual situation
# AUTH="1234

case "The $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 exists, 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)
                The ${0} stop
                The ${0} start
                ;;
        *)
                echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}"2 > &exit 1
esac
Copy the code

Set execution permission:

chmod +x /etc/init.d/redis
Copy the code

Set boot:

Enable automatic service startup
chkconfig redis on
Copy the code

Manual execution mode:

Try to start or stop Redis
service redis start
service redis stop
service redis restart
Copy the code

Build the REDis extension for PHP

  1. Download the Redis extension (pecl.php.net/package/red…) (Stable version)
  2. Tar ZXVF extension package
  3. Expansion pack CD
  4. /php/bin/phpizeExecute ize to generate a configuration file based on the PHP kernel version
  5. Execute command:./configure --with-php-config=/php/bin/php-config
  6. Execute command:make && make install
  7. Copy the directory path of the generated redis. So file (shown after make ends)
  8. vim /php/lib/php.ini Extension = generated path /redis.so
  9. service php-fpm restart

Reference:

Installation: www.cnblogs.com/haoxinyue/p… Set the startup: my.oschina.net/indestiny/b…