openresty/nginx+php+memcache实现高速缓存

一.memcache源码编译

memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开
发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的、需
要频繁访问数据库的网站访问速度提升效果十分显著  。这是一套开放源代码
软件,以BSD license授权发布。
[root@server1 ~]# tar zxf memcache-4.0.5.2.tgz
[root@server1 ~]# cd memcache-4.0.5.2
[root@server1 memcache-4.0.5.2]# ./configure --with-php-config=/usr/local/lnmp/php/bin
[root@server1 memcache-4.0.5.2]# make
[root@server1 memcache-4.0.5.2]# make install

二.memcache配置文件修改

[root@server1 memcache-4.0.5.2]# yum install -y autoconf
[root@server1 memcache-4.0.5.2]# cp example.php memcache.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-4.0.5.2]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# ls
50x.html  bbs  download  example.php  index.html  index.php  memcache.php  redhat.jpg
[root@server1 html]# cd ~
[root@server1 ~]# ls
memcache-4.0.5.2      nginx-1.18.0.tar.gz  oniguruma-6.8.2-1.el7.x86_64.rpm        openresty-1.17.8.2.tar.gz  php-7.4.6.tar.bz2
memcache-4.0.5.2.tgz  nginx-1.19.1         oniguruma-devel-6.8.2-1.el7.x86_64.rpm  package.xml
nginx-1.18.0          nginx-1.19.1.tar.gz  openresty-1.17.8.2                      php-7.4.6
[root@server1 ~]# cd /usr/local/lnmp/php/lib
[root@server1 lib]# ls
php  php.ini
[root@server1 lib]# vim php.ini
[root@server1 lib]# cd ~
[root@server1 ~]# vim .bash_profile
[root@server1 ~]# cd /usr/local/lnmp
[root@server1 lnmp]# cd php
[root@server1 php]# ls
bin  etc  include  lib  php  sbin  var
[root@server1 php]# cd ..
[root@server1 html]# netstat -antlp | grep :11211
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      6896/memcached      
tcp6       0      0 :::11211                :::*                    LISTEN      6896/memcached      

php.ini
在这里插入图片描述

[root@server1 ~]# yum install  memcached
[root@server1 ~]# systemctl start memcached..

三.nginx+php+memcache

1.编辑memcache.php文件,监控本机

[root@server1 lnmp]# cd nginx
[root@server1 nginx]# cd html
[root@server1 html]# ls
50x.html  bbs  download  example.php  index.html  index.php  memcache.php  redhat.jpg
[root@server1 html]# vim memcache.php 
memcache.php中显示监控页面登录的用户名和密码
修改memcache.php中的 
MEMCACHE_SERVERS为127.0.0.1:11211

在这里插入图片描述

2.测试:访问www.westos.org/memcache.php

在这里插入图片描述

四.openresty

    OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大
量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超
高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
    OpenResty通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自
主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,
Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以
及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能
Web 应用系统。
    OpenResty的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 
Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 
MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。

五.server1上下载并编译openresty

[root@server1 ~]# tar zxf openresty-1.17.8.2.tar.gz 
[root@server1 ~]# cd openresty-1.17.8.2 
[root@server1 openresty-1.17.8.2]# ./configure 
[root@server1 openresty-1.17.8.2]# gmake 
[root@server1 openresty-1.17.8.2]# make install 
[root@server1 build]# cd /usr/local/openresty/nginx/sbin 
[root@server1 sbin]# ./nginx -t
[root@server1 sbin]# ./nginx 

六.server3,server4安装memcached

[root@server3 ~]# yum install -y memcached
[root@server3 ~]# ssh server4 yum install -y memcached
[root@server3 ~]# systemctl start memcached
[root@server3 ~]# ssh server4 syatemctl start memcached

六.openresty中设置监控

[root@server1 ~]# vim /usr/local/openresty/nginx/html/memcache.php

在这里插入图片描述

七.修改openresty配置文件,并测试

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

1.非高速缓存:

在这里插入图片描述

2.测试:

[root@foundations13 ~]# ab -c10 -n 20000 http://172.25.13.1/index.php
访问速度慢,失败2000次

在这里插入图片描述

3.高速缓存:

在这里插入图片描述

4.测试

[root@foundations13 ~]# ab -c10 -n 20000 http://172.25.13.1/index.php
访问速度快,无失败

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值