CentOS安装Redis服务 + PHP redis.so 扩展

Centos版本为6.9,Redis版本为4.0.4

首先下载Redis,官网为 https://redis.io/download

$ wget http://download.redis.io/releases/redis-4.0.4.tar.gz

$ tar xzf redis-4.0.4.tar.gz

$ cd redis-4.0.4

$ make

$ make test

$ make install

这里在执行 make test 的时候如果出现问题,需要Tcl8.5的库

错误1:

You need tcl 8.5 or newer in order to run the Redis test

解决:

# yum install tcl

错误2:

[exception]: Executing test client: NOREPLICAS Not enough good slaves to write..

NOREPLICAS Not enough good slaves to write.

......

Killing still running Redis server 63439

Killing still running Redis server 63486

Killing still running Redis server 63519

Killing still running Redis server 63546

Killing still running Redis server 63574

Killing still running Redis server 63591

I/O error reading reply

......

解决:

vim tests/integration/replication-2.tcl

- after 1000

+ after 10000

错误3:

[err]: Slave should be able to synchronize with the master

in tests/integration/replication-psync.tcl

Replication not started.

解决:

遇见过一次,重试make test就ok了。

错误4:

[err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1) in tests/integration/replication-psync.tcl

解决:

vimtests/integration/replication-psync.tcl

- after 100

+ after 1000

接下来  make PREFIX=/usr/local/redis install

会在/usr/local/redis下生产bin文件夹  bin下面有

redis-benchmark  redis性能检测工具

redis-check-rdb 检查rbd日志的工具

redis-sentinelRedis集群的管理工具监控多个master-slave集群,发现master宕机后能进行自动切换

redis-check-aof  检查aof日志的 工具

redis-cli        redis-server    等文件

我们来到bin的目录下,执行 ./redis-server& ,如果看到下图就说明redis服务已经启动成功。

CentOS安装Redis服务 + PHP redis.so 扩展_第1张图片
Redis启动成功界面

稍后再写如何开启自动开启redis服务


接下来开始安装PHP的Redis扩展

yum install php-devel

wget https://github.com/nicolasff/phpredis/archive/master.zip

如果没装unzip,需要先安装unzip

yum install unzip

unzip master.zip

解压目录为phpredis-master,进入该文件夹,开始编译php扩展

phpize

 配置环境

./configure

编译

make && make install


编译完成后显示

进入/usr/lib64/php/modules/文件夹,发现redis.so的扩展

修改/etc/php.ini,添加下面的扩展



重启服务器

service httpd restart

重启服务器后查看phpinfo,如下图所示

CentOS安装Redis服务 + PHP redis.so 扩展_第2张图片
php扩展添加成功

你可能感兴趣的:(CentOS安装Redis服务 + PHP redis.so 扩展)