openresty实现lnmp的缓存前移_saori(๑><๑)的博客-爱代码爱编程
1.关闭之前的nginx
[root@server1 ~]# nginx -s stop
2.解压openresty源码包
[root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz
3.搭建预编译环境、编译并安装
[root@server1 ~]# cd openresty-1.13.6.1
[root@server1 openresty-1.13.6.1]# ls
bundle COPYRIGHT README.markdown util
configure patches README-win32.txt
[root@server1 openresty-1.13.6.1]# ./configure
[root@server1 openresty-1.13.6.1]# gmake && gmake install
4.把上一篇博客用来测试的两个文件复制到当前路径下
[root@server1 openresty-1.13.6.1]# cd /usr/local/openresty/nginx/
[root@server1 nginx]# ls
conf html logs sbin
[root@server1 nginx]# cd html/
[root@server1 html]# cp /usr/local/lnmp/nginx/html/index.php .
[root@server1 html]# cp /usr/local/lnmp/nginx/html/example.php .
5.修改openresty的配置文件
[root@server1 conf]# vim nginx.conf
修改的部分:
user nginx nginx;
worker_processes 1;
http {
upstream memcache{
server localhost:11211;
keepalive 512;
}
include mime.types;
default_type application/octet-stream;
新添加的部分:
location /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;
}
location ~ \.php$ {
set $key $uri$args;
srcache_fetch GET /memc $key; #读数据
srcache_store PUT /memc $key; #放数据
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
6.openresty语法检测
[root@server1 conf]# cd /usr/local/openresty/nginx/sbin/
[root@server1 sbin]# ./nginx -t
7.打开openresty
[root@server1 sbin]# ./nginx
8.查看进程
[root@server1 sbin]# ps ax
9.测试:浏览器访问172.25.7.1
[root@server1 sbin]# ab -c 10 -n 5000 http://172.25.7.1/index.php
[root@server1 sbin]# ab -c 10 -n 5000 http://172.25.7.1/example.php
结论:相比上一篇博客的一层缓存,再添加一层缓存,速度都提高了很多,且出错率都为0