I. Installation of Redis
1. Create Redis user groups and users
-r-g redis-s/sbin/nologin-m Redis
2. Download the Redis source package and put the source package into the/usr/local/src/directory
Download page:http://redis.io/download
Redis-3.2.5.tar.gz is used here.
:http://download.redis.io/releases/redis-3.2.5.tar.gz
3. Enter the src/directory
cd/usr/local/src/
4. Unzip the source package
TAR-ZXF redis-3.2.5.tar.gz
5. Enter the Redis source directory, compile and install
CD redis-3.2.5/makePREFIX=/usr/local/redis Install
6. Create a Redis file directory
mkdir -p/usr/local/redis/datamkdir -p/usr/local/redis/etcmkdir -P/ var/run/redismkdir -P/var/Log/redis
7. Put the configuration file into the redis/etc/directory
CP redis.conf/usr/local/redis/etc/
8. Modify the Redis configuration file redis.conf
Vim/usr/local/redis/etc/redis.conf
9. Change to the following, save exit
# TCP Queue Length, the CentOS system defaults to 128, this value should not be greater than the operating system's value tcp-backlog# to Yes, to ensure that Redis can run in the background Daemonize Yes#redis pidpidfile/var/run/redis/redis. PID # Redis log logfile "/var/log/redis/redis.log"#redis data store directory dir /usr/local/ redis/data/
10. Modify Redis Directory Permissions
chown -R redis:redis/usr/local/redischown -R redis:redis/var/run/Redis chown -R redis:redis/var/Log/redis
11. Add the Redis command to the environment variable and modify the profile file
Vim/etc/profile
12. Change to the following, save exit
path=/usr/local/mysql/bin:/usr/local/php/bin:/usr/local/redis/bin:$PATH
13. Make the configuration in/etc/profile effective immediately
Source/etc/profile
14. Add the Redis service script to the init.d/directory to create the REDISD file
Vim/etc/init.d/redisd
15. Add the following to save the exit
#!/bin/sh##chkconfig:35#Simple Redis INIT.D script conceived to work on Linux systems#As it does use of the/proc filesystem.. /etc/rc.d/init.d/functions. /etc/sysconfig/Network ["$NETWORKING"=" No "] &&Exit0Redisport=6379BASEDIR=/usr/local/RedisEXEC=$BASEDIR/bin/redis-servercliexec=$BASEDIR/bin/redis-CLI Pidfile=/var/run/redis/redis.pidconf="$BASEDIR/etc/redis.conf "functionstart () {if[-F$PIDFILE] ThenEcho"$PIDFILEexists, process is already running or crashed "Else Echo-N "Starting Redis server ..."Daemon--user=redis--pidfile=$PIDFILE $EXEC $CONF #$EXEC $CONF Echofi}functionStop () {if[!-F$PIDFILE] ThenEcho"$PIDFILEDoes not exist, process was not running "ElsePID=$ (cat$PIDFILE) Echo"Stopping ..."#$CLIEXEC-P $REDISPORT shutdownKillproc-p$PIDFILE $EXEC-INTEcho-N "Waiting for Redis saving data & shutdown." while[-x/proc/${pid}] Do Sleep1Echo-N "." Done Echo-E "\nredis stopped"fi} Case"$"In start) start; stop) stop;; Status) Status-P$PIDFILE $EXEC ;; restart) stop start;; *) Echo"Use Start or stop as first argument" ;; Esac
View Code
16. Add executable permissions for REDISD
chmod +X/ETC/INIT.D/REDISD
17. Joining Redis to system services
Chkconfig--add REDISD
18. Set Boot up
Chkconfig REDISD on
19. Start Redis
Service REDISD Start
Second, PHP7 installation Redis expansion
1.yum Installing Git
Yum-y Install git
2. Enter the src/directory
cd/usr/local/src/
3.git Download Phpredis Expansion
Clone https://github.com/phpredis/phpredis.git
4. Enter the phpredis/directory
CD phpredis/
5. Default clone of php5 Redis extension, need to switch to PHP7 branch
git checkout PHP7
6. Build and install extensions
phpize./configure--with-php-config=/usr/local/php/bin/php-&& make install
7. Modify the php.ini file
Vim/usr/local/php/etc/php.ini
8. Add redis.so extension configuration, save exit
extension=redis.so;
9. Restart Apache or PHP-FPM
service httpd restartservice php-fpm restart
10. Add php files to the web directory, such as adding PHP files to the web directory, such as/usr/local/apache/htdocs/redis.php or/usr/local/nginx/html/redis.php
<? PHP $redis New Redis (); $redis->connect (' 127.0.0.1 ', 6379); $redis->set (' class ', ' TOEFL '); Print_r ($redis->get (' class '));
Access URLs, such as: http://192.168.8.9/redis.php
The page is displayed correctly, the configuration is successful
Building Lnamp Environment (v)-PHP7 source installation Redis and Redis expansion