构建nginx高速缓存

使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制

[root@server1 etc]# cd
[root@server1 ~]# cd memcache-4.0.5.2/
[root@server1 memcache-4.0.5.2]# ls
[root@server1 memcache-4.0.5.2]# cp example.php memcache.php /usr/local/nginx/html/

 
[root@server1 memcache-4.0.5.2]# cd /usr/local/nginx/html/
[root@server1 html]# yum install memcached -y
[root@server1 html]# systemctl start memcached
[root@server1 html]# netstat -antlp | grep :11211  ##过滤端口显示11211
[root@server1 html]# cat /etc/sysconfig/memcached   ##查看端口
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

[root@server1 html]# vim memcache.php

配置PHP文件 

分别访问172.25.22.1/example.php和memcache.php测试页

在真机测试: ab -c10 -n 1000 http://172.25.52.1/example.php  

 

 刷新后百分之百

OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

OpenResty通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。

Openresty里面有nginx模块,也有缓存模块,所以要用高速缓存,需要使Openresty里面的nginx运行
软件下载: https://openresty.org/cn/  

[root@server1 ~]# lftp 172.25.254.250
lftp 172.25.254.250:~> cd pub/docs/lamp/
lftp 172.25.254.250:/pub/docs/lamp> get openresty-1.19.9.1.tar.gz 
5166658 bytes transferred                                      
lftp 172.25.254.250:/pub/docs/lamp> exit
[root@server1 ~]# cd openresty-1.19.9.1
[root@server1 openresty-1.19.9.1]# ls   ##有configure文件,可编译make
bundle  configure  COPYRIGHT  patches  README.markdown  README-windows.txt  util
[root@server1 openresty-1.19.9.1]# cd bundle/
[root@server1 bundle]# ls


[root@server1 openresty-1.19.9.1]# cd /usr/local/openresty/
[root@server1 openresty]# ls
bin  COPYRIGHT  luajit  lualib  nginx  pod  resty.index  site
[root@server1 openresty]# cd nginx/
[root@server1 nginx]# ls
conf  html  logs  sbin
[root@server1 nginx]# cd conf/
[root@server1 conf]# pwd
/usr/local/openresty/nginx/conf
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# netstat -antlp

 [root@server1 conf]# vim nginx.conf

修改用户,并发数改为auto,openfile改为65535

添加memcache参数

 

复制/usr/local/nginx/html下nginx的默认发布目录文件到/usr/local/openresty/nginx/html的默认发布目录中:

在真机测试: ab -c10 -n 5000 http://172.25.52.1/example.php  

 [root@server1 conf]# nginx -s stop   ##
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx -t   ##检测语法
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx ##启动
[root@server1 conf]# ps aux | grep nginx

真机测试:ab -c10 -n 5000 http://172.25.52.1/example.php   

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值