操作系统:CentOS7.2 64位
一、安装Redis
1.下载最新版本:
1$ wget http://download.redis.io/releases/redis-4.0.8.tar.gz 2$ tar xzf redis-4.0.8.tar.gz 3$ cp -p redis-4.0.8 /usr/local/redis4 4$ cd redis4 5$ make
这样就安装成功
2. 运行redis, 进入src目录,运行下面命令
$ src/redis-server
3. 测试:
1$ src/redis-cli 2redis> set hello world 3OK 4redis> get hello 5"world"
4. 自启动
1$ cp /usr/local/redis4/redis.conf /etc/redis.conf 2$ vim /etc/redis.conf 3编辑如下 4daemonize yes 5 6$ cp /usr/local/redis4/utils/redis_init_script /etc/rc.d/init.d/redis 7$ cd /etc/rc.d/init.d/ 8$ vim redis #把里面的运行目录换成你自己的,并加上chkconfig和description 9 10 11#!/bin/sh 12# 13# Simple Redis init.d script conceived to work on Linux systems 14# as it does use of the /proc filesystem. 15# chkconfig: 2345 90 10 16# description: Redis is a persistent key-value database 17 18REDISPORT=6379 19EXEC=/usr/local/redis4/src/redis-server 20CLIEXEC=/usr/local/redis4/src/redis-cli 21 22PIDFILE=/var/run/redis_${REDISPORT}.pid 23CONF="/etc/redis.conf" 24 25case "$1" in 26 start) 27 if [ -f $PIDFILE ] 28 then 29 echo "$PIDFILE exists, process is already running or crashed" 30 else 31 echo "Starting Redis server..." 32 $EXEC $CONF 33 fi 34 ;; 35 stop) 36 if [ ! -f $PIDFILE ] 37 then 38 echo "$PIDFILE does not exist, process is not running" 39 else 40 PID=$(cat $PIDFILE) 41 echo "Stopping ..." 42 $CLIEXEC -p $REDISPORT shutdown 43 while [ -x /proc/${PID} ] 44 do 45 echo "Waiting for Redis to shutdown ..." 46 sleep 1 47 done 48 echo "Redis stopped" 49 fi 50 ;; 51 *) 52 echo "Please use start or stop as first argument" 53 ;; 54esac
自启动:
1$ chkconfig redis on 2 3$ service redis start #启动 4$ service redis stop #关闭服务
二、安装Redis PHP扩展
1.下载安装扩展
1$ wget http://pecl.php.net/get/redis-4.0.0RC2.tgz 2$ tar zxvf redis-4.0.0RC2.tgz 3$ cd redis-4.0.0RC2 4 5$ /usr/local/php7/bin/phpize ----给PHP动态添加扩展命令,在php的bin目录下 6$ ./configure -with-php-config=/usr/local/php7/bin/php-config 7$ make && make install
2.在php.ini里添加扩展名称
1$ vim /usr/local/php7/etc/php.ini 2extension=redis.so --添加扩展名称