LNMP企业实战案例--OpenResty的相关介绍与部署

1.OpenResty相关介绍

OpenResty(又称:ngx_openresty) 是一个基于 NGINX 的可伸缩的 Web 平台,由中国人章亦春发起,提供了很多高质量的第三方模块。

OpenResty 是一个强大的 Web 应用服务器,Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,更主要的是在性能方面,OpenResty可以 快速构造出足以胜任 10K 以上并发连接响应的超高性能 Web 应用系统。
360,UPYUN,阿里云,新浪,腾讯网,去哪儿网,酷狗音乐等都是OpenResty的深度用户。
OpenResty 的目标是让你的Web 服务直接跑在Nginx服务内部,充分利用Nginx的非阻塞I/O模型,不仅仅对HTTP 客户端请求,甚至于对远程后端诸如MySQL,PostgreSQL,Memcaches以及Redis等都进行一致的高性能响应。所以对于一些高性能的服务来说,可以直接使用OpenResty 访问 Mysql或Redis等,而不需要通过第三方语言(PHP、Python、Ruby)等来访问数据库再返回,这大大提高了应用的性能。参考openresty中文官网http://openresty.org/cn/

==OpenResty即为 “PLUS”版的nginx,==对nginx的源码进行了非常多的改进

2.OpenResty部署过程

(1)解压及编译

[root@server1 lnmp]# tar zxf openresty-1.13.6.1.tar.gz 
[root@server1 lnmp]# cd openresty-1.13.6.1
[root@server1 openresty-1.13.6.1]# ./configure --prefix=/usr/local/openresty

(2)安装

[root@server1 openresty-1.13.6.1]# gmake && gmake install

配置openresty

首先停止原来的nginx:

[root@server1 nginx]# nginx -s stop
[root@server1 conf]# vim nginx.conf
修改:
 2 user  nginx nginx;
添加20-22行内容,68-88行内容
 17 http {
 18     include       mime.types;
 19     default_type  application/octet-stream;
 20     upstream memcache {
 21         server localhost:11211;
 22         keepalive 512;
 23     }

 68         location /memc {
 69         internal;       #只接受内部访问,不接受外部http访问。比较安全
 70         memc_connect_timeout 100ms;
 71         memc_send_timeout 100ms;        #后端服务器数据回传时间
 72         memc_read_timeout 100ms;        #连接成功后,后端服务器响应时间
 73         set $memc_key $query_string;
 74         set $memc_exptime 300;
 75         memc_pass memcache;
 76         }
 77         
 78 
 79         location ~ \.php$ {
 80             set $key $uri$args;         #http的GET方法便是get,PUT方法表示set
 81             srcache_fetch GET /memc $key;     #请求php页面时,先会去memcache中找,如果没有,正常访问;
 82             srcache_store PUT /memc $key;       #访问结束后将结果存到memcache,下次访问时直接从缓存中读取
 83             root           html;
 84             fastcgi_pass   127.0.0.1:9000;
 85             fastcgi_index  index.php;
 86             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 87             include        fastcgi.conf;
 88         }

(4)建立测试文件

可以将之前使用过的测试文件复制过来:

[root@server1 conf]# cp /usr/local/lnmp/nginx/html/index.php /usr/local/openresty/nginx/html/
[root@server1 conf]# cp /usr/local/lnmp/nginx/html/example.php /usr/local/openresty/nginx/html/
[root@server1 conf]# cd /usr/local/openresty/nginx/html/
[root@server1 html]# ls
50x.html  example.php  index.html  index.php

(5)开启openresty

[root@server1 html]# /usr/local/openresty/nginx/sbin/nginx 

(7)测试
在真机客户端测试:

当都不使用memcache缓存时:

[root@foundation1 ~]# ab -c 10 -n 5000 http://172.25.1.1/index.php

访问网站时间对比:

在这里插入图片描述
没有memcache缓存,但有nginx(OpenResty)缓存
在这里插入图片描述
当都使用memcache缓存时测试:

[root@foundation1 ~]# ab -c 10 -n 5000 http://172.25.1.1/example.php

访问网站时间对比:
光使用memcache缓存时间比 使用nginx(openresty)缓存+memcache缓存长:
在这里插入图片描述
在这里插入图片描述

发布了149 篇原创文章 · 获赞 1 · 访问量 3018

猜你喜欢

转载自blog.csdn.net/qq_36417677/article/details/104737888