企业实战案例-- OpenResty简介与部署

一、OpenResty简介

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

OpenResty 是一个强大的 Web 应用服务器,Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,更主要的是在性能方面,OpenResty可以 快速构造出足以胜任 10K 以上并发连接响应的超高性能 Web 应用系统。

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

二、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

3.配置openresty

首先停止原来的nginx:

[root@server1 nginx]# nginx -s stop
[root@server1 conf]# vim nginx.conf
修改:
 2 user  nginx;

 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 

6.测试
在客户端测试:

当都不使用memcache缓存时:

[root@foundation63 kiosk]# ab -c 10 -n 5000 http://172.25.63.1/index.php

之前nginx服务器时:
在这里插入图片描述
使用openresty服务器后:
在这里插入图片描述当都使用memcache缓存时:
使用nginx+memcache时间较 openresty+memcache长:

[root@foundation63 kiosk]# ab -c 10 -n 5000 http://172.25.63.1/example.php

在这里插入图片描述

在这里插入图片描述

发布了127 篇原创文章 · 获赞 65 · 访问量 4341

猜你喜欢

转载自blog.csdn.net/qq_35887546/article/details/104576123