php与nginx的高速缓存

memcache

PHP的加速模块
本部分是对php的内存加速的配置

1. memcache安装

  609  phpize # 生成./configure文件
  610  yum install -y autoconf # 安装包
  611  ls
  612  phpize
  613  ls
  614  ./configure
  615  make && make install
  616  ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

vim /usr/local/php/etc/php.ini
systemctl reload php-fpm
php -m | grep memcache

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2. 安装过程问题

php -m 搜索不到memcache模块

在这里插入图片描述
最后发现是文件名字错了,是php.ini不是php-ini
在这里插入图片描述

3. 模块配置

cp example.php memcache.php /usr/local/nginx/html/  # memcache.php是监控页面 # example.php负责存储数据到memcache
yum install -y memcached.x86_64
systemctl enable --now memcached.service

在这里插入图片描述
在这里插入图片描述

vim /usr/local/nginx/html/memcache.php

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 对比磁盘和内存读取的性能

在这里插入图片描述
在这里插入图片描述

4 问题

 client -> nginx -> *.php -> fastcfi_pass -> php-fpm:9000 -> nginx -> client
 # nginx处理php文件的流程

在处理请求的过程中是通过php-fpm:9000来处理文件,性能还是不够高速,nginx起到的作用很小,需要等待php的处理。

php+nginx高速缓存配置

传统的处理还需要经过PHP,会降低服务器性能。

在这里插入图片描述

openresty

https://openresty.org/cn/

在这里插入图片描述
非常适合前端开发人员
在这里插入图片描述

  1. 安装
tar -zxf openresty-1.21.4.1.tar.gz
cd openresty-1.21.4.1/
./configure --prefix=/usr/local/openresty --with-http_ssl_module --with-http_stub_status_module
# make & make install # 这种写法会出现一定的概率安装不完整
make
make install

在这里插入图片描述

在这里插入图片描述

  1. 配置文件
cd /usr/local/openresty/nginx/conf
cp /usr/local/nginx/conf/nginx.conf . # 为了快速配置可以将nginx的配置文件复制到openresty中
cp /usr/local/nginx/conf/cert.pem .
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

cd /usr/local/openresty/nginx/html
cp /usr/local/nginx/html/index.php .
cp /usr/local/nginx/html/example.php .

在这里插入图片描述
3. 负载均衡

# 负载均衡
    upstream memcache {
        server 127.0.0.1:11211;
        keepalive 512;
    }

然后通过反向代理,把请求交给负载均衡器

# 在虚拟主机里面定义location
  location /memc { # /memc是虚拟路径,并不存在
        internal;
        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        set $memc_key $query_string;
        set $memc_exptime 300;
        memc_pass memcache;
        }
# 在php目录定义中加入
			set $key $uri$args;
            srcache_fetch GET /memc $key;
            srcache_store PUT /memc $key;

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值