一:安装redis服务
1、wget http://download.redis.io/releases/redis-5.0.0.tar.gz
2、tar xzf redis-5.0.0.tar.gz
3、cd redis-5.0.0
4、yum -y install gcc
5、make (在makefile的开头定义CFLAGS 变量:CFLAGS = -g ,否则调试过程中无法跟踪代码)
6、make test 如果报错类似 You need tcl 8.5 or newer in order to run the Redis test
则需要安装:tcl
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
sudo ./configure
sudo make
sudo make install, sudo make test
7、更改配置文件(https://www.cnblogs.com/yorkyang/p/8182451.html)
更改日志目录:logfile "/usr/local/redis/run/6379.log"
更改数据存储目录:dir /usr/local/redis/data
守护进程启动 daemonize yes
开启AOF:appendonly yes
no-appendfsync-on-rewrite 在重写时是否追加aof,默认为no数据更可靠,为了性能可以改为yes。
aof_current_size 当前aof文件大小
aof_base_size 上次重写时aof文件的大小
auto_aof_rewrite_min_size(aof文件最小重写大小)
auto_aof_rewrite_percentage(下一次aof重写最小大小的增长率,默认值100)
自动执行bgrewriteaof的条件:
(1)aof_current_size大于 auto_aof_rewrite_min_size
(2)(aof_current_size - aof_base_size)/ aof_base_size > auto_aof_rewrite_percentage
slowlog_max_len 慢查询时间定义,单位um,不要设置过大,默认10ms通常设置1ms
slow_log_slower_than 慢查询队列长度,存在内存,先进先出,太小会丢失一部分,默认128,通常设置1000
8、启动redis服务
复制其配置文件redis.conf 到etc 文件夹下
cd redis解压目录
cp redis.conf /etc
进入etc,找到redis.conf 并修改 daemonize no(第128行) 为 daemonize yes ,这样就可以默认启动就后台运行
cp ./src/redis-server /usr/local/bin/redis-server
cp ./src/redis-cli /usr/local/bin/redis-cli
cp ./src/redis-benchmark /usr/local/bin/redis-benchmark
cp ./src/redis-check-rdb /usr/local/bin/redis-check-rdb
cp ./src/redis-check-aof /usr/local/bin/redis-check-aof
cp ./src/redis-sentinel /usr/local/bin/redis-sentinel
cp ./src/redis-cluster-proxy /usr/local/bin/redis-cluster-proxy
redis-server /etc/redis.conf
二:安装redis扩展
1、下载php-redis扩展包
2、解压拆包后进入目录,可以看到如下:
3、在该目录下执行php安装目录下的phpize命令
4、此时目录下会多一个configure文件
5、现在可以配置了,--with-php-config 是告诉扩展需要安装的位置,自动帮我们配置好编译程序(执行一旦报错,有可能是没有安装autoconf,执行以下yum install autoconf即可)
6、编译make
7、编译通过,执行 make install
安装完之后,提示该扩展放置的目录,进入该目录会发现redis.so扩展
9、修改php.ini文件,增加如下信息
(一般情况下添加 extension=redis.so即可)
10、保存退出后,重启服务器。查看phpinfo()信息
此时显示加载成功。