centos 7 安装 redis 3.2.9

 在centos 7 系统中安装redis 3.2.9的过程方法。

下载redis3.2.9软件包

 
 
bash
  1. cd /usr/local
  2. #下载安装包
  3. wget http://download.redis.io/releases/redis-3.2.9.tar.gz

解压

 
 
bash
  1. tar -xzvf redis-3.2.9.tar.gz
  2. #重命名文件夹
  3. mv redis-3.2.9 redis
  4. cd redis

编译安装

 
 
bash
  1. make
  2. #完成后会在上一层文件夹生成bin目录,都移动到redis目录中
  3. #bin目录中有redis-server、redis-cli等文件
  4. mv bin redis

设置配置文件

 
 
bash
  1. cp redis.conf /etc/

指定配置文件启动redis服务

 
 
bash
  1. cd src
  2. [root@localhost src]# ./redis-server /etc/redis.conf

使用内置的客户端命令redis-cli进行使用

 
 
bash
  1. #使用src目录或bin目录中的redis-cli启动
  2. [root@localhost src]# ./redis-cli
  3. 127.0.0.1:6379> 
  4. redis> set test bar
  5. OK
  6. redis> get test
  7. "bar"


centos 7 添加 redis 3.2.9 开机启动脚本

 在centos7系统中给redis 3.2.9 添加设置开机启动脚本,当系统重启后每次都自动启动redis服务,省去手动进行启动。

centos redis 3.2.9 启动脚本,其中的一些路径可以根据实际安装路径进行更改,脚本代码来自网络实测可用

centos 7 安装 redis 3.2.9流程:http://zixuephp.net/article-267.html

 
 
bash
  1. #在启动文件夹创建脚本文件
  2. vim /etc/init.d/redis
 
 
bash
  1. #!/bin/sh 
  2. # chkconfig:   345 86 14
  3. # description:  Redis is a persistent key-value database
  4. PATH=/usr/local/redis/bin:/sbin:/usr/bin:/bin
  5.     
  6. REDISPORT=6379 
  7. EXEC=/usr/local/redis/bin/redis-server
  8. REDIS_CLI=/usr/local/redis/bin/redis-cli
  9.     
  10. PIDFILE=/var/run/redis_6379.pid
  11. CONF="/etc/redis.conf"
  12.     
  13. case "$1" in
  14.   start) 
  15.     if [ -f $PIDFILE ] 
  16.     then
  17.         echo "$PIDFILE exists, process is already running or crashed"
  18.     else
  19.         echo "Starting Redis server..."
  20.         $EXEC $CONF 
  21.     fi
  22.     if [ "$?"="0" ]  
  23.     then
  24.        echo "Redis is running..."
  25.     fi
  26.     ;; 
  27.   stop) 
  28.     if [ ! -f $PIDFILE ] 
  29.     then
  30.         echo "$PIDFILE does not exist, process is not running"
  31.     else
  32.         PID=$(cat $PIDFILE) 
  33.         echo "Stopping ..."
  34.         $REDIS_CLI -p $REDISPORT SHUTDOWN 
  35.         while [ -x ${PIDFILE} ] 
  36.         do
  37.           echo "Waiting for Redis to shutdown ..."
  38.           sleep 1 
  39.         done
  40.         echo "Redis stopped"
  41.     fi
  42.     ;; 
  43.   restart|force-reload) 
  44.     ${0} stop 
  45.     ${0} start 
  46.     ;; 
  47.  *) 
  48.   echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 
  49.     exit 1 
  50. esac

设置所有人执行权限

 
 
bash
  1. chmod a+/etc/init.d/redis

加入开机启动服务

 
 
bash
  1. chkconfig redis on

重启服务

 
 
bash
  1. service redis restart
  2. service redis stop
  3. service redis start

重启系统生效

 
 
bash
  1. reboot


给php7安装redis扩展库




下载php7的redis扩展库
 
 
bash
  1. wget https://codeload.github.com/phpredis/phpredis/zip/php7
解压redis扩展库的编译zip包
 
 
bash
  1. unzip php7
  2. #进入解压目录
  3. cd phpredis-php7
通过phpize扩展脚本生成configure编译配置文件
 
 
bash
  1. [root@localhost /]# /usr/local/php/bin/phpize
  2. Cannot find config.m4. 
  3. Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module
编译指定php7的php-config配置文件的路径
 
 
bash
  1. ./configure --with-php-config=/usr/local/php/bin/php-config
进行安装
 
 
bash
  1. make && make install
编辑php.ini配置文件
 
 
bash
  1. vim /usr/local/php/etc/php.ini
对编译安装完后生成的扩展库路径和扩展库so文件增加到php.ini配置文件内,编译路径在安装的时候会自动生成,需要根据实际路径填写,包括上面的配置路径和phpize的实际路径
 
 
bash
  1. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20160303" 
  2. extension=redis.so

添加php7的redis扩展库需要先安装好php再执行这里的操作。安装好后可以通过运行php脚本进行查看扩展库的支持是否添加成功。

 
 
php
  1. <?php
  2.    phpinfo();
  3. ?>

redis support image


猜你喜欢

转载自blog.csdn.net/daily886/article/details/80113227