LINUX【企业】 ------,


LINUX【企业】 ------- LNMP架构下的OpenResty的部署

OpenResty简介

我们都知道Nginx有很多的特性和好处,但是在Nginx上开发成了一个难题,Nginx模块需要用C开发,而且必须符合一系列复杂的规则,最重要的用C开发模块必须要熟悉Nginx的源代码,使得开发者对其望而生畏。为了开发人员方便,所以接下来我们要介绍一种整合了Nginx和lua的框架,那就是OpenResty,它帮我们实现了可以用lua的规范开发,实现各种业务,并且帮我们弄清楚各个模块的编译顺序。

 

 

OpenResty运行原理

Nginx 采用的是 master-worker 模型,一个 master 进程管理多个 worker 进程,基本的事件处理都是放在 woker 中,master 负责一些全局初始化,以及对 worker 的管理。在OpenResty中,每个 woker 使用一个 LuaVM,当请求被分配到 woker 时,将在这个 LuaVM 里创建一个 coroutine(协程)。协程之间数据隔离,每个协程具有独立的全局变量_G。

作用:OpenResty实现Nginx服务内部加速,Nginx直接去memcache中拿数据

 

系统环境:RedHat6.5系统

实验环境

                   server1: 172.25.60.1/24

 物理主机:172.25.60.250/24

 


部署过程如下:

1.下载并解压安装包

[root@server1 lnmp]# tar zxf openresty-1.13.6.1.tar.gz

2.编译安装

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

3.将nginx的测试文件复制到openresty的nginx的发布目录中

[root@server1 openresty-1.13.6.1]# cp /usr/local/lnmp/nginx/html/index.php  /usr/local/openresty/nginx/html/
[root@server1 openresty-1.13.6.1]# cp /usr/local/lnmp/nginx/html/example.php  /usr/local/openresty/nginx/html/


4.编辑nginx的配置文件/usr/local/openresty/nginx/conf/nginx.conf

 17 http {
 18        upstream memcache {  
 19            server localhost:11211;
 20            keepalive 512;
 21       }
 22     include       mime.types;
 23     default_type  application/octet-stream;


 53         location /memc {
 54             internal;
 55             memc_connect_timeout 100ms;
 56             memc_send_timeout 100ms;  
 57             memc_read_timeout 100ms;
 58             set $memc_key $query_string;
 59             set $memc_exptime 300;
 60             memc_pass memcache;
 61         }


 77         location ~ \.php$ {
 78             set $key $uri$args;
 79             srcache_fetch GET /memc $key;
 80             srcache_store PUT /memc $key;
 81             root           html;
 82             fastcgi_pass   127.0.0.1:9000;
 83             fastcgi_index  index.php;
 84             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 85             include        fastcgi.conf;
 86         }

5.开启nginx

cd /usr/local/openresty/nginx/sbin
 

[root@server1 sbin]# ./nginx  -t    //检测nginx的配置文件是否有语法错误

[root@server1 sbin]# ./nginx       //开启nginx

查看nginx的监测端口

 

测试:在浏览器中访问172.25.27.1,显示nginx的测试页

 

ab -c 10 -n 5000 http://172.25.60.1/index.php


ab -c 10 -n 5000 http://172.25.60.1/example.php

注意:对比之前memcache时,会有加速

 

相关内容

    暂无相关文章