在centos 7 系统中安装redis 3.2.9的过程方法。
下载redis3.2.9软件包
bash
- cd /usr/local
- #下载安装包
- wget http://download.redis.io/releases/redis-3.2.9.tar.gz
解压
bash
- tar -xzvf redis-3.2.9.tar.gz
- #重命名文件夹
- mv redis-3.2.9 redis
- cd redis
编译安装
bash
- make
- #完成后会在上一层文件夹生成bin目录,都移动到redis目录中
- #bin目录中有redis-server、redis-cli等文件
- mv bin redis
设置配置文件
bash
- cp redis.conf /etc/
指定配置文件启动redis服务
bash
- cd src
- [root@localhost src]# ./redis-server /etc/redis.conf
使用内置的客户端命令redis-cli进行使用
bash
- #使用src目录或bin目录中的redis-cli启动
- [root@localhost src]# ./redis-cli
- 127.0.0.1:6379>
- redis> set test bar
- OK
- redis> get test
- "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
- #在启动文件夹创建脚本文件
- vim /etc/init.d/redis
bash
- #!/bin/sh
- # chkconfig: 345 86 14
- # description: Redis is a persistent key-value database
- PATH=/usr/local/redis/bin:/sbin:/usr/bin:/bin
- REDISPORT=6379
- EXEC=/usr/local/redis/bin/redis-server
- REDIS_CLI=/usr/local/redis/bin/redis-cli
- PIDFILE=/var/run/redis_6379.pid
- CONF="/etc/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
设置所有人执行权限
bash
- chmod a+x /etc/init.d/redis
加入开机启动服务
bash
- chkconfig redis on
重启服务
bash
- service redis restart
- service redis stop
- service redis start
重启系统生效
bash
- reboot
给php7安装redis扩展库
下载php7的redis扩展库
bash
- wget https://codeload.github.com/phpredis/phpredis/zip/php7
解压redis扩展库的编译zip包
bash
- unzip php7
- #进入解压目录
- cd phpredis-php7
通过phpize扩展脚本生成configure编译配置文件
bash
- [root@localhost /]# /usr/local/php/bin/phpize
- Cannot find config.m4.
- Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module
编译指定php7的php-config配置文件的路径
bash
- ./configure --with-php-config=/usr/local/php/bin/php-config
进行安装
bash
- make && make install
编辑php.ini配置文件
bash
- vim /usr/local/php/etc/php.ini
对编译安装完后生成的扩展库路径和扩展库so文件增加到php.ini配置文件内,编译路径在安装的时候会自动生成,需要根据实际路径填写,包括上面的配置路径和phpize的实际路径
bash
- extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20160303"
- extension=redis.so
添加php7的redis扩展库需要先安装好php再执行这里的操作。安装好后可以通过运行php脚本进行查看扩展库的支持是否添加成功。
php
- <?php
- phpinfo();
- ?>